Why is JavaScript such a popular languahe, while having such poor syntax. I mean this:

Why is JavaScript such a popular languahe, while having such poor syntax. I mean this:
});
});
})();

is regular js syntax.

Why?

Other urls found in this thread:

developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
webpack.js.org/configuration/resolve/
npmjs.com/package/module-alias
npmjs.com/package/babel-plugin-module-alias
twitter.com/SFWRedditVideos

It's the result of trying to create a functional programming language based on Scheme while using C-like syntax.

Those are callback functions, they aren't used anymore.

Look into promises and async/await.

>regular js syntax
>code uses jQuery

The syntax i pointed out has nothing to do with jQuery

It's not as poor as you think it is. An honest advice: for your own well-being, do not look at any lisp code.

It's the most consistent syntax you dumb shit, the one that helps you visualize the syntax tree the most. But maybe you're just a script kiddie.

There is no need to be upset, I'm just trying to help OP.

It wanted to be lisp but c-syntax was hacked on at the last second by marketing because they were afraid )))) will scare off code monkeys and thus we instead get });});});}); which is supposed to be better somehow.

Thanks for the help.

>The syntax i pointed out has nothing to do with jQuery
>$('.arc').empty();
>$('.arc').append(
>$('.arc > span').each(

What did he mean't by this?

I was talking about this:
});
});
})();

jQuery is JS anyway.

>semicolons are not necessary
>nobody forces you to write selfexecuting functions
>nobody forces you to use jQuery and chain methods

>poor babby is confused by nesting many statements into each other

It's really not confusing, it's just plain ugly.

>>semicolons are not necessary
That's not the issue
>>nobody forces you to write selfexecuting functions
They help scoping, nobody *forces* you to do anything
>>nobody forces you to use jQuery and chain methods
If anything, jQuery looks better and it's not just JQuery that looks like this, it's JS

this is how it looks when you use modern syntax

That makes perfect sense to me. What is your issue with it?

Imagine being so stupid that even javascript is too intellectual for you
LMAO

Not to mention modern JS style lambdas.

var add = (a, b) => a + b

use ES6, Babel and Webpack, this code style is deprecated

people say the same about lisps' parenthesis too but they're still great langs

js is bad but not for meme reasons like you listed

wtf I love javascript now

>c-syntax was hacked on at the last second by marketing because they were afraid )))) will scare off code monkeys
Not exactly. Netscape specifically wanted the language to look like Java (and even gave it its retarded name after Java) because Java was hot shit back then and they thought they would just ride the hype wave.

>Those are callback functions, they aren't used anymore.

why wouldnt you use callback functions? promises require errorhandling or wraping your code in try/catch statements.

most time using a simple cb is much simpler and faster

>and they thought they would just ride the hype wave.
and they just did

It's a messy language. It was meant to be human readable like the rest of the internet, but instead people came up with bloat because 'lel just wait for hardware to be faster'. Now everyone minifies and obfuscates everything and we need other languages to transpile to javascript resulting in even more unreadble pieces of shit. I personally prefer if websites just worked without javascript, but they don't because 'muh SEO and UX needs it all in one page so I can shove more ads and bloat and call it features'. You see alot of people shit on every other language on Sup Forums, but I think javascript is truly (maybe not through its own fault) the worst.

I will never understand how developers in "modern" languages can waste so many resources.
Why would you create a new array just to hold the reversed data? Just read from the array backwards with []. Also why the fuck would you iterate through an array with callback functions? Are for loops truly so bad? Or JS' new for of?

My favorite thing "modern" developers fuck up is checking if one string begins or ends with another by copying part of the string with substring and then checking if they are equal.
What the fuck.

Also, this code won't handle surrogate pairs or grapheme clusters.

0 / 10 see me after you commit seppuku.

Because you can propagate the error down to the point where you want to handle it.
I mean, you can still do that with plain callbacks but you have to use the throw idiom every time, and it becomes hard to follow what shouid be a single flow of control. Think of a ~webapp~ with hundreds of thousands of LOC.
function caller(err, res) {
try {
someIO(params, callback);
}
catch (err) {
// handle
}
}

function callback(err, res) {
if (err) throw err;
someOtherIO(param, otherCallback);
}

function otherCallback(err, res) {
if (err) throw err;
// go on
}


function caller(err, res) {
someIO(params).then(res => {
// do something
return someOtherIO(params);
}).then(res => {
// go on
}).catch(err => {
// handle
});
}


async function caller(err, res) {
try {
const res = await someIO(params);
// do something
const secondRes = await someOtherIO(params);
// go on
}
catch (err) {
// handle
}
}

You can just delegate error handling higher in the stack too by returning the promise or letting the async function throw.
It's a nice workaround and should have been the way node was designed from the beginning, instead of the horrible unidiomatic code it spawned.

yeah sure, I agree with you if you have nesting of callbacks.

but if you just have one callback, promises seem overkill.

[null, null] == "\t,"
js is so shit you can't trust the equality operator to test for equality, you have to use the "no really" operator

\t doesn't work if you insert it here tho
[null, null] == "," still gives true.

>still uses jQuery
>won't use ES6
>complains about syntax

kys

You're a retard who doesn't understand weak typing. You're using a string type as one of the operands, and arrays have a .toString() function that gets invoked when you use a string type as an operand.

>If you don't like a thing, you don't understand it
Weak typing was always a garbage idea.

If you want to criticise weak typing, then make an argument against weak typing. Don't make an argument where you pretend to be surprised about implicit type conversion.

I'm with you, I think weak typing is a bad idea, but pretending to be ignorant about the language mechanisms is stupid. If you know why [null, null] == "," then don't make a post about how surprised you are about it.

Oh, and by the way, the === is not a "no really" operator, it's an identity operator (rather than an equality operator).

>If you know why [null, null] == "," then don't make a post about how surprised you are about it.
Is it obvious what each of these evaluates to?
[] + []
[] + {}
{} + []
{} + {}

To someone who knows the language, it is about as obvious as the difference between an copy assignment and a copy constructor in sepples.

+ is not only arithmetic add, it's also a string concatenation.

JavaScript has a precedence table, look it up if you're uncertain.

P.S. I'm not saying that this is good or even intuitive, I'm just saying that this is the way it is.

The difference between a copy constructor and copy assignment can be learned in a few minutes (though sepples' initialization rules are completely fucked, and that's a story for a different time)

Python got this right. You can have dynamic typing without having type coercion. There's no good answer to what 2 + "3" should do, so in Python an error is raised. That's sane. Javascript and PHP believe it's better to do something insane than to stop working.

react != javascript

react is JSX

import { Dropdown } from '../../../elements/form/dropdown'


dude...(../..)

there's zero jsx in this snippet

who cares. just use typescript faggot

>why wouldnt you use callback functions?

Because callbacks can't be composed like Promises. Callbacks are basically deprecated now. Promises are the shit

This. OP's code is some ugliness, and he presents it as normal, clean, acceptable code. It might have been 3 years ago, but now that's just ugly. It's not modern

shit font

its not that bad, vscode has extensions to help you import those paths automatically

Coffeescript is the PERFECT scripting language. Coffeescript should be made into its own standalone compiler instead of being a transpiler. It would not only replace ES6 but it would be better than Python and Ruby. Coffeescript has all the best features of JS, Python and Ruby all rolled into one. It has the most beautiful syntax of ANY programming language...pic related.

fuck this shit.. i need to compile it into JS to understand wtf is going on.

only atom developer hipsters seem to be using it anyways

can you expand on that ui imports?

Does modern mean bloated frameworks?

>can you expand on that ui imports?
expand how? you create millions of react components and combine them into more complex ones by importing.

The lower level ones should be dumb (basically just rendering the view and executing parent component functions). The higher level ones should do the logic.

as this dude pointed out, I might have not the best folder structure, but luckily there are refactoring and importing extensions for vscode

more about imports
developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

what 2 + "3" does should be random
imagine all the fun, sometimes you get 5, sometimes you get 23 etc

I'm a C/C++ programmer, have worked on OS and stuff, and I've also used Java for an app. Recently I needed to make a bunch of websites/web apps/blogs so I learned JS, jQuery, CSS, HTML, and even a bit of React.js

JavaScript, for what it does, is the comfiest language around. I'm not joking. Writing it is easy, reading it is easy, it does what you want it to do, and, for it's purposes, it's fast.

It was horrible because it was written in 10 days or something, but the newer versions (called EcmaScript) tidied it up nicely and made it super easy to do anything you want to do. You have an idea, you sit down and write it. To do the same thing (let's say 3 hours worth of work) in Java and some GUI framework it would take literally the whole day.

my point is that it's possible to setup your module resolver so that you can use paths relative to your base directory. /shit/piss/whatever/common/element/form/dropdown is miles better than ../../../elements/form/dropdown, even if it's a bit longer.
it's also possible to create aliases so /shit/piss/whatever/common/element/form/dropdown might become @elements/form/dropdown

how do those aliases get resolved? you need to set them in webpack?

with webpack:
webpack.js.org/configuration/resolve/
without webpack:
npmjs.com/package/module-alias
if you use typescript you might also need to tinker with "rooDir", "baseUrl" and "paths" compiler options

I forgot that module-alias is node-exclusive. here's another one npmjs.com/package/babel-plugin-module-alias

All functions should return random output. That way, in an infinite multiverse, there's going to be a universe where all functions always return the desired value.

but why are you importing for example a dropdown element? Isn't this super specific?

C# >

NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERD

Promises are only really used when doing AJAX calls