pascal
Ah, Borland, come back;
happy days;
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 …
It's not about the feels, it's that JavaScript is ambiguous if you rely on ASI. I thought any programmer would have been able to understand that.
It's also ambiguous in a thousand other ways too, but I guess nobody's going to do the decent thing and take it round the back of the woodshed and shoot it, so we'll have make do with minor improvements like this.
Like most programmers, I guess, I have strong opinions on tabs vs spaces, but why the hell is a semicolon an issue? Most languages I've used have insisted on them so I use them habitually and can't see the issue in adding them.
For tabs vs spaces, the only argument I can see for spaces is that online resources use spaces so it makes grabbing snippets easier. Tabs lets the developer choose how big an indent they want, and (potentially) lets every developer have their own preference without messing up other people's code. But, honestly, most IDEs nowadays let you toggle back and forth easily enough that I'm not sure why anyone cares.
Can be a real pain with Python where the number of characters forming the indent specify the block level.
Does that line have an indent of '1' or four?
Unambiguous if a space is used, but it may appear as multiple spaces if tabs are used - e.g. two in one editor and four in another. Gets really nasty to work out why the code doesn't work as expected if a mix are used - code may be at different block levels even when it shows as being at the same level.
RPG II anyone? Each position on the first line was another configuration parameter and woe betide you if you missed a character.
Then setting flags, using exact column positions.
Give me semi-colons and tabs/spaces any day!
And what about in-line or hanging opening curly brackets?
So, by that line of reasoning, Lisp should be shot because _I_ think its excessive use of parentheses sucks? Despite being a super clever language with devoted followers?
Hint: in both cases, their formatting approach is a meta design-feature. Plenty of people like that design, plenty do not.
If you don't, then don't use them.
Thankfully languages are not like Maduro in Venezuela, plenty of choices around.
Heck, I've even heard from reliable sources that some people like PERL.
"languages that need whitespace to decide the structure of a program should be similarly taken around the back of the shed."
I can see why someone thought it would be a good idea. I can also see why it isn't. An IDE that automates indentation or something like cb is a better solution.
> "I can see why someone thought it would be a good idea."
Me too. Some programmers obsessively indent their code to keep it visually clear. They have also noted how the curly braces or parentheses can be logically implied by their ever-present indentation. It is therefore natural that they should take the next step and remove those maddening braces! Thus were born the indent-aware languages.
Python is liked by those who also like to indent anyway. This is good because such people tend to be strong performers, and having a language they are comfortable with cannot be a Bad Thing. No one is forced to use Python (well, hardly ever) and the rest of us are happy with our sloppy braces.
Yeah, well, that was because no-one uses punch cards any more.
Really, once they went the way of the dodo, the Proper Thing to do was absolutely to treat any amount of contiguous whitespace equally. I have that etched into my brain thanks to 'C', which is probably one of the reasons I grapple with Python.
languages that need whitespace to decide the structure of a program should be similarly taken around the back of the shed.
Because? Block delimiters are required for the compiler whitespace is just as good for this as semicolons are and have the advantage of increasing readability.
"Gets really nasty to work out why the code doesn't work as expected if a mix are used"
Dont you have a just-fixit script to replace all tabs with 4 spaces? it saves loads of aggro when copying and pasting a mish mash of stackoverflow answers, some with tabs and some with spaces. :P
Can be a real pain with Python where the number of characters forming the indent specify the block level.
Only if you're an idiot and mix tabs and spaces (or spaces and more spaces) in indentation.
Does that line have an indent of '1' or four?
"Does that line have an indent of 2, 3, 4, 5, 8 spaces?"
Unambiguous if a space is used, but it may appear as multiple spaces if tabs are used - e.g. two in one editor and four in another.
So someone who reads 8-character indented code more easily could read your code more easily? The horror!
Would you prefer to force all developers to work with the same font and text size? That would make it even more unambiguous!
Gets really nasty to work out why the code doesn't work as expected if a mix are used
And yet you spacers conveniently forget that you have even worse problems if two people both use spaces, but have their preferred "space" indent set to different widths.
Use an editor with visible white-space. Use an editor which auto-adjusts indentation behaviour to the file. BE CONSIDERATE.
By which, I mean: tabs are objectively superior.
That's what you get for using a language where white space carries a semantic content. It really is a misguided design.
Python's semantic whitespace is clearly an inferior imitation of Damian Conway's Acme::Bleach module for perl. From the description: The first time you run a program under use Acme::Bleach, the module removes all the unsightly printable characters from your source file. The code continues to work exactly as it did before, but now it looks like this:
use Acme::Bleach;
Plenty for the tab vs space people to argue over!
"Gets really nasty to work out why the code doesn't work as expected if a mix are used - code may be at different block levels even when it shows as being at the same level."
Not if you use a decent editor, it doesn't (I prefer emacs - your own tastes will vary)
But then what do I know? I've only been a Python dev for 15 years ...
(I'm not saying that it's a particularly _good_ idea, but the people who use it as a stick to beat Python with clearly haven't used it for any length of time. Or have a crap text editor.)
If a mix is used, the whole file is declared syntactically invalid. Problem solved.
A computer should never guess what the programmer meant. Tolerance has its place, and that place is end-user input. Programmers should just get it right and they should have the input thrown back at them repeatedly until they do that.
Funnily enough, this is also the answer to JavaScript's semi-colon question.
Berlin-based developer Yoshua Wuyts laments
Berlin-based hobbyist, I think you mean. I have never met a developer who only used a single language, except for some embedded guys who do everything in C (and even they know several ASM flavours). If all you know is JS then you're equivalent to a VBA power user writing Word macros, which is a useful skill but doesn't give you a credible perspective for addressing language design issues. Listening to guys like this is how Personal Home Page managed to become and remain the worst language in the world (tm).
And it, feels, well, a little hurtful."
Get used to it, snowflake. You're dealing with computers here. They don't "do" empathy and they don't give an Aardvark's left testicle about your emotional state.
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.
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.)
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 :)
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.
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.
> 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.
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;
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.
> 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.
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!
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.
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.
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.
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.
> 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.
> 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.).
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.
> 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.
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.
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.
"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.
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.
"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) ?
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!!
"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.
ObColonsInProgramsReference (OK, it's not semicolons. But it still makes me giggle. And so true).
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.
<rant>Would dearly love to remove the code formatting in Visual Studio 2017. If you're writing web sites (C#, Razor, JS, CSS/SASS) you can't switch it all off. Well, you think you have, but then you try copying and pasting a bit of code, in the same page even, and bang, it's reformatted the damn thing for you. If you're not quick enough with Ctrl+z you end up expending more keystrokes fixing the formatting than writing the code. Needless to say, Microsoft couldn't give a flying f**k about it. I know, I've been on at them for years about it. Couldn't care less. All they want to do is the next whizzy thing no one asked for, not the basics everyone uses.</rant>
I had a long template literal to return from a function and I thought it would look better if I would put the return statement on a line of its own.
Of course, the function stopped returning any value at all, and because there was no actual code (only values) after the return statement, the interpreter wasn't putting out a warning either.
But I like JavaScript. It's crazier than R by a mile!
People are making this way too complicated. It's really this easy, just three simple rules:
1. Semicolons to terminate statements should be required. Anybody not using them should be fired.
2. Braces to denote blocks of code, even if just one statement, should be required. Anybody not using them should be fired.
3. Spaces (NOT TABS) should be required. Anybody using tabs should be fired.
I have just solved 99% of ECMAScript's issues in three simple rules. Where do I send my consulting invoice?