Wednesday, July 30, 2008

C++ Is Premature Optimization

While C++ does give you extraordinary power to optimize and specify your code, ultimately it suffers from enforced application of it's own rigid model for how you do that. Invariably high-performant code becomes a mass of unreadable, undebuggable code with excessive template parameters. And the magic that is the compiler is walled off from you: you have no power to modify or enhance it's behavior.

I may be turning into a Lisp convert at long last.

Wednesday, July 16, 2008

Making Prolog familiar

While I'm a huge fan of Prolog, I definitely understand that it's syntax and behavior is too far removed from that of C-based languages (e.g., C, C++, Java, C#, JavaScript, etc.).  So without sacrificing the beautiful semantics of Prolog (unification, backtracking), could we restore some familiarity to the language, and thus expose it to new users?

Let's start with the basic logical operators:

  • -> ; represents if-then-else
  • ; represents or
  • , represents and
  • = represents unification of the term on the left with the term on the right
  • is represents an assignment of the value on the right to the term on the left
  • ( and ) are used both for grouping and to bound lists
Problem is, of course, engineers accustomed to C-based languages read these differently:
  • -> represents the pointer derference, member access operator (combination of *.)
  • ; represents the end of a statement, or a separator between statements executing sequentially
  • , represents either a series of expressions executed in order, or arguments to a function
  • = is an assignment statement from right to left
  • ( and ) are just for grouping, and do not imply a data structure
With this in mind, we can adjust the basic operators to match more closely to C:
  • Instead of using -> ; for if-then-else, use the C ternary operator ? :
  • Instead of ; to represent "or" of expressions (thus alternative not sequential execution), let ; be the "and" operator--so a series of expressions connected by ";" will be executed sequentially, in the typical case
  • Leave , to be both the or operator and a delimiter in argument lists
  • Let = be the assignment operator
  • Use is as the unification operator
  • Use { and } to bound lists, with elements separated by ;

C++ must go

I've had it; C++ officially needs to be replaced, and I don't even want to hear about C++0x. Either one is struggling to assemble the right templates, or from someone else's "standard" template library, or dealing with compile failures, or hitting missing features in the compiler, or unable to debug into those "standard" template libraries, or unable to set a breakpoint in a method of a template because the debugger is confused, or even crashing the outright.

*This* is productivity?

Here we are, C++ is the pinnacle of programming for performance,but even competent programmers must fight against the very tools on which there work depends. The separation of compiler, linker, debugger, and new program made sense 40 years ago when computers were expensive and slow: now, however, they can afford to be more dynamic, facilitating debugging the compiler as easy as the target program itself. Why should the debugger of an understanding of a programming language that is not automatically shared with the compiler? Why are templates (so arcane) the only method for reusing significant algorithms across  wildly divergent types? Is there no middle ground between preprocessor macros and templates, so that one does not have to to outside the language (or struggle with a poorly supported one based on templates) just to get the power of a LISP macro?

I'm ready. In fact, this might be how I want to contribute to computer science: reinvent our infrastructure, the languages and tools that support the languages we use.

Saturday, July 12, 2008

Harvard Square

I had forgotten how glorious Harvard Square can be in summer. All within the space of 10 minutes I have seen a juggler, a vocalist accompanying himself with a keyboard, a budding filmmaker capturing ambient street scenes, a gelatti stand that would make an Italian proud, and I am tasting a perfect latte made with care and artistry--including the tree design delicately drawn on top. I miss my partner, though. Can't wait to see him again tomorrow!

Posted with LifeCast

Summer

At home spending way too much time with iPhone 2.0.  What should be just a cellphone is certainly far more than that...

Posted with LifeCast