The code we write is not supposed to be a line by line count of what we want the cpu to do. It is merely a way of describing our business rules / logic in a way that is non-ambiguous.
How our code gets converted into machine code, (or an IL for that matter) is the job of the compiler / interpreter.
With multiple cpu's we may need to address an extra concern : distributing load across multiple processors. For any loop or repetitive action there may be several ways to achieve optimal performance depending on the data we may be working on.
People talk of using extra markup to define to the compiler which optimization scheme (if any) should be used. I say this is the wrong approach. It adds complexity to the piece of logic we are trying to describe, causing the programmer to hold too many concerns in their head at the same time.
The code we write should be only what is necessary to define the routine and no more. That is the best abstraction for code. No leaks please. Optimization should be a concern you address later in an orthogonal view, or using an external tool which extrapolates the routines that qualify for optimization, and then allows the user to choose which model to use.
Its a bit like one person can design the schema of the database, and another can add and remove indexes in order to address performance issues. (Its one separation of concerns that rdbms databases do well. Databases suck at providing other abstractions like inheritance and interfaces. Views are a great way to create a sub-set of functionality. I think the problem is that the database should be defined as the combination of all possible views rather than the views being a subset of the whole database. Its kind of like micro-kernel vs monolithic kernel. In the end the database administrator really needs to understand every table, rule, column and view if he is to
make any change to the schema of the database. Nasty. )
Better yet, (going back to the multi-processor optimization) you could have the application keep statistics and choose the best optimization at run time based on the data/conditions at the time. Anyway, at least we have the option to do all this if we separate the concern!
I suppose this approach can also be taken for locking on variables.
Identifying the possibility of race conditions,and dead locks... shouldn't all this be possible just by interogating the source? If a human can do it, a computer program could do it even easier, and with a lot more accuracy. Why then do we even bother to think about obtaining locks on sync objects? Why cant the compiler work out where its needed and let us FOCUS ON THE LOGIC/ BUSINESS RULES!
Whenever I hear "don't forget to do this.... don't forget to do that..." I think "We could be doing this much better!"
No comments:
Post a Comment