4 ms·
I love this sort of cs history. I’m also curious—why do we “throw” an error or “raise” an exception? Why did the for loop use “for” instead of, say, “loop”?
by seabass 1y ago
I love this sort of cs history. I’m also curious—why do we “throw” an error or “raise” an exception? Why did the for loop use “for” instead of, say, “loop”?
- antod 1y agoI'm guessing "throw" came about after someone decided to "catch" errors. As for "raise", maybe exceptions should've been called objections.
- zahlman 1y agoRuntimeObjection: autopsy report changed contents during cross-examination
- maxbond 1y ago"Exception" comes from hardware/state machines, and the name reflects that they may not be error cases. For instance, if an embedded device is waiting for a button press, then pressing that button will put the MCU into an exceptional/special state (eg interrupting execution or waking up from sleep). But surely those days are in the past. We should call them objections, because they're always used for errors and never for control flow. [1] After all, that would be an unconditional jump, and we've already settled that those are harmful. [1] https://docs.python.org/3/library/exceptions.html#StopIteration https://docs.python.org/3/library/exceptions.html#StopIterat...
- titanomachy 1y agoThat's a great question. The first language I learned was python, and "for i in range(10)" makes a lot of sense to me. But "for (int i = 0; i < 10; i++)" must have come first, and in that case "for" is a less obvious choice.
- masklinn 1y agoFOR comes from ALGOL in which as far as I know is was spelled: for p := x step d until n do
- Dwedit 1y agoBASIC had the FOR-NEXT loop back in 1964. 10 FOR N = 1 TO 10 20 PRINT " "; 30 NEXT N C language would first release in 1972, that had the three-part `for` with assignment, condition, and increment parts.
- zabzonk 1y agoIn Fortran, it is a do-loop :)
- bee_rider 1y agoFortran has grown a lot over time. If somebody said it don’t have a do loop in 196X, I wouldn’t be too surprised. Really it’s just syntactic sugar, just use a goto.
- pklausler 1y agoThe entire point of Fortran was being an effective optimizing compiler for DO loops.
- bregma 1y agoFORTRAN IV, at least the version I used on the PDP-11 running RSX, did not have a DO-loop. Just IF and GO TO. But it did have both logical and arithmetic IF.
- pklausler 1y agoI don’t believe this.
- kahirsch 1y agoThis reminds me of a little bit of trivia. In very old versions of BASIC, "FORD=STOP" would be parsed as "FOR D = S TO P". I found that amusing circa 1975.
- QuesnayJr 1y agoAlgol 58 had "for i:=0(1)9". C's for loop is a more general variant.
- flufluflufluffy 1y agoI think “raise” comes from the fact that the exception propagates “upward” through the call stack, delegating the handling of it to the next level “up.” “Throw” may have to do with the idea of not knowing what to do/how to handle an error case, so you just throw it away (or throw your hands up in frustration xD). Totally just guessing
- owlbite 1y agoI suspect it comes from raising flags/signals (literally as one might run a flag up a flag pole?) to indicates CPU conditions, and then that terminology getting propagated from hw to sw.
- comex 1y agoI would have thought it came from the concept of 'raising an issue' or even 'raising a stink'.
- Findecanor 1y agoSounds plausuble. Some of the earliest exception handling systems did not have any semantic difference between CPU exceptions and software exceptions.
- devnullbrain 1y agoYou can still use SIGUSR1 and SIGUSR2 for it.
- deleted 1y ago[deleted]
- reverendsteveii 1y agoidk because there are some circles in which boolean variables are called flags but I've never seen them referred to as being raised or unraised/lowered, only set and unset
- kps 1y ago
- baq 1y agoYou throw something catchable and if you fail to catch it it’ll break. Unless it’s a steel ball. You raise flags or issues, which are good descriptions of an exception.
- pansa2 1y ago“for” is short for “for each”, presumably. `for i in 1..=10` is short for “for each integer i in the range 1 to 10”.
- cb321 1y agoYeppers. For a few more details, one might start here: https://en.wikipedia.org/wiki/Universal_quantification https://en.wikipedia.org/wiki/Universal_quantification
- gmueckl 1y ago"For" for loop statements fits with math jargon: "for every integer i in the set [1:20], ..."
- deleted 1y ago[deleted]
- yongjik 1y agoIt's been ages, but I think an earlier edition of Stroustrup's The C++ Programming Language explains that he specifically chose "throw" and "catch" because more obvious choices like "signal" were already taken by established C programs and choosing "unusual" words (like "throw" and "catch") reduced chance of collision. (C interoperability was a pretty big selling point in the early days of C++.)
- jamesemmott 1y agoThe design of exception handling in C++ was inspired by ML, which used 'raise', and C++ might itself have used that word, were it not already the name of a function in the C standard library (as was 'signal'). The words 'throw' and 'catch' were introduced by Maclisp, which is how Stroustrup came to know of them. As he told Guy Steele at the second ACM History of Programming Languages (HOPL) conference in 1993, 'I also think I knew whatever names had been used in just about any language with exceptions, and "throw" and "catch" just were the ones I liked best.'