home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!pmafire!news.dell.com!swrinde!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
- From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
- Subject: Re: FORTRAN bug(was Re: C++ vs. Ada -- Is Ada loosing?)
- Message-ID: <1992Dec14.165537.18275@mksol.dseg.ti.com>
- Organization: Texas Instruments Inc
- References: <EACHUS.92Dec7184734@oddjob.mitre.org> <1992Dec8.072300.21473@smds.com> <1992Dec8.172551.16780@newshost.lanl.gov> <1992Dec9.060218.23940@seas.gwu.edu> <1992Dec11.132942.24054@mksol.dseg.ti.com> <1992Dec11.163811@lglsun.epfl.ch>
- Date: Mon, 14 Dec 1992 16:55:37 GMT
- Lines: 164
-
- In <1992Dec11.163811@lglsun.epfl.ch> nebbe@lglsun.epfl.ch (Robb Nebbe) writes:
-
- >Michael Feldman:
-
- > int x;
- > ...
- > x = 1;
- > while (x <= 10);
- > {
- > printf("%d\n", x);
- > x++;
- > }
-
- >For 10 points on your grade: what is printed? Why?
- >Try explaining it to a freshman.
-
-
- >Fred McCall:
- >
- >Nothing is printed. You built an infinite loop. This is hard to
- >understand? You made a while loop with an empty body and a condition
- >that is never met because you never increment x. Your freshmen don't
- >get this?
-
- >Me:
-
- >Good syntax means that code should do what it looks like it should do. The
- >above code is an example of less than optimal bordering on poor language
- >syntax.
-
- It looks like it does what it should do to me, other than the abysmal
- and unnecessary use of braces and indentation. It's the language's
- fault that poor coders can write poorly formatted code?
-
- >The reason being that many compilers don't detect that what is
- >obviously wrong code is wrong. On top of that the problem is rather inocuous
- >and if I didn't know that the problem was there I might miss it when reading
- >through the code. Basically the presence of a typo must be detected by having
- >your program hang. A far from optimal situation.
-
- Well, I prefer to think of it as the presence of a typo must be
- detected by knowing the language -- a situation that is hardly
- peculiar to C, and that is, in fact, pretty much a prerequisite for
- writing working code in ANY language.
-
- >The far worse problem with C syntax is the one that caused the problem for
- >ATT. (This is all second hand so anyone in the know should correct me if I'm
- >wrong.) A programmer had left out a break in a switch statement. I don't
- >know the what the actual code was like by a switch looks like this.
-
- From reports I've seen, this isn't what caused the problem.
-
- > switch (x)
- > {
- > case 1:
- > printf("x == 1\n");
- > break;
- > case 2:
- > printf("x == 2\n");
- > break;
- > default:
- > printf("x != 1 && x != 2\n");
- > }
- > printf("done");
-
- >The break is necessary to leave the switch because the cases only serve as
- >labels and execution will fall through to the next case statement. This is a
- >case (no pun) where assembler shows through the C syntax. The machine code that
- >is generated for the switch is a jump table based on the value of x. At the end
- >of the statements another jump is required to avoid executing the rest of the
- >code from the other case statements.
-
- Gee, once again one is expected to know the language to write working
- code in the language. Funny how that works. And if I implement the
- wrong algorithm in Ada, it will tell me that I've made an error?
-
- Just by the way, I believe that the actual problem was caused by
- someone who put a 'break' statement inside an 'if', with the intention
- of exiting the 'if' from the middle. Of course, this doesn't work,
- and he actually wound up leaving an enclosing loop prematurely. It
- was something like that, anyway. The problem was the PRESENCE of a
- 'break', not the absence of one.
-
- >The fact that these problems exist in C is well known and most C texts point
- >them out. I would like to point out that these idiosyncracies have not
- >prevented C from being succesfully used in a phenomenal amount of code.
-
- >People need to put C in perspective. When people started using C it was
- >because the choice was between assembler and C for many projects. For larger
- >projects the choice was between something like FORTRAN with some assembler
- >and C. My experience in mixing assembler and FORTRAN is very limited but it is
- >far from a trivial endevour. In both cases I would unhesitatingly choose C.
-
- >Now there are other choices such as Ada for doing programs that interface with
- >the hardware. Why do people keep using C? A lot of it has to do with inertia.
- >Another reason that we shouldn't forget is that a good C/C++ programmer can
- >turn out some very high quality code and if it aint broke don't fix it. In
- >fact I would go as far as to say that well written C/C++ code is almost as
- >readable as Ada.
-
- Personally, I find well-written C a lot MORE readable than Ada. But I
- think the point is well taken. It is possible to write opaque code in
- ANY language.
-
- >The problem with Ada is that it is a lot more difficult to do code generation
- >in my head ;-) Some of you will scoff but my education is in computer
- >engineering (thus hardware) and there is a tremendous amount a satisfaction in
- >knowing what it is that I am telling the hardware to do and not just in the
- >abstract sense.
-
- >When I program in Ada this sense of satisfaction is just not there. Programming
- >in C is sort of like making a piece of furniture yourself from scratch and
- >programming in Ada is like buying a kit.
-
- >However I put such personal feelings aside when I have to do a project because
- >my level of confidence in 5000 lines of Ada is definitely higher than my
- >level of confidence in 5000 lines of C/C++. This isn't that I'm a better
- >programmer in Ada than in C/C++. To the contrary I'm sure that I master C
- >better than Ada but I probably know Ada better than C++. The reason is that
- >when I write code in Ada it usually won't compile if it wasn't what I meant.
- >In C/C++ the compiler isn't as helpful. For novice Ada programmers however this
- >is viewed as frusterating because the compiler won't except their code and it
- >is what they mean :^)
-
- >Michael Feldman:
- >|> >Any similar idiosyncracies in Ada?
-
- >Fred McCall:
- >|>
- >|> Single character ones? Probably not, but that just indicates that Ada
- >|> is incredibly more verbose than C. One of the things I DISlike about
- >|> it, by the way.
-
- >Me:
-
- >Actually the fact that Ada is verbose has absolutly nothing to do with the
- >fact that it doesn't have any similar idiosyncracies. The difference is that
- >the syntax of Ada was studied to avoid such problems and this wasn't a
- >concern when they thought up the syntax for C. If they designers of C had been
- >interested in avoiding such problems it wouldn't have been too hard.
-
- Well, there is just a bit more to it that that, and I think someone
- back there a while ago posted a list showing a few 'peculiar'
- structures for Ada, as well. I wish I still had it.
-
- >Robb Nebbe nebbe@lglsun.epfl.ch
-
- >P.S. If you don't put the breaks in the switch it would print the following
- >if x == 1:
-
- >x == 1
- >x == 2
- >x != 1 && x != 2
- >done
-
- This is a surprise? If you don't put in the print statements it
- doesn't print anything. These two results are about equally
- surprising.
-
- --
- "Insisting on perfect safety is for people who don't have the balls to live
- in the real world." -- Mary Shafer, NASA Ames Dryden
- ------------------------------------------------------------------------------
- Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
-