[SDL] Off-Topic: Quake II Ported to HTML5
Rainer Deyke
rainerd at eldwood.com
Thu Apr 8 22:30:27 PDT 2010
On 4/8/2010 22:09, Mason Wheeler wrote:
>> ----- Original Message ----
>
>> From: Rainer Deyke <rainerd at eldwood.com>
>> Subject: Re: [SDL] Off-Topic: Quake II Ported to HTML5
>>
>> The function is called 'max'. It's one line long. How can there
>> possibly be any misunderstanding about what it does?
>
> I thought you were only giving illustrative examples, and not real,
> useful code? Most functions that are actually useful are somewhere
> between 5 and 20 lines long, and often have other function calls
> in the function body. Some are much longer than that.
'max' is an example, but it's also a useful function I use very often.
Longer functions may benefit from optional type declarations, although I
would have to decide on a case-by-case basis.
>> template<class T0, class T1>
>> typeof(true ? T0() : T1()) max(T0 v0, T1 v1) {
>> return v0 > v1 ? v0 : v1;
>> }
>
> Holy crap! What in the world is *that*?!? I've seen a more readable
> Max() implemented in assembly!
>
>> Note how the extra clutter in the C++ version decreases readability
>> while adding absolutely no information of any kind.
>
> ....which is why I prefer Pascal. It gets things like this right. Its
> "extra clutter" increases readability by providing useful information.
I challenge you to write a better version in Pascal, given these
requirements:
- It accepts two arguments of possibly different numeric types.
- Its return type has the following properties:
- If both arguments use integer types, the larger integer type is
used as return type.
- If both arguments use floating point types, the larger floating
point type is used as return type.
- If one argument uses a floating point type and the other uses an
integer type, the floating point type is used as return type.
The C++ version is hideously ugly, but at least it does the job.
--
Rainer Deyke - rainerd at eldwood.com
More information about the SDL
mailing list