[SDL] Off-Topic: Quake II Ported to HTML5

Rainer Deyke rainerd at eldwood.com
Thu Apr 8 19:04:54 PDT 2010


On 4/8/2010 15:27, Mason Wheeler wrote:
>> ----- Original Message ----
> 
>> From: Rainer Deyke <rainerd at eldwood.com>
>> Subject: Re: [SDL] Off-Topic: Quake II Ported to HTML5
>> If you understand what the function does, you know its return type.  If
>> you don't understand what the function does, maybe you shouldn't be
>> using it at all.
> 
> You're still thinking like a code writer and not a code reader.  Of course
> you understand what the function does when you create it!  But what if I
> created it a year ago, then I went and took another job somewhere else,
> and you get a CR to fix a bug that eventually takes you into the routine,
> and you've never seen it before.  Don't you want as much *explicit*
> information presented to you as possible, to aid you in figuring out what
> this function is doing?  With real code these days now spending more
> than 60% of its life cycle in maintenance, not development, you're
> approaching this from a very counterproductive paradigm.

The function is called 'max'.  It's one line long.  How can there
possibly be any misunderstanding about what it does?

When reading code, I want the clarity that comes from removing
unnecessary clutter.  If I really can't figure out the type of a
variable, I can always ask my IDE.

Here is the max function in Python:

  def max(x, y):
    if x > y:
      return x
    else:
      return y

Here it is in C++ with proprietary extensions:

  template<class T0, class T1>
  typeof(true ? T0() : T1()) max(T0 v0, T1 v1) {
    return v0 > v1 ? v0 : v1;
  }

Note how the extra clutter in the C++ version decreases readability
while adding absolutely no information of any kind.


-- 
Rainer Deyke - rainerd at eldwood.com




More information about the SDL mailing list