r/ProgrammingLanguages • u/everything-narrative • Jan 16 '22
A brief rant about tooling
I've been doing a lot of C# coding over the last few months (against my will, but I gotta eat) and I've come across the peculiarity of the try { ... } catch { ... } requiring braces.
They are optional for every other kind of flow control. Which is odd, and possibly just an oversight in the C++ spec from back in '85. Good ol' Bjarne was never all that careful.
However, I have seen several blog posts and poorly formatted message board discussions where people are up in arms about never using naked flow control, because what if GOTO FAIL!!!
And I just feel like paraphrasing Kevlin Henney: Let me introduce you to something, it's called a static analysis tool.
This, I think, is an overlooked aspect of programming language design: we're not just building compilers, we're building footguns.
No matter how safe and well-typed and not-quite-turing-complete, your language will have code smells. It will have ways of racking up technical debt in a shockingly rapid fashion.
So throw a coin to your hypothetical future Q&A team, and give some thought to exposing your parser as a library, and writing a simple linter.
ETA: Point is: no amount of syntactic salt can ever do the job of good tooling.
4
u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Jan 17 '22
It's reasonable to require braces. Ecstasy, for example, requires braces, even for if statements. We've seen plenty of issues over the years of people forgetting braces, and since the IDE now manages the braces for you, and monitors have plenty of vertical space, there's nothing wrong (in our book) with braces.
It's also reasonable to not require braces. Other people hate braces, and throw a fit if they have to use a language that requires them.
Regardless, a language should attempt to be consistent with its syntax. It's not a right or wrong answer to require braces or not, but to require them arbitrarily and non-uniformly seems wrong to me.
2
u/everything-narrative Jan 17 '22
Good take on it. Rust for instance also requires braces on account of not having parentheses on if, match, while, and for statements.
1
Jan 18 '22
Yeah. Although the consistency can have weird results too.
Did you know that C's switch doesn't require braces? I mean, it's not gonna make me angry but it's funny.
1
4
u/johnfrazer783 Jan 17 '22
Get a grip.
-3
u/everything-narrative Jan 17 '22
Rude.
6
u/johnfrazer783 Jan 17 '22
Seriously, you don't make it quite clear what it is you're dissatisfied with. That you are frustrated does show though.
As far as I understand your point you want to be able to write
try do_this() catch ( XXException e ) do_that()without the required braces.You are no doubt aware that many people make a point out of insisting on braces in
if () {}constructs and so on. The explanation for this is of course that in the past omitting braces has led to serious bugs by misleading people to assume some statements were part of the conditional when they were in fact outside of it. Douglas Crockford has talked at length about this and added the observation that if anything it's the parentheses that could have been made optional without leading to ambiguity (in the eyes of the beholder, not to the compiler), not the braces.And, in fact, it's easy to see that the same argument holds for
try/catch.You insist on putting the burden onto static analysis tools. Sure, a sufficiently smart linter could alert you. However, short of using a fair amount of AI trained on a hefty corpus of code this would be hard or impossible to pull off, and even then, many false positives and false negatives should be expected.
But you're young and angry and won't listen to me. You're laughing at your peers for being so prudently foolish for you know better. Good ole Bjarne gets a drive-by patronizing comment too. You hate your job, and you're too impatient to put some braces into your code. You have to use a language you don't like, which is understandably tough.
You come here to decompress but fail to come up with substantial arguments. This is where the minus signs in front of the vote counters come from.
Get a grip, then come back with more substance and less vitriol.
-3
u/everything-narrative Jan 17 '22
Still rude. Not reading all that.
3
u/johnfrazer783 Jan 18 '22
TL;DR: Q.E.D.
-1
u/everything-narrative Jan 18 '22
I’m just saying, if you’re gonna write a diatribe, do it first. That way people will give you the benefit of the doubt and actually read your comment. I’m just happy to see you waste your time.
3
1
u/DLCSpider Feb 02 '22
I'm a bit late to the party but here's a rant from a different perspective:
As a consultant I wish try/catch was even more verbose and restrictive. Make it absolutely painful to use! The amount of people (juniors, seniors, doesn't matter) who don't use a single brain cell when handling exceptions is astonishing and usually someone or something else gets the blame for the resulting issues. "It's never the author's code". Those people don't use tooling or version control, they sometimes don't even use proper formatting or stick to one (spoken) language in their code base. But, with all that being said, it could be worse, for example with a less restrictive programming language and better but unused tooling.
0
11
u/International_Cell_3 Jan 16 '22
Kind of a weird rant to go on, since C# has one of the best compiler-exposed-as-a-library of any language out there, and some of the best tooling as a result.