|
Space Whale posted:So if I have the object please don't set non-numeric properties on an array that's some zalgo poo poo where i don't even know what the gently caress happens look just read the description in this for an understanding of what an array is in javascript before continuing okay https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array and in general just please, like, read literally any book about javascript? you're clearly not an idiot but you're just not familiar with the basics of the language and trying to apply what you know in some other language to js, which is going to lead to lots of code that """works""" but is extremely bad (see: your lack of understanding of "this"). if you can't articulate the different between an object and an array you should just brush up with some very light reading abraham linksys fucked around with this message at 01:05 on Aug 18, 2016 |
# ? Aug 18, 2016 01:03 |
|
|
# ? May 25, 2024 04:07 |
|
hell eloquent javascript is $8 right now in https://www.humblebundle.com/books/joy-of-coding-book-bundle just grab that, that's a pretty beloved book
|
# ? Aug 18, 2016 01:07 |
|
yeah plus you'll be stuck with my erlang book in there just do it
|
# ? Aug 18, 2016 01:14 |
|
abraham linksys posted:please don't set non-numeric properties on an array that's some zalgo poo poo where i don't even know what the gently caress happens I didn't. edit: Right now I'm trying to make a thing work, I'll go on a refactor spree later (time permitting, not up to me!) and I ended up with an array of array of... things which had 0 through n numeric properties and also two name properties. I did NOT choose this. this is just scope, right? Hence self=this bla bla bla self.someglobalfuckyou. Space Whale fucked around with this message at 01:24 on Aug 18, 2016 |
# ? Aug 18, 2016 01:21 |
|
the super easy refactor i'd recommend for those things would be to just put the array into another keycode:
|
# ? Aug 18, 2016 01:29 |
|
hooray! i can traverse a FAT12 cluster chain in 68k assembly and read a complete file into memory
|
# ? Aug 18, 2016 01:29 |
|
abraham linksys posted:the super easy refactor i'd recommend for those things would be to just put the array into another key My architect calls them globals. I'm reasonably sure they are; there's a chance he's full of poo but this app is made very badly. I'll go read about scope I guess. That said, if I have a thing with 1 through n, and two non numeric properties, can I just delete the non numeric properties from the object? Otherwise how would I move 1->n into (LETS GO DEEPER!) another property which is itself a normal indexable array?
|
# ? Aug 18, 2016 01:33 |
abraham linksys posted:hell eloquent javascript is $8 right now in https://www.humblebundle.com/books/joy-of-coding-book-bundle just grab that, that's a pretty beloved book take my money!
|
|
# ? Aug 18, 2016 01:34 |
|
Space Whale posted:My architect calls them globals. I'm reasonably sure they are; there's a chance he's full of poo but this app is made very badly. I'll go read about scope I guess. I don't actually know if this is true, but I could imagine that in the top level scope, 'this' refers to the Window object. In that case, you could effectively treat members of 'this' as globals, but only when you're at the top level scope. has your architect never defined a method on an object? e: hey i was right. i think i must have just known this and forgot. code:
DONT THREAD ON ME fucked around with this message at 01:56 on Aug 18, 2016 |
# ? Aug 18, 2016 01:53 |
|
MALE SHOEGAZE posted:I don't actually know if this is true, but I could imagine that in the top level scope, 'this' refers to the Window object. In that case, you could effectively treat members of 'this' as globals, but only when you're at the top level scope. the one caveat is that this is only true when you're not in strict mode! but yeah in a lot of bad loose-mode js code people use this when they should be using window, which can lead to extremely fun times when someone decides to give Function.prototype.bind() a shot
|
# ? Aug 18, 2016 02:07 |
|
Javascript really is the funnest of the p-langs
|
# ? Aug 18, 2016 02:09 |
|
javascript is fun cuz you'll have spent enough time with it that you'll finally think you know everything there is to know, then you go to use Array.prototype.reverse and see it returns an array and assume it returns a new copy, only to find out 30 minutes of debugging later that, nah, it in fact mutates the array but also returns a reference to it, and then you'll want to die that's what "fun" means right
|
# ? Aug 18, 2016 02:11 |
|
wait, why would you assume that? isn't mutating and returning a reference SOP for plangs?
|
# ? Aug 18, 2016 02:14 |
|
half of the functions in the javascript standard library mutate stuff and the other half return a new copy. each individual function is part of the half you think it's not in
|
# ? Aug 18, 2016 02:18 |
|
Stringent posted:wait, why would you assume that? isn't mutating and returning a reference SOP for plangs? no? code:
|
# ? Aug 18, 2016 02:19 |
|
it's me, i'm the bad dev who writes method chaining apis. in my defense, my method chaining apis always return a value and never mutate, but that's because performance, lol
|
# ? Aug 18, 2016 02:25 |
|
as long as you're really explicit about method-chaining existing in your api it's probably fine. i mean there's stuff like lodash's _.chain that is perfectly fine, it's as explicit as possible about what's happening. (then there's stuff like lodash's _.reverse which just calls the native reverse and has the same semantics and it makes me want to die)
|
# ? Aug 18, 2016 02:27 |
|
man even everyone's least favorite language ruby has an awesome and consistent convention for methods that mutate the original valuecode:
|
# ? Aug 18, 2016 02:32 |
|
abraham linksys posted:
the little touches like that are what really sold me on that language when i had to learn it for an internship a few years ago it is so nice to write in for little stuff!
|
# ? Aug 18, 2016 02:38 |
|
it's not really adhered to, tbh. it kinda doesnt really make sense most of the time e: bangs in ruby, i mean DONT THREAD ON ME fucked around with this message at 02:43 on Aug 18, 2016 |
# ? Aug 18, 2016 02:41 |
|
So if i have numerics and non numerics in the same thingy wtf do I do
|
# ? Aug 18, 2016 02:46 |
|
abraham linksys posted:man even everyone's least favorite language ruby has an awesome and consistent convention for methods that mutate the original value destructive methods don't consistently have a bang and a bang doesn't consistently mean it's destructive
|
# ? Aug 18, 2016 02:49 |
|
Weekend Bridges posted:o yeah the whole concept of mutability in ruby is hosed and then people start to overload the bang to mean like, that it mutates global state or w/e, and next thing you know you're confused my only real 'wow i totally misunderstood how the programming language works and it made it into production' moment was this: code:
|
# ? Aug 18, 2016 02:56 |
|
Star War Sex Parrot posted:RULE 5: There shall be no use of dynamic memory allocation after task initialization. this is a great read, why havent i read it before
|
# ? Aug 18, 2016 03:03 |
|
except the section on assertions is full of some kinda gross lookin poo poo
|
# ? Aug 18, 2016 03:19 |
Mutating and returning None instead of mutating and returning a reference caught me off guard all the time when I first started using Python. To this day I'll still doPython code:
|
|
# ? Aug 18, 2016 03:38 |
|
MALE SHOEGAZE posted:yeah the whole concept of mutability in ruby is hosed and then people start to overload the bang to mean like, that it mutates global state or w/e, and next thing you know you're confused okay well fine it's a good idea in theory (i've written very little ruby) i wish there was a similar convention, or at least attempt at one, in js, something like Array.prototype.reverseMutate() or smth Space Whale posted:So if i have numerics and non numerics in the same thingy wtf do I do this is still a weird problem to me. like, if you have an object, you can use "numbers" as keys, but those "numbers" are just getting cast to strings on both the set and get ends. if you have an array, you can use numbers for indices and strings for keys to non-indexed items, but then poo poo just gets insanely weird in a wat sorta way. the only sane way to handle this in javascript is to, like, i said, use an object that contains an array as one of its values. so like... what on earth is this object you're consuming that is an array that has additional properties set on it? can you just refactor whatever code is creating it?
|
# ? Aug 18, 2016 03:39 |
|
VikingofRock posted:I think in Effective C++ Scott Meyers recommends returning a reference from mutating methods in order to allow for method chaining, and reading that book was probably my first attempt to get "good" at programming. Also the C++ STL does it a lot IIRC. So when I started programming outside of C++ I was shocked when not everyone did that. my assumption here is that you would very rarely expect methods in C++ to return a new data structure, given the usual use cases of C++, so that makes sense to me. to anyone coming from a functional programming background, the very idea of a regular ol' function mutating a data structure that it's passed in is sorta blasphemous. javascript, being javascript and drawing people from all walks of life, often attracts people on both sides of spectrum. personally i just like it when methods are extremely clear that they are mutating what they're passed, and the most obvious signal of that is that they don't return anything, and i draw that from python (another good example of this is sorted(foo) vs foo.sort()). honestly i wouldn't be that annoyed about reverse() in JS except for, as previously mentioned, the completely arbitrary randomness of what methods mutate and what don't. at least with python you have the convention of "global functions are gonna return a new thing while methods are going to mutate it"
|
# ? Aug 18, 2016 03:42 |
|
abraham linksys posted:so like... what on earth is this object you're consuming that is an array that has additional properties set on it? can you just refactor whatever code is creating it? Yes. Will $shockinglyBigISP pay me/my team to do that? https://www.youtube.com/watch?v=YpddaZB9bcI
|
# ? Aug 18, 2016 03:46 |
|
welp you could do this I guesscode:
|
# ? Aug 18, 2016 03:49 |
|
abraham linksys posted:my assumption here is that you would very rarely expect methods in C++ to return a new data structure, given the usual use cases of C++, so that makes sense to me. to anyone coming from a functional programming background, the very idea of a regular ol' function mutating a data structure that it's passed in is sorta blasphemous. my c++ reckons would be that it's perfectly fine to return a new data structure in c++ b/c you can let the compiler do the return-value optimization https://en.wikipedia.org/wiki/Return_value_optimization
|
# ? Aug 18, 2016 03:50 |
|
well i guess thats not quite the same thing but w/ever
|
# ? Aug 18, 2016 03:50 |
|
abraham linksys posted:if you have an array, you can use numbers for indices and strings for keys to non-indexed items, i didn't understand what you guys were talking about but it suddenly just clicked and that is horrifying. i'd never really realized that about Arrays.
|
# ? Aug 18, 2016 03:51 |
|
abraham linksys posted:welp you could do this I guess What scared me is how easily I was able to find questions online about this and canned idioms to handle it.
|
# ? Aug 18, 2016 03:55 |
|
MALE SHOEGAZE posted:i didn't understand what you guys were talking about but it suddenly just clicked and that is horrifying. i'd never really realized that about Arrays. it's real good times. i keep referencing the "wat-like" behavior because i've definitely seen code samples where this can gently caress poo poo up badly, like the original wat talk might actually have this in there (i should just rewatch it). i want to say you can get an array into a state where length returns the incorrect value, or something equally strange?
|
# ? Aug 18, 2016 03:58 |
|
hahaha what the gently caress is wrong with me I actually did it. so I took this extremely trivial sample from the Windows Scripting documentation:JavaScript code:
C++ code:
|
# ? Aug 18, 2016 03:59 |
|
i don't understand you
|
# ? Aug 18, 2016 04:00 |
|
abraham linksys posted:it's real good times. i keep referencing the "wat-like" behavior because i've definitely seen code samples where this can gently caress poo poo up badly, like the original wat talk might actually have this in there (i should just rewatch it). i want to say you can get an array into a state where length returns the incorrect value, or something equally strange? I thought I had an array of arrays of arrays. I really had an array of arrays of object-things with some numeric properties from 0 to n. .length was undefined on the innermost array-like-thing and that's where I found the for-in idiom. When debugging I just saw the inner for loop never triggered at all, and it was because of two name properties just thrown onto the inner array because the prior dev was an rear end in a top hat. Adding these non numeric properties basically hoisted it (on it's own petard!) into object-dom so array stuff quit working. So, "just iterate over its properties!"
|
# ? Aug 18, 2016 04:03 |
|
hackbunny are... are you okay?
|
# ? Aug 18, 2016 04:05 |
|
|
# ? May 25, 2024 04:07 |
|
jony neuemonic posted:hackbunny are... are you okay? I wonder sometimes. I actually liked doing it
|
# ? Aug 18, 2016 04:12 |