Forum > Suggestions
Simplifying compound control structures
JackD:
I love Pascal and have been programming in it for 30 years, but the one thing about it which irritates me is the ambiguity of compound control statements, especially in regards to if-then. This blog post sums it up :
Pascal’s syntactic ambiguity and C’s ineptitude
More generally, I'm taking about dispensing with begin-end in control statements, as Wirth did with Modula-2 and Oberon. It makes for clearer and much more readable code which has a pleasing symmetry about it.
I have no idea how much work would be involved to implement this, and it's probably been suggested before, but I'm interested in responses.
Handoko:
Multiple level if then else statement will be much clearer:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if cond1 thenbegin if cond2 then do_something1 else do_something2end;
or
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if cond1 then case cond2 of True: do_something1; False: do_something2; end;
Begin-end block and case statement are very useful to make the code clearer.
marcov:
While the M2 syntax is mostly IMHO better, there is a reason this hasn't happened yet. Compatibility is simply more important than microsyntax improvements that are mostly generated by IDEs nowadays anyway.
But if you want to invent a new language, go ahead.
JackD:
Hi Handoko,
I agree, if we have to make do with what we have. But neither are as clear as :
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if cond1 then if cond2 then foo else bah endend;
Actually, I don't use either of your suggestions, but this:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if cond1 then begin if cond2 then begin foo end else begin bah endend;
JackD:
--- Quote ---While the M2 syntax is mostly IMHO better, there is a reason this hasn't happened yet.
--- End quote ---
"yet"? So there is some hope, then? :D
--- Quote from: marcov on December 08, 2022, 10:56:28 am ---Compatibility is simply more important...
--- End quote ---
Yes, I suspected it would be.
--- Quote ---But if you want to invent a new language, go ahead.
--- End quote ---
I think I'll stick with Pascal. There's no such thing as a perfect language, and it's good enough. :)
Navigation
[0] Message Index
[#] Next page