Lindsey Kuper (lindseykuper) wrote,
Lindsey Kuper
lindseykuper

A textbook example

Bad and wrong.

From page 151 of Concepts in Programming Languages by John C. Mitchell:

For example, consider the following two expressions:

3 + 2
3.0 + 2.0

Here is how the compiler will produce code for evaluating each expression:

3 + 2: The parsing phase of the compiler will build the parse tree of this expression, and the type-checking phase will compute a type for each symbol. Because the type-checking phase will determine that + must have type int * int -> int, the code-generation phase of the compiler will produce machine instructions that perform integer addition.

3.0 + 2.0: The parsing phase of the compiler will build the parse tree of this expression, and the type-checking phase will compute a type for each symbol. Because the type-checking phase will determine that + must have type real * real -> real, the code-generation phase of the compiler will produce machine instructions that perform integer addition.

Okay, if you're going to insult our intelligence by writing the same thing twice, at least have the decency to correct "integer" to "real" in that last sentence. Not like that would disguise the fact that you copied and pasted, but at least then it'd be, oh, I don't know, not completely incorrect?

And the kicker, of course, is that this is from the section of the book about polymorphism and overloading, directly following your little rant about how the C++ implementation of parametric polymorphism "requires more effort at link time and produces a larger code, as instantiating a template several times will result in several copies of the code". Gosh, it sounds perfect for you.

Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 7 comments