News for hackers. Stuff that matters.
Re:The Cost of JavaScript by PerryCox on Wednesday November 15, 2017 @02:26PM (#15706933)
We live in a world where everyone wants to make Electron apps instead of doing anything in a compiled language or anything other than JavaScript really.

Maybe it's because I've never been a webdev but I just don't understand the fascination with JavaScript. Personally I hate JavaScript any time I have to code in it. Give me literally any other language.

Re:The Cost of JavaScript by greggman on Wednesday November 15, 2017 @03:09PM (#15707301)
I programmed assembly then C then C++ through the the 80s, 90s and 2000s. I love JavsScript. It just so damn easy. No fighting with headers, include paths, linker options, make files , cmake files, scons files, etc. No cross platform bs. When I want to share I just send a link. Electron does have a few platform issues to build the app but they're most solved for me. I get formatting, styles, animation, for free. I get cross platform graphics, video, and audio for free, networking is trivial. I also get pretty amazing debugging tools.

iteration time is orders of magnitude faster than any C/C++ project I've ever worked on.

I hated JavaScript at first because I didn't understand it. It took about 2 year to stop trying to turn in back into C++. It didn't help that my first real intro was in an environment that used Google Closure and the closure compiler both of which were designed by Java programmers to try to treat JavaScript as Java and disallowed real JavaScript.

now I mostly loath going back to C++ and having to fight the dev tools on each platform which seem to change every 5 years such that all old samples fail.

is it JS perfect? no, i think I kind of miss static typing but not always. It's often a joy to just do it.

Re:The Cost of JavaScript by megaman22 on Wednesday November 15, 2017 @03:53PM (#15707644)
> No fighting with headers, include paths, linker options, make files , cmake files, scons files, etc

Instead you get to fight with often poorly-versioned bower/npm dependency hell, and gulp/grunt/webpack config errors with inscrutable messages.

> having to fight the dev tools on each platform which seem to change every 5 years such that all old samples fail.

Such stability! If anything in javascript still works five months later, I count my lucky stars.

Re:The Cost of JavaScript by jeeberz on Wednesday November 15, 2017 @04:04PM (#15707768)
I hear you but since I've been using yarn to lock all package versions I haven't had any issues.

https://yarnpkg.com/lang/en/docs/yarn-lock/

JS development without yarn is complete madness.

Re:The Cost of JavaScript by merb on Wednesday November 15, 2017 @05:26PM (#15708481)
which means that you do not use a npm proxy.
Re:The Cost of JavaScript by aprdm on Wednesday November 15, 2017 @08:58PM (#15709747)
You can just build a RPM package with your dependencies and another with the dist result.

We have something like that,

node_modules for some project goes to a rpm called $project_name-devel

and the result goes to $project_name

Is not really that complicated and then we don't rely on anything outside of our control (e.g: github, npm)

We never had an issue with this workflow. Our dependencies (the devel package) changes maybe once every two months if so?

Re:The Cost of JavaScript by blunte on Wednesday November 15, 2017 @05:34PM (#15708558)
If you went from asm/c/c++ to js, and you didn't use a half dozen other languages including Python, Ruby, and even Java back in the day, then it's no wonder you're happy with JavaScript.

That's like saying that chalk tastes so much better and is so much easier to digest than gravel. However, it's good to be happy with a language... so if it works for you, great!

Re:The Cost of JavaScript by Yetanfou on Wednesday November 15, 2017 @04:53PM (#15708208)

   I get formatting, styles, animation, for free. I get cross platform graphics, video, and audio for free
That is only true if by "for free" you mean you (or your users) get to exchange an oversized portion of their free memory and CPU cycles for those things. Better hope those users have at least as powerful a system as you do or they'll be looking elsewhere for their text editor, cooperative workbench or IDE.
Re:The Cost of JavaScript by wruza on Wednesday November 15, 2017 @04:29PM (#15708002)
>No fighting with headers, include paths, linker options, make files , cmake files, scons files, etc

These downsides only appear when you’re working on project that did it wrong way. Thousand-line autogenerated makefiles, pkg-config-unaware craplibs with headers based on different basedirs (Qt, I’m looking at you), idiots who think that using cmake/qmake/etc will magically ensure buildability on different platforms and never ever test that it does build there.

In pure js you don’t have include/dependecy problem simply because there is no require/include option at all. Then you install node/npm with 100Mb of js backing it aaand it is yet another complex toolkit to learn forever. With no man pages and shady internet snippets. My hate of js comes from different direction though — I know it and it is ugly simpleton that dooms you to boilerplate, polyfill and spaghettize everything. Debuggers help until you get a “framework” that turns everything upside down and whirls.

I’m sharing your every 5 years annoyance though, even non-web does too much change for the sake of change. No good ui also, you’re right. This comment was meant to be a counter-argument, but it appears that both worlds are crap.

Re:The Cost of JavaScript by olalonde on Wednesday November 15, 2017 @02:32PM (#15707015)
> Maybe it's because I've never been a webdev but I just don't understand the fascination with JavaScript.

1) It's the only true "write once, run everywhere" language out there (along with languages that transpile to JS).

2) npm

3) Asynchronous I/O

Re:The Cost of JavaScript by dullgiulio on Wednesday November 15, 2017 @03:38PM (#15707516)
Javascript "fame" came before npm/Node.js and before it had any idea async/await would ever be implemented.

Simply put, Javascript is the only language in the browser.

Re:The Cost of JavaScript by crandycodes on Wednesday November 15, 2017 @03:58PM (#15707695)
Asynchronous I/O refers to the fact that all I/O interactions default to being asynchronous in JS, not the fancy new `await` keyword, which is nice, but just sugar around Promises. The result of this default is that makes a best practice into a feature, not something I have to manage as a developer.
Re:The Cost of JavaScript by goatlover on Wednesday November 15, 2017 @09:26PM (#15709853)
Because of Node or the browser's event loop? It's not like JS was the first language to have a built-in event loop. Visual Basic did exist.
Re:The Cost of JavaScript by austincheney on Wednesday November 15, 2017 @03:47PM (#15707600)
Yes, but not much before. It took heavy evangelism and Google Chrome's JIT to make JavaScript popular about 10 years ago.
Re:The Cost of JavaScript by dullgiulio on Thursday November 16, 2017 @04:34AM (#15711345)
Maybe you don't remember the early 2000s when people were adding flying butterflies around the cursor with Javascript?

Recently there has been hype and explosion but web development (development on the browser, which means Javascript for lack of alternatives) had a long way coming.

Re:The Cost of JavaScript by wruza on Wednesday November 15, 2017 @04:46PM (#15708147)
The only true “write once run everywhere” is ANSI C, please don’t overestimate js in that regard. Unless you’re using polyfills and babels, it is feature-detection hell never ever imagined on desktop or embedded.

Asynchronous, parallel or progressive io existed since forever, and barely is an exclusive property of js. Moreover, it is not required from application programmer, unless the platform is built in a way that it is impossible to avoid.

Re:The Cost of JavaScript by com2kid on Wednesday November 15, 2017 @05:35PM (#15708568)
> The only true “write once run everywhere” is ANSI C,

Sure, until your pointer size varies from platform, or LONG is 64bits on one platform and 32bits on another.

Don't forget compiler support, which version of C are you using? Does the compiler support it everywhere?

C runs everywhere with sufficient #IFDEFs.

Re:The Cost of JavaScript by wruza on Wednesday November 15, 2017 @07:35PM (#15709347)
If C code incorrectly depends on specific type sizes or is written for less portable standard than ANSI C or can be compiled with non-compliant compiler only, then it will be less or non-portable.

You can argue that these restrictions allow less freedom of expression and more quirks in some cases, but the same applies to js without polyfills and babels, because these are effectively ifdefs and compilers. The one main difference is that correct C code actually can be deployed to a variety of platforms unavailable to javascript, which is runnable on just few selected powerful environments with heavy help of what is called compat-libs in non-web world. Moreover, with all these compat layers you cannot just take js code and use it in non-hosted environment; that’s why everything runs in embedded node/webkit. This is barely portable, and I think you’re confusing [seeming] ubiquity and with actual portability (like “everywhere”).

Re:The Cost of JavaScript by com2kid on Thursday November 16, 2017 @01:23PM (#15715113)
> If C code incorrectly depends on specific type sizes

Now days C includes wonderful things such as int64_t and int32_t.

Before those existed, life was hard. Everyone had to implement their own type system abstraction layer on top of C, for good reasons. Making a structure that maps to a network data packet is irritating when the underlying types of the language vary in size from platform to platform.

Thus the million different prefixed IFDEF'd type systems in headers.

The size of an enum is up to the compiler. Some optimize so that enums with less than 256 elements will have 8bit values, other compiler's don't, always setting size as 32bit. Simple solution is to set a value at the end of the enum to 0xffffffffu, but I've had teams I've worked on shy away from using enums for data modeling specifically because of how the C spec defines them.

#pragma pack not being part of the spec also causes headaches. I get why, some platforms don't support unaligned access (heck, ARM up until relatively recently). Most modern compilers implement it, and it'd be nice if the standard laid down a single, opt-in, syntax for compilers to use. Even with pack, #pragma push and pop are not implemented everywhere, so you there is still this mess of cross-plat code that is needed. (#pragma push and pop are seriously useful, also possible to get in a lot of trouble with them!)

All this can be worked around, but it very much makes C not write once run everywhere. It is write once, adapt for a bunch of platform inconsistencies, run most places until it segfaults, fix the segfault, run again, hope it works until some new platform is brought up.

I'm not saying JS runs everywhere, far from it. It is true that there is a C compiler for almost every platform, but for the deep embedded platforms, the C code is very much custom. Just a few years ago, a product I worked on had an 8bit micro on it with 256 byte memory pages. It was attached to a Cortex M4 with 256KB of SRAM. The Cortex M4 had more memory hanging off an external bus. A huge chunk of the code for all of this cross-compiled to run on Windows with lots of mocks for the hardware, including the entire Flash file system.

Each of the embedded systems relied on compiler intrinsics, accessing magic memory addresses, and the rare drop to raw assembly. Getting the code cross platform was less IFDEF's than one would imagine, mostly because code was kept in separate _win32.c/_arm.c files, and each file started with a giant #IFDEF(__win32) or #IFDEF(__ARM) (best way to do this IMHO, throw *.c into the build system, let the preprocessor figure it out).

C may be supported everywhere, but making the same C code run everywhere is a huge hassle. In comparison, cross-plat JS engines (e.g. Node) don't scale down nearly so much, but when they are brought to a platform, everything is going to be the same. The abstraction layer provided is a lot more robust, by design. Two very different goals.

Lua and Forth programmers all think this is silly, since their languages really do run everywhere. :-D

Re:The Cost of JavaScript by blunte on Wednesday November 15, 2017 @05:38PM (#15708598)
I'm confused. Are you naming npm as a plus? 5,000 individual downloads/dependencies to use a library that you could hand write in a couple of hours... not to mention embarrassing events like left-pad...
Re:The Cost of JavaScript by olalonde on Wednesday November 15, 2017 @05:51PM (#15708744)
> 5,000 individual downloads/dependencies to use a library that you could hand write in a couple of hours...

Yes, that's a trade I'm always willing to do. I'd rather use those couple of hours to write something new or spend some time with the family. "left-pad" was a minor annoyance that was quickly resolved.

Re:The Cost of JavaScript by Can_Not on Thursday November 16, 2017 @12:12PM (#15714402)
Leftpad, a one time event that was fixed very quickly with a solid permanent solution? Being able to use libraries that 5,000+ other people have already vetted for quality for you so you don't have to waste a couple of hours hand writing them? That's 2 pluses right there.
Re:The Cost of JavaScript by bpicolo on Wednesday November 15, 2017 @02:27PM (#15706944)
Electron isn't great just because it runs javascript, it's great because you get to use the HTML/CSS you're used to making pretty UIs with to make pretty desktop UIs. HTML/CSS have their warts, but they're a fantastically efficient way to build out UIs.
Re:The Cost of JavaScript by megaman22 on Wednesday November 15, 2017 @02:37PM (#15707053)
So instead of running WinForms or Qt or GTK or, god help us, Swing, components in a tight, snappy desktop app, we're mostly running Bootstrap components in a webview. Six of one, half-dozen of the other, in my book.

The Stockholm syndrome around using browser technology everywhere, just because you've been brutalized into learning its wrinkles to work on the web, is scary.

Re:The Cost of JavaScript by greggman on Wednesday November 15, 2017 @03:14PM (#15707353)
having built both native and electron my experience is it's an order of magnitude faster to use electron to ship on win/Mac/Linux than any native tech

clone this repo, follow steps at bottom of readme, ship on 3 platforms

https://github.com/greggman/electron-hello-world

Re:The Cost of JavaScript by jarjoura on Wednesday November 15, 2017 @03:34PM (#15707486)
Every single platform has their 1-line hello world example. iOS has storyboards, Windows has XAML, Linux has QT components.

If all you need is an action button to trigger some underlying code, then those hello-world products are very simple.

Electron is NOT that easy to use of a platform. In fact, it's quite technical and requires a lot of knowledge about node and HTML/CSS. It requires that the developer understand you're running a node process that feeds its results to a browser that has a native chrome.

Visual Studio Code and Slack for example have native plugins that light-up the various platform's features. So you're never completely guarded from having to write native code. At the end of the day it's just another UI toolkit and language choice you can make when building out your software.

Re:The Cost of JavaScript by bpicolo on Wednesday November 15, 2017 @04:06PM (#15707794)
> it's quite technical and requires a lot of knowledge about node and HTML/CSS

HTML/CSS are already something with massive widespread know-how and insane numbers of online resources. That's a huge deal. This takes every web developer and makes them a cross-platform desktop app developer with no additional learning.

Re:The Cost of JavaScript by jarjoura on Wednesday November 15, 2017 @05:18PM (#15708405)
To a point that is correct. For simple button actions that trigger a web request and display content, I would agree the knowledge is there and available. For any deeper skillset, photo manipulation, live camera, geospatial or map related code, webgl, etc. Solutions in those spaces are just as undocumented on any platform and require a sophisticated developer to write complex code to solve.

A developer with the caliber required to solve those problems will be comfortable in any language they are asked to write in.

Re:The Cost of JavaScript by cageface on Wednesday November 15, 2017 @05:16PM (#15708376)
Every single platform has their 1-line hello world example. iOS has storyboards, Windows has XAML, Linux has QT components.

The point is that Electron is cross platform. Building three different native apps with completely different UI toolkits is a huge amount of work and depends on much less common skillsets.

Re:The Cost of JavaScript by jarjoura on Wednesday November 15, 2017 @05:22PM (#15708445)
Sure, until you hit a wall with the sandbox. Then you will have to write native code to enable features only available on the platform that the application is run on.
Re:The Cost of JavaScript by cageface on Wednesday November 15, 2017 @06:19PM (#15708961)
Maybe but the UI is the lion's share of the code for most of these apps so you start way ahead.
Re:The Cost of JavaScript by tfmatt on Wednesday November 15, 2017 @02:45PM (#15707106)
The tooling in my opinion is much better and the barrier of entry is much lower. How many people have been deterred from writing Java because of eclipse configuration? Setting up a remote webserver, launching an app with debug parameters, install eclipsing, setting up a new project and connecting to the remote app. With client side JavaScript (my specialty) the debugger is built right into the browser, hit F12 and you are debugging. The barrier to entry for developing a UI in JavaScript is extremely low. Mocking out JSON data, and running a simple python server to test a couple ideas takes minutes. Try that with JSP, JSF, JSTL, PrimeFrames etc. See you in a week.
Re:The Cost of JavaScript by JustSomeNobody on Wednesday November 15, 2017 @02:55PM (#15707180)
> How many people have been deterred from writing Java because of eclipse configuration?

And yet, this hypothetical person wants to write an Electron app to run on desktops?

I don't get this argument. If you are good enough to understand how to write and deploy an Electron app, you should certainly be able to understand Eclipse.

Note: I'm not advocating for Java here...

Re:The Cost of JavaScript by murukesh_s on Wednesday November 15, 2017 @03:21PM (#15707389)
That was probably a bad argument, setting up eclipse shouldn't be tougher than setting up tooling for modern SPA frameworks like react or vue..

But Electron is a there for a different reason. I can convert my SPA to a working desktop app with minimal coding (same Css/js front end/ja backend, if you use nodeJs). And even it works for all major platforms. So I literally have one codebase for web and all three desktop platforms.. beat that!

I know it's not optimal to have everyone open a chromium instance under the hood but how bad is it from JVM?

Re:The Cost of JavaScript by pjmlp on Thursday November 16, 2017 @03:01AM (#15710902)
Much worse, it consumes more RAM, executes slower and lacks the platform integration even what Swing is capable of, reducing the UI/UX to the minimum denominator of HTML5 / CSS3 capabilities.

And with Java, I have the option to have an actual binary, 100% native code, if I feel inclined to do so.

Something that many Java haters keep being unaware of.

Re:The Cost of JavaScript by TomMarius on Sunday November 19, 2017 @08:40AM (#15733827)
Yes, technologically worse. Decision to go with Electron is a business one.
Re:The Cost of JavaScript by tynorf on Wednesday November 15, 2017 @03:01PM (#15707237)
> Give me literally any other language.

I'm torn between JS and PHP for the language I have the least fun programming in.

Re:The Cost of JavaScript by noir_lord on Wednesday November 15, 2017 @04:33PM (#15708039)
System at work is written in terrible terrible php, over the last few years PHP has come a long way, many of it's programmers haven't alas
Re:The Cost of JavaScript by wruza on Wednesday November 15, 2017 @04:54PM (#15708215)
That’s exactly my experience too. I’m attributing this to “the web curse”. Anything touched by the web is cursed with... I can’t even formulate it in few words, should be complex ancient magic.
Re:The Cost of JavaScript by hamstercat on Wednesday November 15, 2017 @04:04PM (#15707764)
Next time you're forced to deal with JavaScript, try out TypeScript. It's a subjective subject, but it's pretty fun to use and it compiles down to JavaScript. There are a lot of tools around this ecosystem, but as for anything experience helps.
Re:The Cost of JavaScript by k__ on Wednesday November 15, 2017 @04:56PM (#15708232)
TypeScript, Flow, Reason, ClojureScript...
Re:The Cost of JavaScript by pbreit on Wednesday November 15, 2017 @02:54PM (#15707178)
Surely you understand the value of a JavaScript runtime in every browser?
Re:The Cost of JavaScript by pjmlp on Wednesday November 15, 2017 @05:39PM (#15708606)
To make Ads and track user behavior?
Re:The Cost of JavaScript by austincheney on Wednesday November 15, 2017 @03:46PM (#15707587)
> Maybe it's because I've never been a webdev but I just don't understand the fascination with JavaScript.

Native lexical scope. Do more with less and write/test it in a fraction of the time. Seriously, a couple of rockstar JavaScript devs could easily replace a large department of equally skilled Java developers.