5 ms·
(Only tangentially related to the OP, but what the hell.) Does anyone here have an experience programming in Oberon-07? One of the most interesting features o
by ainar-g 7y ago
(Only tangentially related to the OP, but what the hell.)
Does anyone here have an experience programming in Oberon-07? One of
the most interesting features of the language for me is the fact that it
doesn't have a BREAK statement. Which means that one must use a form of
WHILE for linear searches. Probably to force people to think in terms
of structured programming instead of the logic of “hidden GOTOs”. Does
it ever bother you? Did you ever had a thought like “Sheesh, this would
be so much better with a FOR and a BREAK.”?
- olaf 7y agoIt has LOOP and EXIT, I remember that turned out to be the most used repetition construct when I was using (IIRC) JPI Modula-2. For me, it was so easy to think about loops that way, with an EXIT/condition in the middle of the loop body.
- ainar-g 7y agoYou're probably thinking of the original Oberon. Wirth has removed both LOOP and EXIT from Oberon-07. See here: http://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf http://people.inf.ethz.ch/wirth/Oberon/Oberon07.pdf.
- vbezhenar 7y agoYou can easily emulate break with conditional variable.
- ainar-g 7y agoOf course, but wouldn't that effectively defeat the purpose of removing BREAK/EXIT in the first place? With something like: WHILE ~(lastIteration) & ~(Found(haystackPart, Needle)) DO (* Advance the haystackPart. *) END; I can at least say that after the loop if lastIteration is true, then the needle wasn't found in the haystack. While something like WHILE ~(found) DO (* Stuff. *) END; Conveys next to no information. To say nothing about the fact that the body of the loop will probably be full of: IF ~found THEN (* Stuff. *) END
- microtherion 7y ago> Of course, but wouldn't that effectively defeat the purpose of removing BREAK/EXIT in the first place? Personally, I do like having BREAK/EXIT, but in the eyes of structured programming purists, a loop with an explicit conditional still has a single entrance and single exit, while BREAK/EXIT statements destroy this property.
- bhaak 7y agoAn elegant solution (if applicable) is placing a deliberate sentinel value at the end of your data before looping. https://en.m.wikipedia.org/wiki/Sentinel_value https://en.m.wikipedia.org/wiki/Sentinel_value Whereas usually loops have 2 tests for checking if the while loop should end (end-of-data-reached? or break-condition-is-true?) you only need to check for the latter. This is a very Oberonesque programming optimization.
- pjmlp 7y agoC++ as well, to the point that C++20 ranges have the notion of end sentinel values built in.
- ainar-g 7y agoI'm sorry, but I don't see how that answers my question. Oberon-07 has real FOR loops over arrays, so it doesn't need sentinel values. My question was about an idiom like: WHILE True DO (* Stuff. *) IF someCondition THEN EXIT; END; (* More stuff. *) END;
- badsectoracula 7y agoMy guess is that Wirth's approach would be to avoid having too much logic in a loop (if really necessary, break it into separate procedures) and if needed to do something like WHILE ~someCondition DO (* Stuff *) IF ~someCondition THEN (* More stuff *) END; END; In general from a quick look at the projectoberon.com source code (which is largely written by Wirth) the vast majority of WHILE and REPEAT uses seem to be less than 4 lines long.
- bhaak 7y agoI answered for a sub space of all the possible problems that can be solved with LOOP and EXIT which lend themselves to a much better structured approach. Also, you were jumping to FOR loops over arrays. But instead the sentinel values are much better suited for linked lists. What a programming language allows shapes how you program in it. The Sapir-Whorf Hypothesis is probably much more true with programming languages than natural languages. One of Wirth's mantras is "don't show me your code, show me your data structures and I'll immediately know if your code is any good". There are certainly moments when I would like to have certain programming constructs. But then I have to solve the problem in another way. But this happens in a lot of languages. Be it C, Ruby, Javascript, or Oberon (whatever version).
- gmfawcett 7y agoOn a tangent to your tangent: the `while` and `for` loops in Ocaml also do not have a `break` statement. Early exits are typically achieved by raising and catching an exception (which fortunately is quite efficient in Ocaml).