[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Why is JavaScript such a popular languahe, while having such

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 61
Thread images: 5

File: 2017-08-22-141157_519x263_scrot.png (31KB, 519x263px) Image search: [Google]
2017-08-22-141157_519x263_scrot.png
31KB, 519x263px
Why is JavaScript such a popular languahe, while having such poor syntax. I mean this:
        });
});
})();

is regular js syntax.

Why?
>>
>>62031694
It's the result of trying to create a functional programming language based on Scheme while using C-like syntax.
>>
>>62031694
Those are callback functions, they aren't used anymore.

Look into promises and async/await.
>>
>>62031694
>regular js syntax
>code uses jQuery
>>
>>62031988
The syntax i pointed out has nothing to do with jQuery
>>
>>62031694
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.
>>
>>62032058
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.
>>
>>62032098
There is no need to be upset, I'm just trying to help OP.
>>
File: flowerinos.jpg (119KB, 638x960px) Image search: [Google]
flowerinos.jpg
119KB, 638x960px
>>62031694

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.
>>
>>62032111
Thanks for the help.
>>
>>62032015
>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?
>>
>>62031694
I was talking about this:
        });
});
})();

jQuery is JS anyway.
>>
>>62031694
>semicolons are not necessary
>nobody forces you to write selfexecuting functions
>nobody forces you to use jQuery and chain methods
>>
>>62031694
>poor babby is confused by nesting many statements into each other
>>
>>62032942
It's really not confusing, it's just plain ugly.
>>
>>62032904
>>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
>>
>>62033004
this is how it looks when you use modern syntax
>>
>>62031694
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
>>
>>62033061
Not to mention modern JS style lambdas.

var add = (a, b) => a + b
>>
>>62031694
use ES6, Babel and Webpack, this code style is deprecated
>>
>>62032951
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
>>
>>62033114
>>62033061
>>62031820
wtf I love javascript now
>>
>>62032725
>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.
>>
>>62031820
>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
>>
>>62033182
>and they thought they would just ride the hype wave.
and they just did
>>
>>62031694
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 /g/, but I think javascript is truly (maybe not through its own fault) the worst.
>>
>>62031694
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.
>>
>>62033539
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.
>>
>>62034531
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
>>
File: javascript holy tinity.jpg (36KB, 659x317px) Image search: [Google]
javascript holy tinity.jpg
36KB, 659x317px
>>62036157
\t doesn't work if you insert it here tho
[null, null] == ","
still gives true.
>>
>>62031694
>still uses jQuery
>won't use ES6
>complains about syntax

kys
>>
>>62036157
>>62036185
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.
>>
>>62036865
>If you don't like a thing, you don't understand it
Weak typing was always a garbage idea.
>>
>>62036911
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).
>>
>>62036947
>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?
[] + []
[] + {}
{} + []
{} + {}
>>
>>62036998
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.
>>
>>62037089
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.
>>
>>62033061
react != javascript

react is JSX
>>
>>62033061
import { Dropdown } from '../../../elements/form/dropdown'


dude...(../..)

>>62037391
there's zero jsx in this snippet

>>62031694
who cares. just use typescript faggot
>>
>>62033539
>why wouldnt you use callback functions?

Because callbacks can't be composed like Promises. Callbacks are basically deprecated now. Promises are the shit
>>
>>62036844
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
>>
>>62031694
shit font
>>
>>62037593
its not that bad, vscode has extensions to help you import those paths automatically
>>
File: 706e67.png (12KB, 708x565px) Image search: [Google]
706e67.png
12KB, 708x565px
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.
>>
>>62038194
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
>>
>>62033061
can you expand on that ui imports?
>>
>>62037647
Does modern mean bloated frameworks?
>>
>>62038361
>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.

>>62037593
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
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
>>
>>62037185
what 2 + "3" does should be random
imagine all the fun, sometimes you get 5, sometimes you get 23 etc
>>
>>62031694
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.
>>
>>62038018
>>62038460
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
>>
>>62039100
how do those aliases get resolved? you need to set them in webpack?
>>
>>62039448
with webpack:
https://webpack.js.org/configuration/resolve/
without webpack:
https://www.npmjs.com/package/module-alias
if you use typescript you might also need to tinker with "rooDir", "baseUrl" and "paths" compiler options
>>
>>62039912
I forgot that module-alias is node-exclusive. here's another one https://www.npmjs.com/package/babel-plugin-module-alias
>>
>>62038563
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.
>>
>>62038460
but why are you importing for example a dropdown element? Isn't this super specific?
>>
>>62031694
C# >
>>
NEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEERD
>>
>>62031820
Promises are only really used when doing AJAX calls
Thread posts: 61
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.