Is that some weird shorthand for array length/contents == 0 ?
Nope, that's just how type coercion works.
If you have an object and are comparing to a string or number, it converts the object to a primitive. For arrays, it does this via .toString(), which is implemented as .join(), which concatenates all elements into a string using the specified separator, which is the default comma in this instance.
So [].toString() => "", ["cat", "dog"] => "cat,dog" etc.
When you compare a string and a number, which you're now at, you coerce the string into a number.
That's horrendous. So are Java UIs. I always liked Java's interoperability with C/C++ a little better than C#'s, though. Deterministic resource management is not one of C#'s many shining bright spots.
Question: any folks out there work at places where screaming "FUCK!" at the top of your lungs and then punching walls is considered acceptable behavior?
I'm trying to figure out if that was a 90's thing, or an "awful startup I would never work for at my age" thing.
edit: I'm not passing judgement on punching walls, just on the startup I worked for where it was fairly normal.
Question: any folks out there work at places where screaming "FUCK!" at the top of your lungs and then punching walls is considered acceptable behavior?
I'm trying to figure out if that was a 90's thing, or an "awful startup I would never work for at my age" thing.
edit: I'm not passing judgement on punching walls, just on the startup I worked for where it was fairly normal.
Awful startup full of high stress and low emotional maturity.
Javascript has multiple return values AND undefined! Pick your poison! :rotate:
Ohh, and null !== undefined, but null == undefined.
This just reminded me of the face I made when I found out that in Ruby, nil was an object. And as a result, checking if something is nil doesn't work like you figured it would.
is there any valid technical reason why javascript is the scripting language of the browser and not literally any other language on earth
Well, it was shabbily designed in a rush, is inconsistent and full of nonsense, has grown exponentially in an uncontrolled manner into a massive chaotic spiderweb, and is a basic necessary evil for anybody doing work on the Web.
So really, it sounds perfect for the Web, doesn't it?
Feels like I'm maybe doing something weird here but it also felt like a decent way to make sure you can only use predefined values and not just any string. Or at least have to think about why you're suddenly casting a string to something else.
edit: it's for JSON responses, so I don't want any random string.
You're more than welcome to like js or hate java, but man I hate js.
It's like the concentrated nexus of everything people hate about non-strongly typed languages. If it weren't so ubiquitous I'd avoid it out of hand, but unfortunately I have been forced at various points in my career to do significant work with it. Trivial work is just that: trivial. Eh.
You put python in a browser and we'll talk. Python is great. But I hate javascript nearly as much as I used to hate visual basic, back when it was even slightly relevant.
+1
OrcaAlso known as EspressosaurusWrexRegistered Userregular
Dynamic typing is bad enough. To be weakly typed on top of that means fighting layers of bugs at runtime that other languages can find at compile time--or at least at runtime when you try to do something invalid (e.g. Python). I'm not sure how anybody does anything with JS without using TDD and full code coverage, whereas in a language like Java or C++, I can see how people can put off testing long enough for it to become a pain to deal with. And then there's Haskell, which sometimes works out such that if you can get it to compile, it'll just work...
0
admanbunionize your workplaceSeattle, WARegistered Userregular
edited April 2017
I don't really hate Java, though my reasons against it are a mirror of yours: it's a concentrated nexus of everything I hate about strongly-typed languages.
I'd much rather a language give me the tools I need to write good code and force me to figure out protections (like using === instead of == in JS) then get in my way at every turn. Especially a language forced into an environment where its development is going to be slowed by external forces. Imagine what Java would be if it didn't just have to deal with the Oracle dev team, but also all the browser dev teams.
I honestly just don't get the fear people have of weak/dynamic typing. It causes the occasional dumb bug, sure, but for me it's never been more severe then any other dumb bug.
I don't really hate Java, though my reasons against it are a mirror of yours: it's a concentrated nexus of everything I hate about strongly-typed languages.
I'd much rather a language give me the tools I need to write good code and force me to figure out protections (like using === instead of == in JS) then get in my way at every turn. Especially a language forced into an environment where its development is going to be slowed by external forces. Imagine what Java would be if it didn't just have to deal with the Oracle dev team, but also all the browser dev teams.
I honestly just don't get the fear people have of weak/dynamic typing. It causes the occasional dumb bug, sure, but for me it's never been more severe then any other dumb bug.
Man...my thought is "If I want you to perform data conversion on my variable, I'll ask you to do it, thank you very much." If a compiler or interpreter can prevent 20 or 30% of my bugs at the cost of me occasionally having to type "ToString()", I will 100% take that. Not to mention interfaces. Was working with a js guy who told me his front end was displaying garbage because the server was passing him back a garbage string...I forget the exact look of it, but something like "["hi"],["bye"]" and I said, "That's because it's an array of strings". Sidenote: Not sure how you work with js without that being obvious to you, but it horrifies me that that mistake is even possible. Maybe that's more of a JSON issue than JS, though. It's been a while.
3DS: 4098-4243-6127
+3
admanbunionize your workplaceSeattle, WARegistered Userregular
I don't really hate Java, though my reasons against it are a mirror of yours: it's a concentrated nexus of everything I hate about strongly-typed languages.
I'd much rather a language give me the tools I need to write good code and force me to figure out protections (like using === instead of == in JS) then get in my way at every turn. Especially a language forced into an environment where its development is going to be slowed by external forces. Imagine what Java would be if it didn't just have to deal with the Oracle dev team, but also all the browser dev teams.
I honestly just don't get the fear people have of weak/dynamic typing. It causes the occasional dumb bug, sure, but for me it's never been more severe then any other dumb bug.
Man...my thought is "If I want you to perform data conversion on my variable, I'll ask you to do it, thank you very much." If a compiler or interpreter can prevent 20 or 30% of my bugs at the cost of me occasionally having to type "ToString()", I will 100% take that. Not to mention interfaces. Was working with a js guy who told me his front end was displaying garbage because the server was passing him back a garbage string...I forget the exact look of it, but something like "["hi"],["bye"]" and I said, "That's because it's an array of strings". Sidenote: Not sure how you work with js without that being obvious to you, but it horrifies me that that mistake is even possible. Maybe that's more of a JSON issue than JS, though. It's been a while.
I mean that just sounds like your JS guy... sucked. APIs are gonna API and if they're not giving you back the data you expect you're gonna have problems no matter what language you're developing in.
OrcaAlso known as EspressosaurusWrexRegistered Userregular
I dislike weak typing because I encode information about the correctness of my program in the types I use. In some cases, I'm using the type system to perform computation.
With strong, static typing I can find out that I'm misusing something by compiling it. With weak, dynamic typing, I find out I'm misusing something when something percolates to the output that looks funny. Or maybe it just randomly fails for some corner case. With strong dynamic typing, misuse is at least highlighted at runtime with an appropriate exception because I'm trying to pass an array into something that expects an integer, or a Foo into something that expects a Baz.
I dislike weak typing because I encode information about the correctness of my program in the types I use. In some cases, I'm using the type system to perform computation.
With strong, static typing I can find out that I'm misusing something by compiling it. With weak, dynamic typing, I find out I'm misusing something when something percolates to the output that looks funny. Or maybe it just randomly fails for some corner case. With strong dynamic typing, misuse is at least highlighted at runtime with an appropriate exception because I'm trying to pass an array into something that expects an integer, or a Foo into something that expects a Baz.
furthermore, to me, the idea that TDD fixes all of this thus undermines any perceivable advantages of the flexibility and "ease" of javascript
If you say Yocto enough times you forget what you're talking about
yocto. yocto yocto embedded gumstix yocto yocto
Open embedded BB recipes patch yocto yocto yocto
New projects here are ditching our old (decade+) home-rolled build system (python scripts that generate Makefiles, because who wants their builds to go fast?) and Linux stack and going Yocto/OE. It is so much better, holy shit.
Posts
Nope, that's just how type coercion works.
If you have an object and are comparing to a string or number, it converts the object to a primitive. For arrays, it does this via .toString(), which is implemented as .join(), which concatenates all elements into a string using the specified separator, which is the default comma in this instance.
So [].toString() => "", ["cat", "dog"] => "cat,dog" etc.
When you compare a string and a number, which you're now at, you coerce the string into a number.
"" => 0
0 == 0
TRUE!
Edit: well I got told
How I navigated that table "Loose equality using ==":
Object on the left to Number on top, ToPrimitive(Object) == Number.
ToPrimitive(Object) is a String, use the table again.
String on the left to Number on top, ToNumber(String) === Number.
So ToNumber(ToPrimitive([])) === 0, which is true.
False is actually on the other side of 0.
[] == "" == 0 == false
[] == false would use the table result of ToPrimitive(A) == ToNumber(B).
ToPrimitive([]) == ToNumber(false)
"" == 0
And we know the rest from there.
Holy shit and we thought C++ was arcane
Gives me a lot more confidence going into the next few.
Praise Honky!
http://steamcommunity.com/id/pablocampy
I'm trying to figure out if that was a 90's thing, or an "awful startup I would never work for at my age" thing.
edit: I'm not passing judgement on punching walls, just on the startup I worked for where it was fairly normal.
Awful startup full of high stress and low emotional maturity.
yocto. yocto yocto embedded gumstix yocto yocto
It's free and if your running / managing servers it's probably worth looking at.
This chapter, https://landing.google.com/sre/book/chapters/embracing-risk.html, is essential reading if you want some help explaining to business or clients why their ask of 99.999% uptime, while cool on paper, is completely impractical.
Open embedded BB recipes patch yocto yocto yocto
This just reminded me of the face I made when I found out that in Ruby, nil was an object. And as a result, checking if something is nil doesn't work like you figured it would.
is this a joke
It's an artifact of history, sort of like why C and C++ are used so widely despite being awful languages.
Well, it was shabbily designed in a rush, is inconsistent and full of nonsense, has grown exponentially in an uncontrolled manner into a massive chaotic spiderweb, and is a basic necessary evil for anybody doing work on the Web.
So really, it sounds perfect for the Web, doesn't it?
(also consider the first of the series: https://aphyr.com/posts/340-reversing-the-technical-interview )
edit: it's for JSON responses, so I don't want any random string.
type errorType string const ( errorNotFound = errorType("notfound") errorMalformedBody = errorType("malformed") ) func newError(status errorType, err error) []byte {}Knowing what you work with I would have expected the 2nd one(hexing) to be the one you find most fun.
Aphyr is a great guy using a great language ;o)
Edit: https://aphyr.com/posts/341-hexing-the-technical-interview
Hahahaha, wow. Writing JVM code byte by byte?
Where's the magnetic needle, or the butterfly.
I would much rather always use java than ever use javascript.
Or, more specifically, JVM bytecode.
There are a lot more languages than just Java that use the JVM. And Java itself isn't awful to use these days.
You're more than welcome to like js or hate java, but man I hate js.
It's like the concentrated nexus of everything people hate about non-strongly typed languages. If it weren't so ubiquitous I'd avoid it out of hand, but unfortunately I have been forced at various points in my career to do significant work with it. Trivial work is just that: trivial. Eh.
You put python in a browser and we'll talk. Python is great. But I hate javascript nearly as much as I used to hate visual basic, back when it was even slightly relevant.
I'd much rather a language give me the tools I need to write good code and force me to figure out protections (like using === instead of == in JS) then get in my way at every turn. Especially a language forced into an environment where its development is going to be slowed by external forces. Imagine what Java would be if it didn't just have to deal with the Oracle dev team, but also all the browser dev teams.
I honestly just don't get the fear people have of weak/dynamic typing. It causes the occasional dumb bug, sure, but for me it's never been more severe then any other dumb bug.
Full .NET technology stack with an emphasis on code coverage with unit testing, continuous integration, etc.
Just sent me through an offer that was higher than I was expecting.
Gonna accept.
PRAISE HONKY!
http://steamcommunity.com/id/pablocampy
C# should replace everything tbh.
I won't disagree with this.
Man...my thought is "If I want you to perform data conversion on my variable, I'll ask you to do it, thank you very much." If a compiler or interpreter can prevent 20 or 30% of my bugs at the cost of me occasionally having to type "ToString()", I will 100% take that. Not to mention interfaces. Was working with a js guy who told me his front end was displaying garbage because the server was passing him back a garbage string...I forget the exact look of it, but something like "["hi"],["bye"]" and I said, "That's because it's an array of strings". Sidenote: Not sure how you work with js without that being obvious to you, but it horrifies me that that mistake is even possible. Maybe that's more of a JSON issue than JS, though. It's been a while.
I mean that just sounds like your JS guy... sucked. APIs are gonna API and if they're not giving you back the data you expect you're gonna have problems no matter what language you're developing in.
With strong, static typing I can find out that I'm misusing something by compiling it. With weak, dynamic typing, I find out I'm misusing something when something percolates to the output that looks funny. Or maybe it just randomly fails for some corner case. With strong dynamic typing, misuse is at least highlighted at runtime with an appropriate exception because I'm trying to pass an array into something that expects an integer, or a Foo into something that expects a Baz.
furthermore, to me, the idea that TDD fixes all of this thus undermines any perceivable advantages of the flexibility and "ease" of javascript
New projects here are ditching our old (decade+) home-rolled build system (python scripts that generate Makefiles, because who wants their builds to go fast?) and Linux stack and going Yocto/OE. It is so much better, holy shit.