|
|
# ? Jun 1, 2024 01:50 |
|
nanananananacode:
|
# ? Jan 10, 2014 06:28 |
|
The reason, by the way, is that the Array constructor when given one numerical argument that's a valid array length does something more or less equivalent to this:JavaScript code:
1. Create a new array P with length O.length, as if it were constructed by Array(O.length). 2. Iterate i from 0 to O.length 3. For each i, check that the property i exists on O[i] using the internal [[HasProperty]] method. 4. If it does exist, assign f(O[i]) to the P[i] Since the Array(n) constructor above doesn't actually set the properties 0..n on the created object, map never invokes f and never assigns anything to the numerical properties of its returned object (obviously P.length is set by the Array constructor). The array literal syntax like [undefined, undefined, undefined actually does set the properties 0, 1 and 2 to undefined so map behaves differently on that object. Apparently this is by design so sparse arrays retain their sparseness when mapped over. JavaScript code:
Deus Rex fucked around with this message at 08:23 on Jan 10, 2014 |
# ? Jan 10, 2014 08:20 |
|
shrughes posted:They were probably emulating Perl behavior or other old programming language behavior. No, Javascript only has two value types: string and number. Generic operators/functions deal with value types, not duck-typed classes, and any objects passed to them are coerced to either string or number with, respectively, .toString() or .valueOf(). It's that simple. That's why NaN pops up so often in Javascript: valueOf called on something that isn't a number E: there's a wordfilter for "javascript<colon>" . "Security" hackbunny fucked around with this message at 12:15 on Jan 10, 2014 |
# ? Jan 10, 2014 11:57 |
|
hackbunny posted:No, Javascript only has two value types: string and number. Generic operators/functions deal with value types, not duck-typed classes, and any objects passed to them are coerced to either string or number with, respectively, .toString() or .valueOf(). It's that simple. That's why NaN pops up so often in Javascript: valueOf called on something that isn't a number You're not saying anything I didn't already know when articulating that belief and you also haven't said anything that counters the claim that they were emulating the behavior of Perl's sort function.
|
# ? Jan 10, 2014 12:36 |
|
Steve French posted:Except that sorting an array of integers lexicographically is not sane. Maybe giving not-meaningful results when sorting a heterogeneous array when an explicit comparator is not given, as python does, is not sane either. In Python3 instead of a not-meaningful result you get a TypeError.
|
# ? Jan 10, 2014 12:37 |
|
shrughes posted:You're not saying anything I didn't already know when articulating that belief and you also haven't said anything that counters the claim that they were emulating the behavior of Perl's sort function. It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too? On the other hand, everything save for corner cases like undefined and null (?) implements toString. It's the only sane default
|
# ? Jan 10, 2014 12:54 |
|
hackbunny posted:It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too? On the other hand, everything save for corner cases like undefined and null (?) implements toString. It's the only sane default Except with the other example, it doesn't just .toString(). With mixed numbers and strings it just fucks up completely.
|
# ? Jan 10, 2014 13:07 |
|
Jewel posted:Except with the other example, it doesn't just .toString(). With mixed numbers and strings it just fucks up completely. code:
|
# ? Jan 10, 2014 14:36 |
|
One place where I do like Python 3 better.code:
|
# ? Jan 10, 2014 15:21 |
|
hackbunny posted:It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too?
|
# ? Jan 10, 2014 17:30 |
|
That's a lot of concern for something that shouldn't really matter, because why are you sorting arrays with items of different types in the first place? It just seems like throwing out the baby with the bath water to me. And really, you can't think of a better way than always iterating the array to see if the items are all numbers? Well, lets temporarily assume that that is the best way; not the end of the world really since that's an O(n) operation and the sort itself is going to be O(n log n). But that's still sorta lovely, right, since we don't want to be paying that cost all the time when we're just sorting strings, etc. So let's think of something better but still kinda hokey; just start sorting based on the type of the first object in the array, and if you encounter a different type, instead of throwing an error like other languages do, just start sorting over again based on the new information. Now you've got pretty normal sort performance for arrays of numbers and arrays of strings (the ought-to-be-common-case that you ought to care about), and worst case a constant factor penalty of about 2 for heterogeneous arrays. Or of course the array object could just keep track of what sorts of items are in it as those items are added and removed. Finally, saying one aspect of the language design is the only sane option given other aspects of the language design is not really a valid defense to criticisms of the language design. I admit that it seems somewhat problematic that sub-arrays might sort differently than the whole array, but I also think it is problematic that arrays of numbers sort lexicographically. This is a lovely tradeoff imposed by the "feature" that sorting heterogenous arrays works the way it does, which does not seem like a valuable feature to me.
|
# ? Jan 10, 2014 18:51 |
|
Steve French posted:instead of throwing an error like other languages do, I'm a big fan of the computer making GBS threads itself and calling for a human, but for some reason the web types think you should just keep chuggin'??
|
# ? Jan 10, 2014 18:56 |
|
Or you could do this:NFX posted:Numbers sort lower than strings, "10" sorts lower than "2" (it's not a natural sort). Seems sane? JavaScript code:
|
# ? Jan 10, 2014 19:01 |
|
code:
|
# ? Jan 10, 2014 19:44 |
|
Steve French posted:Finally, saying one aspect of the language design is the only sane option given other aspects of the language design is not really a valid defense to criticisms of the language design.
|
# ? Jan 10, 2014 19:47 |
|
I was going to say "just use < and >" but then I did this:JavaScript code:
I guess it could be fun to try to reverse engineer their sort functions this way E: I just want to mention that all browsers report that 'seven' < 4 is false Munkeymon fucked around with this message at 19:57 on Jan 10, 2014 |
# ? Jan 10, 2014 19:53 |
|
hackbunny posted:Definitely not, I have personal experience with this. Turns out the Java stack is untyped, and the same location can hold an object or an integer or a boolean, and optimizing compilers will reuse stack locations, and decompilers don't have the faintest idea how to handle that and will produce horrible broken code that doesn't even compile Which just goes back to something we've covered before, which is that decompilers are usually written by incompetents, because despite being logically "untyped" in a function-global sense, the JVM operand stack is required to have a consistent depth and typing at any given place in a function, and in fact JVMs are required to verify that for every method in a class before reporting that it's been successfully loaded.
|
# ? Jan 11, 2014 03:40 |
|
Munkeymon posted:I was going to say "just use < and >" but then I did this: You should try 'seven' > 4 as well. It doesn't return true. You can't really expect a meaningful output from a sorting algorithm when you're giving it an inconsistent comparison function. That said, trying to reverse-engineer a sorting algorithm by having it use an inconsistent comparison function and then just feeding it different inputs does seem like an interesting challenge.
|
# ? Jan 11, 2014 04:48 |
|
Crossposting this from Rocksmith 2014 thread:quote:1/9/2014 - Steam (PC/Mac) Patch Notes
|
# ? Jan 11, 2014 07:35 |
|
Stubb Dogg posted:Crossposting this from Rocksmith 2014 thread: Ha, I got that game (and a bass) for my dad who's always wanted to play bass guitar. But I set it up for him. Lucky I was born in September of that year.
|
# ? Jan 11, 2014 08:27 |
|
Stubb Dogg posted:Crossposting this from Rocksmith 2014 thread: Really, they're just jumping the gun by thirty or so years, because at some point you will be able to represent at least all living humans' birth dates with a unix time
|
# ? Jan 11, 2014 11:27 |
|
Thirty years? Did you know people can and often do live past the age of 74?
|
# ? Jan 11, 2014 12:51 |
|
Deus Rex posted:Thirty years? Did you know people can and often do live past the age of 74? I'm sorry my random, round number of years "or so" wasn't up to your high standards of accuracy.
|
# ? Jan 11, 2014 13:09 |
|
Stubb Dogg posted:Crossposting this from Rocksmith 2014 thread: My account name on my computer is Firstname Lastname. When I installed Uplay it created a file in C:\Users\ just called "Firstname". Here's the entire file contents: C:\Users\Firstname posted:C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\Uplay.exe Lastname\UninstalString2.txt How does that even happen? Shell piping gone wrong? From an installer!
|
# ? Jan 11, 2014 13:16 |
|
How dare you use spaces in your strings!
|
# ? Jan 11, 2014 13:19 |
|
Stubb Dogg posted:Crossposting this from Rocksmith 2014 thread: This is the saddest coding horror I've ever read.
|
# ? Jan 11, 2014 15:23 |
|
piratepilates posted:This is the saddest coding horror I've ever read. It is funny though, and you can understand why that particular issue might have never come up in QA. I doubt any of their playtesters were over the age of 40
|
# ? Jan 11, 2014 15:38 |
|
Dessert Rose posted:Really, they're just jumping the gun by thirty or so years, because at some point you will be able to represent at least all living humans' birth dates with a unix time It's supposed to be a signed integer, so unless there's someone alive that was born before 1901 or so, you can with 32 bits.
|
# ? Jan 11, 2014 16:43 |
|
zergstain posted:It's supposed to be a signed integer, so unless there's someone alive that was born before 1901 or so, you can with 32 bits. There's quite a few still living, but they're unlikely to be playing RockSmith really. Fun fact: there's still about three living subjects of Queen Victoria.
|
# ? Jan 11, 2014 18:15 |
|
I just picked up coding in Javascript and PHP today coming from the land of ASM and C. Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs? WHY have I not done coding in these languages before? This is amazing!
|
# ? Jan 14, 2014 07:16 |
|
ratbert90 posted:I just picked up coding in Javascript and PHP today coming from the land of ASM and C. You should try Python next
|
# ? Jan 14, 2014 08:13 |
|
ratbert90 posted:I just picked up coding in Javascript and PHP today coming from the land of ASM and C. Yeah try like Python or Ruby or something. Javascript isn't great (it's got a lot of weird corners), but PHP is absolute garbage and you do not want to start loving it because it makes stuff easy, because it makes doing stuff correctly a lot harder. e: Python would be pretty good for you to look into in all honesty, it's more C-like than Ruby is (in terms of control flow and general program structure; it's a lot less DSL-y), and it's got a poo poo load of libraries. And also its community is not a bunch of programming hipsters.
|
# ? Jan 14, 2014 10:02 |
|
ratbert90 posted:I just picked up coding in Javascript and PHP today coming from the land of ASM and C. String concatenation is a feature of a lot of languages, including C++ (well...) and Java. You haven't come across it because you've been writing very low level code in C and ASM, and have effectively been living in the 70s. Like, almost any modern language has string concatenation and garbage collection. "Just use a var" is weak typing, and has it's own problems if you're not careful.
|
# ? Jan 14, 2014 13:11 |
|
|
# ? Jan 14, 2014 15:38 |
Ha ha, enjoy your sharepoint sucker.
|
|
# ? Jan 14, 2014 15:46 |
|
ratbert90 posted:I just picked up coding in Javascript and PHP today coming from the land of ASM and C. You are the horror. Try out the sex that is Python or Perl (or even Java/C# for that matter if you've been living in ASM and C) and get the gently caress away from Javascript. Its like the worst language there is after esoteric poo poo like brainfuck or malbolge. Zaphod42 fucked around with this message at 17:01 on Jan 14, 2014 |
# ? Jan 14, 2014 16:58 |
|
Zaphod42 posted:You are the horror. Yeah, don't learn the language that is absolutely loving key for any job that involves web development. That entire web thing is just a fad anyway. Seriously though, I go to a dev conference every year. Two years ago, there were a handful of JS talks. Last year, there were significantly more. This year, it seemed like all anyone was talking about was JS and various JS frameworks, testing JS, SOLID design for JS, etc. On an unrelated note, two years ago there were tons of JVM-focused talks (Clojure, Groovy, Scala, etc). Almost none this year. The number of .NET talks diminished somewhat, although less drastically. I'm not debating that JavaScript is tough to do well and encourages you to shoot yourself in the foot on a regular basis, but it's definitely a key language to be familiar with.
|
# ? Jan 14, 2014 17:03 |
|
I'm more productive in JavaScript than any other language. Most of my new projects are all in JavaScript.
|
# ? Jan 14, 2014 17:07 |
|
|
# ? Jun 1, 2024 01:50 |
|
Suspicious Dish posted:I'm more productive in JavaScript than any other language. You like JavaScript because you can prototype graphical stuff instantly in the browser with no compilation. Ratbert likes JavaScript because they can indiscriminately make everything "var" and add strings together and basically just have freedom (perhaps too much, probably leading to messier code than normal). There's different motives here, and while you're in the right for liking JavaScript for your preferred hobby, I don't think Ratbert is. Python definitely seems like the better option for them.
|
# ? Jan 14, 2014 17:12 |