Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hp-pcd!hplsla!davidr From: davidr@hplsla.HP.COM (David M. Reed) Newsgroups: comp.lang.pascal Subject: Re: C Ternary Conditional Expression? Message-ID: <6490002@hplsla.HP.COM> Date: 25 May 89 19:07:42 GMT References: <950025@hpclcdb.HP.COM> Organization: HP Lake Stevens, WA Lines: 62 Just as a side comment (that I probably should not even be making here), but something I have long wanted to say: I first learned Pascal, and have recently been learning C. My first impression was that, for the most part, C was a "shorthand" version of Pascal (such as using '{' for 'BEGIN'), for those who do not know how to type, or do not want to type a lot, or are lazy, or have to work only through old, slow teletype systems. 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). Typically I find, as someone else has written: > ... the machine code emitted for the C statement mostly matches > the paradigm of Pascal statements you specified... So why write in the terse C format? I personally think that loop = loop + 1; is more clear than loop += 1; or the horrendous loop++; And I despise things like y = ++x; where one has to remember small details (like increment before or after?). (Working with pointers in C can be a real nightmare because of things like this.) If written out in the Pascal style (which can be done in C) there would not have to be any remembering, for it would be very clear. The code generated (depending on the compiler) is not any different for the first three statements, but logically the first is understandable even to those who know nearly nothing about programming. (But maybe that, in part, is why people like to use C. It is a specialized, hidden language like the Lawyers use to hide or obscure details from "common" people.) 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). Yes, there are truly occasions where C is a better choice for writing programs, but personally I believe that is a very small percentage of the time. Since I do not write operating systems, and I feel the code generated by Turbo Pascal is outstanding (excepting the occasional place where assembly language needs to be used, which is true even in C), I use Pascal predominantly.