Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!mcvax!hp4nl!ruuinf!verwer From: verwer@ruuinf.cs.ruu.nl (Nico Verwer) Newsgroups: comp.lang.pascal Subject: Re: C Ternary Conditional Expression? Summary: Let's have conditional expressions in Pascal Message-ID: <1344@ruuinf.cs.ruu.nl> Date: 26 May 89 08:37:39 GMT References: <950025@hpclcdb.HP.COM> <6490002@hplsla.HP.COM> Organization: Univ of Utrecht, Dept of CS Lines: 43 In article <6490002@hplsla.HP.COM>, davidr@hplsla.HP.COM (David M. Reed) writes: > However, C programmers have continually reminded me how "efficient" > code can be written in C verses Pascal, such as > > a[ (indx == last_indx) ? last_val : f(indx) ] = a [ y ]; > > instead of > > IF (indx = last_indx) > THEN temp := last_val > ELSE temp := f(indx); > a[temp] := a[y]; > > But that only means that you can write source code more concisely, not that > the actual machine code is more concise (depending on the compiler, of course). > [...] > So why write in the terse C format? I personally think that I think this is one of the few places where C is a "higher-level" language than Pascal. Of course the compiler will generate code that allocates space for a temporary variable (temp) in both cases, but why declare this variable in your program? Personally, I would like to write the above as a[ IF index = last_index THEN last_val ELSE f(index) ] := a[ y ] ; This would extend the IF-statement to conditional expressions, which in my view is a higher-level construct than the conditional statement in Pascal, because it allows one to write better readable code. > All the person writing C has done, then, is to write less clear code in > fewer lines, often making it harder to understand and maintain later (even > by the original author, and even if well commented). That is why I use Pascal most of the time, that is, if I'm doing low-level, time/space-efficient coding. When speed/memory is not important I use prolog or some functional language, of course. ===================================================================== /| / University of Utrecht, Dept. of Computer Science / | / VOICE: +31-30-533921 || Postbus 80.089 / |/ico Verwer INTERNET: verwer@cs.ruu.nl || 3508 TB Utrecht UUCP: ...!hp4nl!ruuinf!verwer || the Netherlands =====================================================================