Tuesday, November 24, 2009

Good and bad, at the same time

I think it was Kernighan who ranted about the differences between C and Pascal, and how Pascal was a straightjacket and that there was no way to fix it.

I've been working with C++ today, and my mind has been thinking along two lines.

One thought has been: This is the best C++ experience I have had in a long time. And it has been a good experience, for I am using the STL for the first time. STL fixes a lot of problems with C++ and makes many things easier. The 'string' class has made many things easier, and the 'vector' and 'map' classes have also helped. I can program faster than before (in C++) and get more done.

The counter-thought has been: This is the worst programming experience I have had in a long time. And it has been a bad experience, for I am stuck in the static-type-world of C++ and used to languages such as Perl and Ruby. I have been working harder than usual to perform simple tasks. An especially difficult problem is one of collections. The static types of C++ demand that I define a collection and its contained types in advance, where in Perl and Ruby the languages don't care and accept anything you throw at them. (Well, almost anything.)

Perhaps I have learned a bit of programming in Perl and Ruby. During the day, I had various thoughts on the design of programs, but found that C++ could not handle the designs. I had to "dumb down" the design for the compiler. (Perhaps there is a way to torment the compiler into accepting the design, but it eludes me. I suspect it would involve a lot of template magic, and I find that templates tend to make programs harder to read, not easier.)

In the back of my mind is the thought: There is no way to fix C++. Kernighan's rant (if it was his) has come back to haunt me. Yes, the C language is "better" than Pascal because you can do what you need. In that sense Perl and Ruby are better than C++ because you can do what you need.

The problem seems to be the static typing. And that got me thinking.

Static typing is good, for the compiler. It allows the compiler to check operations at compile-time. (Languages with dynamic typing must perform checks at run-time, and that incurs a cost to performance.) The compiler can also optimize code.

But static typing is a pain when developing programs. It forces me to think about the program. It distracts me.

I want a language (or development environment) with variable typing. I want a language that allows me to design programs with dynamic typing and let me create the design. Then, after I have the correct algorithms and code, I want to turn one static typing. Perhaps in small amounts, or for specific objects in the program. (I would expect the IDE to show me which objects have static typing and which do not, and let me implement static typing on my schedule.)

I'm not against static typing. At least, not all the time. Only when I'm programming.


No comments:

Post a Comment