Click here to Skip to main content
15,886,075 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
lopatir17-May-20 20:52
lopatir17-May-20 20:52 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy22-Oct-21 7:57
johnywhy22-Oct-21 7:57 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Lorenzo Bertolino17-May-20 20:59
professionalLorenzo Bertolino17-May-20 20:59 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 1:28
mveRichard Deeming18-May-20 1:28 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
KateAshman17-May-20 21:57
KateAshman17-May-20 21:57 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts17-May-20 22:48
kalberts17-May-20 22:48 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 1:33
mveRichard Deeming18-May-20 1:33 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts18-May-20 4:30
kalberts18-May-20 4:30 
You could e.g. look at CHILL, aka Z.200: Any block may have a handler attached: If there is an ON-clause between the body of the block and the terminating semicolon, the block has a hanlder. If there is no ON-clause, it does not have a handler. THere is no need to pre-announce it.

Note that in CHILL, as well as in most other sensible languages of the Algol class, a statement is a block; you don't need to enclose a single statement to make it one. So it would be like
CallSomeMethod();

CallSomeOtherMethod()     -- note: no semicolon - block not yet complete
ON (SomeFunkyException): 
  LogThisException(); 
END;                      -- here is the semicolon terminating the block
Usually when you want to attch a handler to a group of statements, that group is e.g. a function body, a loop, an if/then/else etc. defining a block. If these two calls are looped, and you want to attach the handler to the loop - i.e. the it is invoked when the exception breaks out of this loop, you would write it as
DO
   CallSomeMethod();
   CallSomeOtherMethod();
OD                        -- note: no semicolon; loop still incomplete
ON (SomeFunkyException):  -- handler for exception in the loop statement
  LogThisException(); 
END; 
The DO-OD bracing of the loop body makes it a block, to which a handler may be attached without any further blocking.

If you want to attach a handler to the two calls, not to the loop as such, you have to make them into block by bracing them:
DO WHILE ExceptionCount < 10;
   SomeCallNotHanldedByTheOnClause();
   BEGIN
      CallSomeMethod();
      CallSomeOtherMethod();
   END                       -- no semicolon - handler follows
   ON (SomeFunkyException):  -- handler for exception in the loop statement
      LogThisException();
      Exceptioncount +:= 1;
   END;
   AnotherCallWithNoHandler();
OD;
Now the handler for the two statements is processed within the loop, and unless another exception is caused, control stays within the loop.

CHILL uses keywords rather than braces; that is not the point here. Braces might have saved a few keystrokes, but since keywords often come in pairs, they do their own bracketing, like DO-OD, ON-END, ... You need to indicate which kind of block (like DO), and adding a brace to indicate "I am serious - a block!" is redundant. You could of course save a keystroke by replacing the OD with a closing brace, but I'd find it strange for braces not to come in pairs. I rather have an OD terminating a loop body, a FI terminating an IF statement and so on, documenting the type of block terminated, rather than a series of anonymous braces terminating a nest of blocks.

You could also note that the use of distinct keywords avoids a lot of other blurb, e.g.

BEGIN
   CallSomeMethod();
   CallSomeOtherMethod();
END 
ON (SomeFunkyException):   LogFunkyException(); Funkiness +:= 1;
   (SomeStrangeException): LogStrangeException(); Strangeness +:= 1;
   ELSE:                   LogOtherException(); EXIT SurroundingStatementLabel;
END;
Each ON-alternative defines a block, with no further need to bracket multiple statements.

CHILL is a language that was actually designed - it didn't end up that way by random luck because the space invasion game presented a new wish that K or R sat down the same night to put into the compiler as best they could. It was known before the first implmentation begun that no bracing was required to add exception handling to a block. That no bracing was required for each on-alternative. And so on. Consequences of the overall language design was considered before the spec was frosen.

So it was someting like that detestable "waterfall model", we'll have to admit that. That is a good enough reason for rejecting the language design, and rather go for one wit a lot of syntatical workadounds, braces, paretheses, keywords to pre-anounce what comes later and whathaveyou.

But please do not confuse "ability to create ugly workarounds that make the language survive" with good design!
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 4:39
mveRichard Deeming18-May-20 4:39 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts18-May-20 20:59
kalberts18-May-20 20:59 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 23:40
mveRichard Deeming18-May-20 23:40 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts19-May-20 6:55
kalberts19-May-20 6:55 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming19-May-20 7:31
mveRichard Deeming19-May-20 7:31 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Stuart Dootson18-May-20 0:59
professionalStuart Dootson18-May-20 0:59 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
BryanFazekas18-May-20 2:21
BryanFazekas18-May-20 2:21 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
W Balboos, GHB18-May-20 2:35
W Balboos, GHB18-May-20 2:35 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Member 1181677618-May-20 3:47
Member 1181677618-May-20 3:47 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
sasadler18-May-20 8:51
sasadler18-May-20 8:51 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek18-May-20 10:25
nedzadarek18-May-20 10:25 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
B Alex Robinson18-May-20 13:45
B Alex Robinson18-May-20 13:45 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Vikram A Punathambekar26-Jun-20 2:57
Vikram A Punathambekar26-Jun-20 2:57 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Kirk 1038982118-May-20 14:56
Kirk 1038982118-May-20 14:56 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek19-May-20 3:55
nedzadarek19-May-20 3:55 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts19-May-20 6:15
kalberts19-May-20 6:15 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy23-Oct-21 3:45
johnywhy23-Oct-21 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.