LWN.net Logo

What is Science?

What is Science?

Posted Jun 30, 2012 0:59 UTC (Sat) by Wol (guest, #4433)
In reply to: C vs. C++ vs. ... by daniel
Parent article: Why learn C? (O'Reilly Radar)

JUST A BUNCH OF ANECDOTES!

Which are then studied, analyzed, and used to predict the future.

If the future is successfully predicted, then we have a workable scientific theory.

It really annoys me when people say "that's just an anecdote". No it isn't! It's a data point! It may be an outlier, it may be invalid, it may be wrong, but it is also well known that people will dismiss inconvenient data points without seriously trying to understand them. Feynman gives a very good example of a rogue data point setting quantum mechanics or something like that back 20 years - they didn't bother to see if any data points were rogue, so the "wrong" answer was used and messed up everything else until the problem was spotted - MANY years down the line.

Anyways - my take on this high/low-level stuff? For any given programmer, their productivity measured in LOC is roughly constant regardless of the language. If it takes 10 lines of C or 100 lines of C++, use C. You'll get it done in one tenth the time. On the other hand, if it takes 10 lines of C++ or 100 lines of C ... you get my drift.

Cheers,
Wol


(Log in to post comments)

What is Science?

Posted Jun 30, 2012 1:41 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

>On the other hand, if it takes 10 lines of C++ or 100 lines of C ...
Usually it's the other way around..

What is Science?

Posted Jun 30, 2012 8:15 UTC (Sat) by HelloWorld (guest, #56129) [Link]

That can't possibly be true. Everything that can be done in C can be done in C++, and more.

What is Science?

Posted Jun 30, 2012 8:27 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

I'm speaking about rewrites in "C++ style", not simple "recompile with g++" rewrites.

They do tend to shrink amount of lines of code quite significantly.

What is Science?

Posted Jun 30, 2012 8:39 UTC (Sat) by HelloWorld (guest, #56129) [Link]

You're contradicting yourself. Wol said "if it takes 10 lines of C++ or 100 lines of C", you said "it's the other way around..", and now you're saying that rewrites in C++ style tend to shrink the amount of code.

What is Science?

Posted Jun 30, 2012 22:00 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

Yes, rewrites in modern C++ tend to shrink code significantly compared to plain C. There's no contradiction.

What is Science?

Posted Jul 1, 2012 10:17 UTC (Sun) by HelloWorld (guest, #56129) [Link]

Uh, yes there is, unless my english parser is utterly broken, but I don't think so.

What is Science?

Posted Jun 30, 2012 8:28 UTC (Sat) by khim (subscriber, #9252) [Link]

This depends on your design very much. If you've dreamed up nice buzzword-compliant architecture of your project with classes, delegates and other such things then usually C++ code is smaller. If you instead will think about the task on hand and remove all the useless abstractions then often the end result will be less buzzword-compliant yet much smaller.

Of course you can write similar code in C++, but it'll not be "ideomatic C++".

What is Science?

Posted Jun 30, 2012 8:44 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link]

Uhm. Why classes are 'buzzword'? They are, like, 30 years old buzzword. In fact, even in languages like Java/C# architects now try to separate data from functionality (Fowler calls that 'anemic domain model'). And I don't understand that bit about 'useless abstractions'. For example, this kind of code:
std::function<void(int,int)> point_callback;

struct dist_summator
{
   Double dist;
   void add_point(double x, double y, double z)
   {
      dist+=sqrt(x*x+y*y+z*z);
   }
};

dist_summator sum;
point_callback=boost::bind(&dist_summator::add_point, &sum, _1, _2, 123.0d);
...
//Get points
...
//Use sum.dist
Is worse than something like this:
(void)(void*, int, int) point_callback;
void * point_callback_ctx;

typedef struct _dist_summator_with_fixed_z_ctx
{
   double sum;
   double fixed_z;
} dist_summator_with_fixed_z_ctx;
void sum_x_y(void *ctx_ptr, int x, int y)
{
   dist_summator_with_fixed_z_ctx *ctx=(dist_summator_with_fixed_z_ctx*)ctx;
   ctx->sum+=sqrt(x*x+y*y+ctx->z*ctx->z); //Whoopsie, forgot about ints here!   
}

dist_summator_with_fixed_z_ctx ctx;
point_callback = &sum_x_y;
point_callback_ctx = &ctx;
//Get points
...
//Use ctx.sum

What is Science?

Posted Jul 1, 2012 5:50 UTC (Sun) by wahern (subscriber, #37304) [Link]

Both of those examples are really ugly. Arguing that one dog is uglier than the next is kind of pointless.

What is Science?

Posted Jul 1, 2012 15:16 UTC (Sun) by hummassa (subscriber, #307) [Link]

Otoh they are close-to-what-I-have-found-IRL many, many times in the last 20 years.

What is Science?

Posted Jul 9, 2012 5:27 UTC (Mon) by daniel (subscriber, #3181) [Link]

And the C example is actually prettier than plenty of kernel code that does similar things.

What is Science?

Posted Jun 30, 2012 19:28 UTC (Sat) by Kluge (guest, #2881) [Link]

"Feynman gives a very good example of a rogue data point setting quantum mechanics or something like that back 20 years - they didn't bother to see if any data points were rogue, so the "wrong" answer was used and messed up everything else until the problem was spotted - MANY years down the line."

Reference?

What is Science?

Posted Jun 30, 2012 23:40 UTC (Sat) by Wol (guest, #4433) [Link]

It's mentioned in "Surely you're joking, Mr Feynman" or "What do you care what other people think"

But it was something like someone did an experiment to determine the spin of some particle. There was one data point that was way out, and actually was sufficient to dominate the result. Unfortunately it was the wrong result.

However many years it was, down the line, Dick looked at what he was doing and said "hey, if that particle was actually the opposite spin, everything would make sense". Then he went back to the original proof and said "hey, I remember thinking that proof was screwy, when it first came out!". Then he actually checked the maths, and said "ooopppsss".

Cheers,
Wol

What is Science?

Posted Jul 1, 2012 11:15 UTC (Sun) by man_ls (subscriber, #15091) [Link]

For any given programmer, their productivity measured in LOC is roughly constant regardless of the language.
Easy there. That is one of the foundations of function points, as seen in Casper Jones' "Applied Software Measurement"; and it is also utterly wrong. Otherwise we would all be programming in "5th generation languages", i.e. Excel macros.

If you want anecdotal evidence, my productivity (measured in LOC/day) in Perl or in assembly is abysmal. On the other hand, in PHP my productivity is insanely great writing garbage that doesn't work, just great for working code, but if I want to develop tight code then it becomes glacial. In Java it is great but diminishing asymptotically as I approach correct, maintainable code.

There are also serious arguments: high-level languages are less important for productivity than high-level frameworks which do everything for you, be it in C, Python or Excel. But the quality of the framework then becomes the dominant factor; if it takes ages to track down frequent bugs then productivity plummets faster than a sheep from a tree. As we have not yet invented measures for framework quality or completeness, the question of productivity remains completely open and mostly independent of the language.

In time I have learned to distrust frameworks, especially when they are high level. (By the way, I contend in passing that PHP is a framework rather than a language.)

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds