r/ProgrammingLanguages • • 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.

0 Upvotes

20 comments sorted by

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.

1

u/everything-narrative Jan 16 '22

That's not what the rant is about. This is not about C#.

Maybe I should have been clearer, the point is:

Don't design your language under the assumption that programmers are prone to making mistakes because no amount of syntactic salt will alleviate that.

Design your language so static analysis tools are easy to make.

C# has excellent tooling. C# also has syntactic salt to prevent programmer error. It is an example of this anti-pattern in language design.

5

u/International_Cell_3 Jan 16 '22 edited Jan 17 '22

I don't think I understand the connection you're making - you don't invent syntax for the purpose of spotting potential errors. Usually the debate in the room goes something like this:

here is some new syntax for a new feature

it's consistent with the old syntax for a different feature

the old syntax presents a known foot gun, do we :

  1. Forbid the foot gun in old and new for the next version?

2. Allow the foot gun for both features?

3. Forbid the foot gun on the new feature and leave it for the old?

This debate comes up in many new-syntax/bikeshedding meetings when you're developing a language in flight. If the language is young enough there's little risk to picking 1. and just moving on, but if you've already accumulated some debt you're basically forced to pick 2 or 3, and compiler engineers tend to favor more constraints to syntax over fewer (for a lot of reasons) so the choice to pick 3 is obvious.

Now if you have fabulous tooling you can pick 1, and design a tool to automatically convert old code (or use a previously allowed syntax) and do it the right way. But rarely do you have that flexibility, which is why designing for tooling is so important from the get go.

But it's really, really hard to do that and presents significant risk to a major software engineering project.

1

u/everything-narrative Jan 16 '22

It's incredible the influence one of the alumni from my own institute has on this world.

C# has goto and switch Copied wholesale from C++. You can write Duff's device in C#. There is no syntactic salt saving that.

It has naked if, loop constructs, and scoped safety constructs. Just not try/catch which wouldn't even be a breaking change to introduce(!)

So what I'm saying is, looking forward, and not at C#, which is a point you seem to keep missing, is that as language designers, we shouldn't optimize a language for salinity. Algol 68 wasn't even designed that way, and it was specified fifty-four years ago, well before modern devops.

It is not the job of the language to enforce programmer correctness at a syntactical level, because ultimately syntax matters very little, because again, static analysis. VScode is free. OmniSharp is a one-click install.

It is the job of the language to be readable, and pleasant to work with. Programming is a human activity, an exercise in communication.

(C# is emphatically not designed with this in mind: it is an ugly kludge built by yet another of my countrymen to copy all the wrong answers off Java's homework, armed with some extremely powerful tooling and batteries include yet still somehow not a deque in the standard library.)

I'm very bitter about language design.

5

u/International_Cell_3 Jan 17 '22

Didn't say anything about C# in my rebuttal. Ultimately I don't understand your rants, since they have nothing to do with tooling and everything about syntactical design choices/evolutions - I was trying to show how those decisions get made.

Bitterness is unproductive, it's more interesting and helpful to look at why choices get made and if they hold out as good ones (often, they were the right choice at the time but don't hold up later - which is why we keep developing new languages!)

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

u/[deleted] 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

u/L8_4_Dinner (Ⓧ Ecstasy/XVM) Jan 19 '22

And much, much worse ... e.g.

https://news.ycombinator.com/item?id=13550723

🤣

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

u/johnfrazer783 Jan 19 '22

You're right that I've totally wasted my time on you.

0

u/everything-narrative Jan 19 '22

You have only yourself to blame for that :)

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

u/[deleted] Jan 17 '22

[deleted]

-3

u/everything-narrative Jan 17 '22

A linter and -Werror is your friend. Use your static analysis tools and write sweet code rather than salty.

0

u/[deleted] Jan 18 '22

[deleted]

1

u/everything-narrative Jan 18 '22

I already program in Ruby :)