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)