[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
this fucking meme language
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 29
Thread images: 5
File: JavaScriptLogo[1].png (86 KB, 730x599) Image search: [Google]
JavaScriptLogo[1].png
86 KB, 730x599
[] + {} // "[object Object]"
{} + [] // 0
({}+[]) // "[object Object]"
>>
>>51393136
>op can't into type coesion

[1, 2, 3].toString() // "1,2,3"
[].toString() // ""
Unary + // to number
+[] // 0
var obj = {};
obj.toString() // "[object Object]"
{} // empty code block
[] + {} // -> [].toString() + {}.toString() -> "" + "[object Object]"
{} + [] // empty code block +[] -> 0
({} + []) // -> {}.toString() + [].toString() -> "[object Object]" + ""
>>
>>51393332
Type coercion is fucking cancer.
>>
>>51393332
he can, he just knows why it's shit.
>>
File: types.png (41 KB, 256x702) Image search: [Google]
types.png
41 KB, 256x702
>>
File: 1430547881158.gif (996 KB, 150x148) Image search: [Google]
1430547881158.gif
996 KB, 150x148
>>51393136
> Some bullshit that would never happen in the wild

If you could please give me a real world example of how those things would affect my development, I'll stop calling you a faggot.
>>
>>51393365
Apparently not, if he's confused about simply conversions

>>51393346
Only for those too stupid to understand
>>
>>51393136
ITT: little bitches who cry because they cannot into a programming language's specifics

Do you bitch and cry about method hiding/overriding/etc in java too, or any of the other irritating ass shit you get there?

>>51393383
And like this guy says, even though the language makes those things possible, no developer worth even a penny would write shit ass code like that.
>>
>>51393332
what's the value of the empty block?
like what could i put for x in x + [] to achieve the same output as
{} + []
?
>>
>>51393387
>Apparently not, if he's confused about simply conversions
He's not confused. Just pointing how what unreadable pig slop JS is. Even diehard JS advocates like Douglas Crawford accept this.
>>
>>51393425
Maybe it's unreadable pig slop when shitheads like you try to write it and achieve nothing but fumbling around and creating retarded ass code like in OP
>>
>>51393387
>Only for those too stupid to understand
In what way do the advantages of type coercion outweigh the negatives?
>>
>>51393471
I write great JS. It was my main job for the past year. It's far from the worst language with broad adoption. It is however deeply flawed. Weak typing is one of many issues.
>>
>>51393410
It's just like a block of code:
if (conditions)
{
Do_blah();
}


In js (and other languages like java and c++) you can have a block without a control statement:
{
Do_blah();
}


And it's true that in all these languages you can have an empty block:
if (conditions)
{
}



Put the two together:
{}


So it's essentially nothing. You could just erase the {} entirely and it would evaluate the same.
>>
>>51393501
In what way do the negatives even affect you if you don't actually try to write the shit code it allows you to write?

>>51393504
google typescript

JS is intended for quick and dirty scripting of shallow stuff, not to write backends and other advanced shit in. If everything you do in typical JS (ie with a dom and such) become typesafe, all the code would become a whole lot more unnevessarily verbose and long, which is not what you want from it
>>
>>51393501
console.log(anArray)
console.log(anObject)
>>
>>51393552
I already know TypeScript. It's neat stuff.
>>
File: image[1].jpg (204 KB, 960x540) Image search: [Google]
image[1].jpg
204 KB, 960x540
>>51393549
i know what blocks are m8. but typing out my cunning answer i realized something:
{} + [] ≡ +[] 

That means in this context {} literally has now value. It's just syntax that gets erased, so to speak. i always thought the empty block would be evaluates but i couldn't figure out which value it would have got. e.g.
(let x = ??? in x + []) == 0 
. I didn't know what to fill x with. but now it's clear... and js is horrible.
>>
>>51393552
>In what way do the negatives even affect you if you don't actually try to write the shit code it allows you to write?

https://zyan.scripts.mit.edu/blog/backdooring-js/

Also, type coercion allows for more flexibility when bypassing many XSS filters, not to mention the numerous bugs that can arise from it during development and the unnecessary confusion it causes for a lot of noobies.

It's ok though, you can keep being lazy and blindly writing your code without paying attention to data types. That would be way too hard.
>>
>>51393552
TypeScript doesn't do anything about JS being weakly typed.

>JS is intended for quick and dirty scripting of shallow stuff, not to write backends and other advanced shit in.
Doesn't matter. It's shit for everything. It's just extra shit that it's the only language to write large web apps in.
>>
>>51393683
You got me backwards, smartass.
>not to mention the numerous bugs that can arise from it during development
That was my point: if you write dumb shit like
>var someNumber = someTextbox.value;
without ever doing a parseInt or whatever then you should be shot for not realizing you're fetching text and pretending it's a number. Only people who write retarded code run into problems like type coercion where they don't expect it. I pay as much attention to data types as you do *despite* js not making me do it. That was my fucking point.

>>51393785
Yes it does anon. You can specify that variables and params must be a certain type, etc.

>>51393785
>it's shit for everything
Well that's just your stupid opinion then cause I find it pretty fucking comfy. I wouldn't wanna have to start writing tons of fucking boilerplate like classes and getters/setters just to update the content of a fucking textbox.
>>
>>51394725
>You can specify that variables and params must be a certain type, etc.
Yes. And is is still just as weakly typed as JS. Look up what weak typing is before you start arguing to people about it.

>>51394725
>Well that's just your stupid opinion then cause I find it pretty fucking comfy.
That's because you don't know anything better.
>I wouldn't wanna have to start writing tons of fucking boilerplate like classes and getters/setters just to update the content of a fucking textbox.
Why would you need to write either of those to update a textbox? Is Java the only other language you know?
>>
>>51394764
>C, Java, C#, php = nothing
good to know anon, I;ll make sure to let my boss know next time he assigns me to a development project
>>
>>51394783
>C, Java, C#, php = nothing
What made you quote that? I said nothing like that. Didn't answer my first question either.

But yeah, PHP is terrible. C, Java and PHP are all statically typed imperative languages based on C style syntax. JS is also imperative with C style syntax. So yeah, you really don't have a very broad knowledge of good languages there.

A good dynamically typed language compared to JS would be python. A better language for almost anything would be F#.
>>
>>51394886
>C, Java and C# are all statically typed
rather
>>
>>51394725
>you should be shot for not realizing you're fetching text and pretending it's a number.

I want to agree, but people make mistakes and type coercion simply gives them too much room to make those mistakes, I really doubt you've always deployed perfect, typesafe javascript. I know I haven't. Code attempting to use a string as an int shouldn't even run without the necessary conversions being performed first. This would prevent all mistakes resulting from improper type usage, be it from noobs or pros that just forgot to add a typecheck.

Don't get me wrong man, I like javascript (it's inheritance model is sex) but type coercion is a retarded fucking feature and it causes more problems than it solves.
>>
tf PHP has to do with this thread?
>>
fucking new generation web development. I miss those times when I made tons of easy money with Flash/ActionScript. Most of you weebfaggots probably weren't even born.
>>
File: cat_saying_hello.jpg (13 KB, 217x287) Image search: [Google]
cat_saying_hello.jpg
13 KB, 217x287
>>51393136
Hmm this whining style seems familiar my pythonista.
Thread replies: 29
Thread images: 5

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.