LWN.net Logo

What is Science?

What is Science?

Posted Jun 30, 2012 8:44 UTC (Sat) by Cyberax (✭ supporter ✭, #52523)
In reply to: What is Science? by khim
Parent article: Why learn C? (O'Reilly Radar)

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


(Log in to post comments)

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.

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