back to article Next; tech; meltdown..? Mandatory; semicolons; in; JavaScript; mulled;

In what non-technical people might take as an attempt to outdo the absurdity of the tabs vs. spaces debate that continues to divide programmers, the TC39 technical group that advises the development of ECMAScript – the specification from which JavaScript is implemented – has proposed telling web developers to terminate …

SVV
Silver badge

Re: ...programmers, aware that every additional character offers another chance to make an error...

Yes Someone who finds clarity in code important is invariably also a good programmer (becsause it shows thought and understanding of the craft)

This is really a debate between compiled and interpreted code - and I MUCH prefer the former as you have to follow the rules 100% to even compile successfully. My experience with Javascript and its' "this may or may not work or it also may not work in the way you thought it would" character led me to avoid taking on any job that even hinted that I might have to use it again after my one hateful experience with it.

Androgynous Cupboard
Silver badge

Re: ...programmers, aware that every additional character offers another chance to make an error...

Personally I leave all the brackets out of my equations, as by this metric it makes them more likely to be correct.

elDog
Silver badge

Re: ...programmers, aware that every additional character offers another chance to make an error...

OMG, another FORTH programmer! On El Reg!

Nothing but words and pages.

Of course, the dream language of special characters that mean a lot is APL.

Mike Pellatt

Re: ...programmers, aware that every additional character offers another chance to make an error...

Of course, the dream language of special characters that mean a lot is APL.

Yabut... invert a matrix with a single operator. That's class. (Not touched the language since 1974. Still remember that. Awesome.)

TotallyInfo

Re: ...programmers, aware that every additional character offers another chance to make an error...

Now you are talking. Both of those are in my past!

FORTH: great for squeezing the entire operations of an airport into something no bigger than a raspberry pi! But really head-twisting to get the reverse-polish notation right :)

APL: Spending a week puzzling over a single line of code that recalculated the universe - magic! Of course, useless if you ever wanted to go back and change it 6 months later! Loved it nonetheless, made me feel like I was a mathematician :)

Tom 7
Silver badge

Bad programmers blame the syntax.

Its a bit like colour or fonts - the computer doesnt really give a shit and yet I've had half my life wasted in meetings while tossers argue about what colour and font 'means'. Just follow the project/company guidelines - or in the case of things like font or colour move everything that depends on it to the design department (that's what CSS is for ffs) so the anally retentive can worry about it while you get on with the code.

Don't argue with wanky style guides - argue with the computer. At least there's some logic there to get your teeth into and you have a chance of winning.

And if you are so old you cant adopt your coding style you should at least be able to write the code that will convert your coding style into whatever is required.

Doctor Syntax
Silver badge

Re: Bad programmers blame the syntax.

"And if you are so old you cant adopt your coding style"

Ah, poor little orphan coding style, looking for new parents.

Paul Hovnanian
Silver badge

Re: Bad programmers blame the syntax.

Oh boy! This brings back memories.

Back when I was working on some automated knowledge capture, we ran into Microsoft products. Engineers who had written documents originally intended for human consumption had created tabular data by adjusting cell entries with a suitable number of tabs and spaces. And then to make larger entries fit their column, scrunch the font down for that one cell. OLE had barely been invented and most engineers couldn't be bothered to embed a spreadsheet object into a text document. And since there were no strict style guidelines (other than make it look nice for the boss), everyone had their own solution.

We eventually did fix the problem with some heuristics that could recognize things that looked like tables, calculate column widths based on font selection (among other things) and make a pretty good guess as to what was going on. The final solution was to import the parsed content into SGML and dump the author into the appropriate editing environment with structure and rules for the next data set version release.

eldakka
Silver badge

Re: Bad programmers blame the syntax.

> And if you are so old you cant adopt your coding style you should at least be able to write the code that will convert your coding style into whatever is required.

Sorta agree - I say sorta because you don't need to write your own...

There are plenty of "pretty print" programs out there that already do this. And they work much better when you have a structured language that requires braces and semi-colons and so on, much easier to parse for pretty printing.

Pen-y-gors
Silver badge

Memory time...

I have no problem with semi-colons;

I tend to put them in anyway just to be safe;

I'm also a fan of BEGIN/END or {} blocks, even when not strictly necessary, because {

They make it clear exactly what the scope of a statement is;

}

I learned coding 40+ years ago, on Algol W - that used semi-colons. Since then a fair proportion of the languages I've used (PL/1, Javascript, Java, PHP, Perl etc) have used semi-colons, so they tend to come as naturally as breathing;

I do agree though that it should remain a warning, or a lot of code will break;

Brewster's Angle Grinder
Silver badge

Re: Memory time...

El Reg slightly mangles this. (Imagine the + term was indented and there was a single line break)

return someObject.someMethodCall()

+ someOtherObject.otherResultRequired();

You know when you've been fucked by ASI.

Yes, there are myriad ways to fix this. The point is those of us who are adults still have to worry about ASI.

nijam
Silver badge

Re: Memory time...

> ... or a lot of code will break

you mean "a lot of code will be revealed to have been broken for years", surely?

druck
Flame

Re: Memory time...

No!

{

block;

}

elDog
Silver badge

Re: Memory time...

I think it should be a FATAL: "Do not use languages that permit ambiguity".

All decent Perl programmers turn on warnings and fatals. It's not just to catch programmers fat-fingering a wrong sequence but also to catch machine and data-dependent errors.

eldakka
Silver badge

Re: Memory time...

> I do agree though that it should remain a warning, or a lot of code will break;

From the context, they want to enforce strict semi-colon usage because ASI has issues with newer 'advanced' features that have complex requirements.

I imagine it would be pretty easy to have a detection routine that says "you aren't using any of the newer version X features, therefore I won't enforce strict semi-colon requirement". Therefore any code written before fancy feature X is defined won't have fancy feature X - because it doesn't exist - and can be detected as not needing strict. And any new code written after fancy feature X is introduced, but doesn't use fancy feature X, can also be detected as not needing it.

Therefore it should only enforce strict semi-colon if those features are detected.

Prosthetic Conscience
Trollface

"but it sounds like the TC39 is saying we're bad for using the language in a particular way"

He should switch to Perl

Pen-y-gors
Silver badge

Re: "but it sounds like the TC39 is saying we're bad for using the language in a particular way"

If there's someone you dislike, by all means wish that they catch a painful, slow and terminal disease or fall into something with lots of sharp blades, but NEVER wish that they switch to Perl!

Anonymous Coward
Anonymous Coward

Anyone seen a single line C program ?

Guy I used to work with - contractor. He worked on code normally, but ran it through a macro to strip out whitespace.

Compiled perfectly, but couldn't be worked on without the unadulterated source.

I imagine contracts are tighter now, so that legible source is mandated, but back then it wasn't. Eventually they had to pay a pretty sum to get the clean source so others could work on it.

Pen-y-gors
Silver badge

Re: Anyone seen a single line C program ?

APL couldn't be worked on even WITH the unadulterated source.

Lysenko
Silver badge

Re: Anyone seen a single line C program ?

That was common with xBase libraries and it's ubiquitous with JavaScript (uglfiy.js etc) because compressing out whitespace and converting variables to single characters reduces the size of downloads (bogus argument of course since you can just gzip the un-obfuscated source and any browser too retarded to support gzip isn't going to support ES5/CSS3 reliably anyway).

The key to success with JavaScript and it's tooling is realising that when you think:

"I'm missing something. It can't be this retarded. Turbo C/Visual Basic/Delphi was more advanced 20 years ago!?"

... you're wrong. It really is that retarded and the browser programming model really is Win16 redux, complete with message queues, async API callbacks, state machines a-go-go and no threading worth a damn. With ES8/TypeScript and web workers (threads) the JS eco-system might catch up to Delphi 3 on WinNT 4 by 2025 - maybe - but don't count on it.

[*] I've just spent 3 months writing an Angular 4 system so I'm not just ranting from the sidelines.

Alistair
Silver badge
Windows

Re: Anyone seen a single line C program ?

@ Pen-y-gors....

I have 300 page manual of APL somewhere. One of my exes mistook it for a book of mandalas.

Christian Berger
Silver badge

Re: Anyone seen a single line C program ?

That's actually something companies do in the car industry. They have to give out the code for contract reasons, but then they uglify it before sending it out for insanity reasons.

David Nash
Silver badge

Re: Anyone seen a single line C program ?

Why would you even do that? Was he desperate for that client never to offer him a contract again?

Androgynous Cupboard
Silver badge

Re: Anyone seen a single line C program ?

Actually, after 20 years of Java threading I'm coming around to the JavaScript everything-is-a-callback idea. Yes it's a bit clunky at times, but clunky is better than looks-correct-but-isn't, which is what normally happens with threads at some point. There's a lot to be said for a purely event-driven model.

Lysenko
Silver badge

Re: Anyone seen a single line C program ?

Actually, after 20 years of Java threading I'm coming around to the JavaScript everything-is-a-callback idea.

After 20 years of Java threading[1] one appreciates why GoRoutines were invented (or Erlang).

[1] Not that I've ever used Java in anger, but you can lose yourself in semaphore/mutex hell with C++ as well, which what I'm assuming you're referring to. Node/JS is equivalent to tackling flu by mandating mouth breathing and abolishing noses - you can always eat dinner with a callback after all.

Doctor Syntax
Silver badge

Re: Anyone seen a single line C program ?

"APL couldn't be worked on even WITH the unadulterated source."

APL and "unadulterated source" both in one sentence. Who'da thunk it?

Ken Hagan
Gold badge

Re: Anyone seen a single line C program ?

This must have been a *long* time ago. UNIX has had "indent" for about 40 years and Visual Thing has had something close enough for over 20.

el_oscuro

Re: Anyone seen a single line C program ?

I actually wrote a 1 line C program. And that code is still running in production.

I had a simple requirement: Run a shell script at a regular interval like every 15 minutes, and log the stdout/stderr to a log file. In Unix I would just put it in the crontab and be done with it. But I had Windows NT 4. The original AT scheduler was very limited but at least it worked. The installation of IE6 completely replaced it with a GUI which I could never get to work. And we couldn't use it as we didn't have RDP anyway.

So my program was basically:

int main(int argc,char *argv[])

{

system(argv[1]);

}

Why would I need this? We couldn't use cygwin or something like that for cron scheduling but we did have the Windows NT resource kit which included the SRVANY utility. This utility allows a command to be run as a service. But that command has to be an EXE and not a .BAT file. I also tried CMD /C but that didn't work either.

The scripts themselves handled all of the scheduling and logging, similar to Unix cron scripts that configure the environment.

10 years ago, we were 100% Windows and these scripts ran *everywhere*. Now we have migrated much to Linux but there are still production applications that use this 1 line program.

Tom 7
Silver badge

Re: Anyone seen a single line C program ?

Proper C programmers use this as a style guide: https://www.ioccc.org/

If you look hard enough there is code that looks exactly like the output it produces - this has to be the ultimate commenting!

Anonymous Coward
Anonymous Coward

Re: Anyone seen a single line C program ?

> Guy I used to work with - contractor. He worked on code normally, but ran it through a macro to strip out whitespace.

What an imbecile.

> Eventually they had to pay a pretty sum to get the clean source so others could work on it.

That would have been the last cheque he got from his employer too. Not to mention that word gets around quickly.

Anonymous Coward
Anonymous Coward

Re: Anyone seen a single line C program ?

> it's ubiquitous with JavaScript (uglfiy.js etc) because compressing out whitespace and converting variables to single characters reduces the size of downloads (bogus argument of course since you can just gzip the un-obfuscated source and any browser too retarded to support gzip isn't going to support ES5/CSS3 reliably anyway).

It was not entirely a bogus argument before HTTP/2, because it also reduced the number of requests, which is where the speed improvements mainly came from.

Nowadays, with gzip encoding and HTTP/2, I am not sure there is much client-side value in packaging assets like that, although there are still some caching improvements and it makes life slightly easier in terms of the build chain (pull with npm, then use browserify or the like to put in the right place, etc.).

Anonymous Coward
Anonymous Coward

Re: Anyone seen a single line C program ?

> Actually, after 20 years of Java threading I'm coming around to the JavaScript everything-is-a-callback idea.

New code no longer uses callbacks, by and large. It would be promises or async / await (which are promises in a different guise).

P.S.

Word of advice: stop reading Stackoverflow. It is full of obsolete "advice", much of it non-quality-controlled copy and paste from a regular web search by people who are into gamification (they get "rewards" of no physical value, such as additional icons next to their name) and have better google skills than you and more time in their hands. On top of that, Google's algorithms seem to weight the site heavily so that copy/paste gets amplified. Remember that Google relies on popularity, not necessarily correctness.

Jonathan 27

Re: Anyone seen a single line C program ?

If I was his supervisor I would have bitched him out on the first comment-less and whitespace-less commit and if he continued cancelled his contract for poor code quality. If you're a contractor, everything you produce belongs to the company, they're paying you for your time, not whatever you feel like giving them.

Jonathan 27

Re: Anyone seen a single line C program ?

Promises are just a better way to use callbacks. It's all syntactic sugar.

Anonymous Coward
Anonymous Coward

Re: If I was his supervisor

Yes, well, the problem is few workplaces are perfect - as you well know.

This is the same company (now defunct) that hired an Oracle SQL guru to rewrite T-SQL stored procs. Was there 6 months. Fucked off. We loaded his "code" up and discovered that he'd done **** all for 6 months. Cue my having to crash-learn Oracle SQL to get it working for the client.

Hindsight is a wonderful thing.

At a previous employer, there was a contractor who was the only resource that could work with SCO-Unix. They couldn't sack him, and he repeated declined suggestions that he become an employee.

Jove
Bronze badge

"This makes me a little sad. JS is the only language I write, and I don't use semicolons. I know it's just a warning clause, but it sounds like the TC39 is saying we're bad for using the language in a particular way. And it, feels, well, a little hurtful."

Poor kid; don't you just feel for it.

spold
Bronze badge

What's old is new again

Algol 60;

Anonymous Coward
Anonymous Coward

Re: What's old is new again

I'm sure I've encountered a langauge which use double-semicolons as statement terminators but can't remember what it was

elDog
Silver badge

Re: What's old is new again

And JOVIAL (Jules Own Version of the International Algorithmic Language).

I actually had to code in it for a short while since Ada hadn't been fully specified for the intended satellite use.

Again, a call-out to FORTH and PROLOG!

sweh

Re: What's old is new again

"I'm sure I've encountered a langauge which use double-semicolons as statement terminators but can't remember what it was"

shell script "case" statements use ";;" to end the case

eg

case $a in

x) foo ; bar ;;

y) baz ;;

*) echo Ooops ;;

esac

sawatts

Always prefer a language to require the developer to be explicit rather than having to guess their intent.

However if you think tabs vs spaces don't matter you've not had to maintain a lot of makefiles.

Meanwhile recall the proposal to provide whitespace operator overloading in C++?

[http://www.stroustrup.com/whitespace98.pdf]

Although the worse example I recall being told about was a proposed language for minicomputers which used normal, italic, bold as part of the language syntax. ...until it was pointed out that in some situations you'd have to be able to tell the difference between a normal and italic full stop.

Simon Harris
Silver badge

"a proposed language for minicomputers which used normal, italic, bold as part of the language syntax"

How about this one then...

https://en.wikipedia.org/wiki/Whitespace_(programming_language) ?

Christian Berger
Silver badge

Why stop there?

I mean if there's a component in Javascript compilers adding semicolons, why stop there? Why don't we standartise it to also add random +4 or similar things to the code, if a semicolon is missing.

Simon Harris
Silver badge

Optional syntax characters.

I'm using this as a precedent to considering decimal points optional next time I make an expenses claim.

AndrueC
Silver badge

That didn't work with SQL programmers. What makes them think that JavaScript programmers are more likely to adhere to such a rule?

PiltdownMan
Facepalm

What about FULL-STOPS

I remember writing a very small COBOL program (back in the Jurassic period, I think it was) of around 100 lines. I missed ONE full-stop out, leading to 400+ error messages!!!

I inserted the offending missed full-stop ( by replacing the erroneous 80 column punched card ) and all the errors disappeared.

Nice!!

Throatwarbler Mangrove
Silver badge
Thumb Up

Re: What about FULL-STOPS

Username checks out.

Jonathan 27

Yeah...

"What's more, this laissez-faire approach makes JavaScript fairly forgiving, which in turn makes it more appealing to inexperienced programmers."

And also a terrible choice for inexperienced programmers, a language with strict typing is much easier to debug and therefore a better choice for inexperienced programmers.

As for semi-colons, I always put a semi-colon on the end of every line in JavaScript. You can really kill yourself looking through code forever just to find an error caused by a missing semi-colon. Making them a language requirement will prevent a few errors, but it will also not be backwards compatible. Is the small benefit worth the small risk for existing code bases? I'd say it's defendant on what your existing code looks like. For mine, it looks just fine.

Mike Pellatt

ObColonsInProgramsReference (OK, it's not semicolons. But it still makes me giggle. And so true).

DrXym
Silver badge

Code formatters often remove them

I write semicolons out of force of habit since most C-like languages require them. But when I run a code formatter, one of the rules will normally strip out the unnecessary ones.

Personally though I think this is symptomatic of the dog's dinner that is Java / ECMAscript. Poorly thought out legacy behaviour that keeps biting people on the ass even to this day. See also the difference between null and undefined - if null was a billion dollar mistake I wonder how much of a mistake undefined is. Or the laughable scope rules for var. Or the difference between == and ===. Or the binding (or not) of this. And a million and one stupid other things.

I'm glad that WebAssembly is a thing now. In time it will provide a choice for web development which doesn't involve writing directly or indirectly (via Typescript / Coffeescript et al) in Javascript. Let Javascript go back to what it was supposed to be in the first place - glue.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon

Biting the hand that feeds IT © 1998–2018