all 21 comments

[–]m68k 6 insightful - 3 fun6 insightful - 2 fun7 insightful - 3 fun -  (0 children)

I see => as "equals or greater than". Me being someone who programed in assembly, C and BASIC, JS doesn't seem to be something I'd want to learn anytime soon. :P

[–]trident765 4 insightful - 2 fun4 insightful - 1 fun5 insightful - 2 fun -  (5 children)

Modern scum seem to derive extreme pleasure from being presented with features that have a very narrow set of applications. The second way may save a few characters of typing in one of the rare cases where the function only needs to be one line, which I imagine is why modern scum love it. They like the idea that there is a designated feature for writing one-line functions.

[–]x0x7 2 insightful - 3 fun2 insightful - 2 fun3 insightful - 3 fun -  (4 children)

Javascript is used primarily as a functional language. Inline function declarations are everywhere. It actually saves a lot of space and prevents 40% of your code being the world function.

Once you have a language that lets you do both procedural and functional paradigms and you develop more than basic experience you find yourself using the functional one almost exclusively.

Like if I want to add every number in an array. a.reduce((a,b)=>a+b)

Or if I want to perform several db calls in parallel and an api call somewhere else asynchronously. function getalldata(tag,cb) { async.parallel([ //Every action is done in parallel cb=>db.get('DB STUFF',cb), cb=>db.get('MORE DB STUFF,cb), cb=>undici.request('https://site/api/get/.......').then(r=>cb(null,r)).catch(cb), ],(err,results)=>{ if(err) return cb(err); //If an error occurred with any of them report it to calling function var [meta,comments,federated]=results; //Move the elements of the results array into named variables cb(null,{meta,comments,federated}); //Return results of data gathering in a dictionary }); }

Show me that being done cleaner in python or c/c++ including the parallelism.

[–]fschmidt[S] 4 insightful - 2 fun4 insightful - 1 fun5 insightful - 2 fun -  (0 children)

I missed this and I want to respond to it. First, Javascript is not used primarily as a functional language. Javascript's functions aren't really functions, they are closures. The difference is that closures have state while functional languages are stateless. I would describe Javascript as a table/closure language like Lua and my Luan. Javascript "objects" are misnamed and are really tables (maps). Javascript's object-oriented features have always been a grotesque hack.

If I want to sum an array in Luan:

local sum = 0
for _, v in ipairs(a) do sum = sum + v end

More verbose than:

local sum = reduce( a, function(x,y) return x+y end )

But the first is clearer to me and is more efficient.

I haven't followed tech ideas in about 20 year since they are all crap, but I do hear mentions of this asych stuff which I assume is some glorified map-reduce. Anyway, there is no valid reason to handle DB requests this way, they should just be done sequentially (in a civilized multi-threaded language). There are valid use cases for map-reduce like gathering a lot of HTTP requests, but this is rare and so this should be as verbose as possible to make clear what is happening.

[–]x0x7 2 insightful - 3 fun2 insightful - 2 fun3 insightful - 3 fun -  (2 children)

Rewriting that last one without arrow functions or gather/spread.

function getalldata(tag,cb) { async.parallel([ //Every action is done in parallel function (cb) { db.get('DB STFFF',cb); }, function (cb) { db.get('MORE DB STUFF',cb); }, function (cb) { undici.request('https://someurl/akldaldk').then(function(resp) { cb(null,r)); }).catch(cb); } ],function(error,results) { if(error) return cb(error); //If an error occurred with any of them report it to calling function cb(null,{meta:results[0],comments:results[1],federated:results[2]}); }); }

What's actually bad about modern javascript isn't ES6 (the features you are showing). It's the increased popularity among large companies that employ dipshits who learned nothing from school besides object orientation and needing to reinject it and demand it with Typescript when the language already had an object/class system that over time became unused because functional programming is better. That and the adoption of bloat frameworks that make you write everything as if it were another language.

Basically they saw it was powerful, but they couldn't get their dipshit staff to actually learn javascript so they had to ruin a language that had many strengths, but now is just a pile of garbage any time their typescript or React touches it.

[–]trident765 1 insightful - 1 fun1 insightful - 0 fun2 insightful - 1 fun -  (1 child)

The functions should just be given names and then async.parallel can be called in a single line.

[–]x0x7 1 insightful - 2 fun1 insightful - 1 fun2 insightful - 2 fun -  (0 children)

When you have a server than handles 50+ types of requests and therefore you need to do that 30 or so times (not all will be structured like this), having a thousand named functions would get pretty tedious. That also doesn't account for functions benefiting and relying on their inline context. I didn't show it here but I had a named parameter in the outer function called tag. I didn't use it anywhere but if I did, a global scope named function isn't going to cut it. You will end up with an inline function even just to call the named function just to pass it tag.

[–][deleted] 3 insightful - 3 fun3 insightful - 2 fun4 insightful - 3 fun -  (1 child)

It's those python mfers, trying to make everything a goddamn one liner

[–]jamesK_3rd 3 insightful - 2 fun3 insightful - 1 fun4 insightful - 2 fun -  (0 children)

Bingo.

[–]IMissPorn 3 insightful - 2 fun3 insightful - 1 fun4 insightful - 2 fun -  (0 children)

Weird. Super compact syntax has its place I guess, but I'd have thought it more relevant for shell scripts and the like. I'm not sure why you need in JavaScript.

Edit: Actually I thought of a use-case. This might come in handy when you're embedding malicious code in sneaky places and every byte counts.

[–]zyxzevn 3 insightful - 2 fun3 insightful - 1 fun4 insightful - 2 fun -  (1 child)

Those ideas come from PhDs who think that Haskell is a good language.
And thus they make it more difficult for people who actually make commercial products.

[–][deleted] 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (0 children)

This is nothing haskell-like. First of all, haskell doesn't have comma-parameterized arguments, and secondly, haskell has separate declarations for a function type and the function definition. Sure, haskell-esque syntax is very confusing and a bit high-minded, but this is not remotely similar nor something a haskell dev would suggest at all.

Also, haskell is an awesome language, lol.

[–]package 3 insightful - 2 fun3 insightful - 1 fun4 insightful - 2 fun -  (0 children)

You legit have to be some kind of barely functioning drooling mongoloid retard to complain about modern javascript vs old javascript of all things. Concise, expressive syntax along with more reasonable scoping behavior have turned a truly horrible and irredeemable dumpster fire into a very usable and useful language.

[–]SoCo 2 insightful - 3 fun2 insightful - 2 fun3 insightful - 3 fun -  (0 children)

If this irks you, don't peek at the direction Python has been going...

[–][deleted] 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (0 children)

I don't disagree. They are one step away from ML, like let add a b = a+b but chose to just take the let keyword and forget the nice syntax.

[–]ID10T 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (2 children)

The second one liner is more readable. Don't let yourself get stuck in the past. Don't get comfortable with your current skill set. If you want to stay relevant in this industry you will need to constantly be learning. Else you become a dinosaur and eventually unemployable.

[–][deleted]  (1 child)

[removed]

    [–]ID10T 2 insightful - 2 fun2 insightful - 1 fun3 insightful - 2 fun -  (0 children)

    Lol ok cool

    [–]GeorgeCarlin 2 insightful - 1 fun2 insightful - 0 fun3 insightful - 1 fun -  (1 child)

    Did you try flutter ?

    It's script-able in dart. I only do back-end(: "databases", encryption and "automatizing") , so i myself don't give a fuck about dart itself.

    But some colleagues of mine seem to value it highly when i hear them talking about it, although it surely is just another google-scam.

    So there has to be something to it, i suppose.

    [–][deleted] 4 insightful - 2 fun4 insightful - 1 fun5 insightful - 2 fun -  (0 children)

    I have done application development in flutter, it isnt really a great option for web yet. Its a composable object-oriented framework using widgets, rather than html/css. The benefit of Flutter is one team can do the all the dev work. You don't need separate ios/android/desktop implementations, and the backend and frontend are even often done together in one codebase.

    Personally I like Flutter for apps for one reason: its cross platform and doesnt require javascript, which is an abomination, but flutter is really janky for web. Im hoping WASM will someday be a feasible replacement