Home > C++ > Strongly Typed

Strongly Typed

In “Hackers and Painters“, one of my favorite essayists and modern day renaissance men, Paul Graham, states his disdain for strongly typed programming languages. The main reason is that he doesn’t like to be scolded by mindless compilers that handcuff his creativity by enforcing static type-checking rules. Being a C++ programmer, even though I love Paul and understand his point of view, I have to disagree. One of the reasons I like working in C++ is because of the language’s strong type checking rules, which are enforced on the source code during compilation. C++ compilers find and flag a lot of my programming mistakes prior to runtime <- where finding sources of error can be much more time consuming and frustrating.

Driven by “a fierce determination not to impose a specific one size fits all programming style” on programmers, Bjarne Stroustrup designed C++ to allow programmers to override the built-in type system if they consciously want to do so. By preserving the old C style casting syntax and introducing new, ugly C++ casting keywords (static_cast, dynamic_cast, etc) that purposefully make manual casts stick out like a sore thumb and easily findable in the code base, a programmer can legally subvert the type system.

C++ gets trashed a lot by other programming language zealots because it’s a powerful tool with a rich set of features and it supports multiple programming styles (procedural, abstract data types, object-oriented, generic) instead of just one “pure” style. Those attributes, along with Bjarne’s empathy with the common programmer, are exactly why I love using C++. How about you, what language(s) do and don’t you like? Why?

  1. Ray
    March 1, 2010 at 7:33 am

    The more you try to handcuff a software developer the more they try to get around it. Mainly due to cost and schedule pressures.

  2. March 1, 2010 at 7:41 am

    Is it mainly due to cost and schedule pressure, or is it mainly because of ego?

  3. Ray
    March 2, 2010 at 7:27 am

    Some ego, some experimentation but mostly people start cutting corners when the cost and schedule legs of the project start getting raddled.

    • March 2, 2010 at 7:33 am

      Have you personally experienced many cases where “cost and schedule legs of the project don’t start getting raddled”?

  4. Raj
    March 2, 2010 at 3:16 pm

    I prefer working with strongly type language, explicitly mentioning type is much better. With the introduction of auto keyword, Visual Assist and modern IDEs the pain of making type agree is much reduced even before compiling. I remember Andrew Koenig in his book Accelerated C++ using vector::size_type, rather than using any other type as counter variable, and I like that.

    • March 3, 2010 at 2:36 am

      Hi Raj,

      I too like getting beat up by the compiler. I’m a glutton for punishment.

      I use unsigned as the type of the looping variable for vector. It’s less verbose and I’m lazy 🙂 .

  5. Raj
    March 3, 2010 at 4:30 am

    Hi Tony, I agree I too use unsigned int, but Ideally we have to use the type as defined inside Allocator, that can be any thing, char or int or long or anything else but size_type is just type defined in allocator type.

  6. Raj
    March 3, 2010 at 4:46 am

    At least with the introduction of auto keyword in C++OX things will be much better, we may not need to think about type itself 🙂 .

  1. January 3, 2011 at 1:16 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: