Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ToxicFrog
Apr 26, 2008


HORATIO HORNBLOWER posted:

Just fixed a 'for in' bug this morning. Code looked like this:

All butts have a zit, but sometimes a zit has a pusName without a pusId (or vice versa). This happened to work fine most of the time, but on IE 8, the length property of butts was the first property to be iterated over. butts.length.zit was of course undefined, so when the pusId was also undefined, the function returned butts.length.

I don't really know JavaScript - is the implication here that "for (x in collection)" iterates not only over the elements of the collection, but also all of its methods/fields/etc?

Adbot
ADBOT LOVES YOU

Scaevolus
Apr 16, 2007

Otto Skorzeny posted:

Here's a recent one-liner bugfix:

code:
-			 xQueueSend(g_director_task, &msg, portMAX_DELAY);
+			 xQueueSend(g_director_queue, &msg, portMAX_DELAY);
Nominally, task handles and queue handles are different types, so the compiler should have caught this bug that took me hours to figure out (I guess I'm blind). The reason it didn't is that FreeRTOS re-typedefs all its internal types to pointers to void in the headers to keep people from inspecting their internals (which doesn't make a lot of sense for an RTOS to do to begin with, since people often need to have the debugger inspect the guts to reason about program behavior), preventing C's type system from warning me that I had hosed up.
Forward declarations are a better way to hide internal details while maintaining type checking.

qntm
Jun 17, 2009

ToxicFrog posted:

I don't really know JavaScript - is the implication here that "for (x in collection)" iterates not only over the elements of the collection, but also all of its methods/fields/etc?

Essentially. JavaScript doesn't really have "collections" per se, it just has objects, which have properties (or fields, whatever). A method is just a property whose value is a function.

Misleadingly, an array is just an object like any other. It has at least one property of its own (length) and you can set more properties if you want. It's just that - effectively - some of the properties are very small integers starting at 0.

"for (x in object)" is intended to iterate over the properties of an object. When you apply it to an array, you do get all of the values from the array, but you get other things as well, as mentioned. To iterate over an array's elements, you want this.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ToxicFrog posted:

I don't really know JavaScript - is the implication here that "for (x in collection)" iterates not only over the elements of the collection, but also all of its methods/fields/etc?

JavaScript objects are just a hash/dictionary, and a for loop iterates over the keys. (And their prototype's keys. And their prototype's prototype's keys. ...)

Arrays usually work ok because they intentionally withhold their other properties from iteration. IE 8 apparently returns an almost-but-not-quite-like-Array object from document.getElementsByTagName that forgot to hide its length property.

raminasi
Jan 25, 2005

a last drink with no ice
JavaScript arrays are definitely goofier than I expected:

MDN posted:

When setting a property on a JavaScript array when the property is a valid array index and that index is outside the current bounds of the array, the engine will update the array's length property accordingly:
JavaScript code:
fruits[5] = "mango";
console.log(fruits[5]); // "mango"
console.log(Object.keys(fruits));  // ["0", "1", "2", "5"]
console.log(fruits.length); // 6
Increasing the length property does not create additional elements.
JavaScript code:
fruits.length = 10;
console.log(Object.keys(fruits)); // ["0", "1", "2", "5"]
console.log(fruits.length); // 10
Decreasing the length property does, however, delete elements.
JavaScript code:
fruits.length = 2;
console.log(Object.keys(fruits)); // ["0", "1"]
console.log(fruits.length); // 2

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

GrumpyDoctor posted:

JavaScript everything is definitely goofier than I expected

There we go.

necrotic
Aug 2, 2005
I owe my brother big time for this!

HORATIO HORNBLOWER posted:

code:
function findButtWithZit(zit) {
    var butts = document.getElementsByTagName("BUTT");
    var i;

    for(i in butts) {
        if(butts[i].zit == zit.pusId || butts[i].zit == zit.pusName) {
            return butts[i];
        }
    }

    return null;
}

I think the real horror here is using for-in on an array. (Sorry, a NodeList!)

Fuck them
Jan 21, 2011

and their bullshit
:yotj:

Adahn the nameless posted:

There's a good chance I'm not understanding your ajax problem fully, but couldn't you just chain promises?

Tried that.

There's some deeply buried labyrinthine issue with events that nobody has been able to catch in the time we could spare to look.

Since our current workaround, well, works, it's on the back burner.

:shepface:

I'm trying to not think about when this is going to bite us in the rear end.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



pseudorandom name posted:

The theory is that transaction reissue was entirely automated.

AFAIK, part of the code dump was the function that automatically re-issued transactions that didn't make it but with a higher fee. I don't know if that was out when Sirer was writing that blog post.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



qntm posted:

One row in the table represents one minimal unit of currency. You can't have fewer than 0 rows, right? :v:

That's exactly the kind of weirdness I come up with :psyduck:

TastySauce
Jul 17, 2004

I AM A SKEPTOPOTAMUS!
I still work here and don't want to get fired, so I'm going to remove this code for now. It's too obviously this peron's code. Sorry.

TastySauce fucked around with this message at 23:14 on Mar 7, 2014

Steve French
Sep 8, 2003

GrumpyDoctor posted:

JavaScript arrays are definitely goofier than I expected:

Given that you can resize arrays by just assigning where you want, and without initializing all elements, that behavior all makes perfect sense to me.

HORATIO HORNBLOWER
Sep 21, 2002

no ambition,
no talent,
no chance

necrotic posted:

I think the real horror here is using for-in on an array. (Sorry, a NodeList!)

Well that's kind of the point, though. An array is iterable so you'd expect for-in to work with it just fine. But there's so many gotchas with the construct in JavaScript that it's best just to avoid it.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

GrumpyDoctor posted:

JavaScript arrays are definitely goofier than I expected:
JS arrays might be called arrays, but don't be fooled: they're not in the least bit like C arrays. They're just JS objects with a funny subscript operator and a few extra methods nailed on.

Spatial
Nov 15, 2007

JS might look like a real language, but don't be fooled. It's just some prat's unfinished hack interpreter from 1995.

pseudorandom name
May 6, 2007

Hey, he did a pretty good job for the two weeks that were allotted to the project.

Huragok
Sep 14, 2011

pseudorandom name posted:

Hey, he did a pretty good job for the two weeks that were allotted to the project.

The rule is prototypes always get promoted to production.

pseudorandom name
May 6, 2007

I'm fairly sure they knew it was destined for production from the beginning.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The entire point of the ten-day deadline was to get it into production before the alternative far worse scripting language being worked on.

Deus Rex
Mar 5, 2005

GrumpyDoctor posted:

JavaScript arrays are definitely goofier than I expected:

Time is a flat circle

Strong Sauce
Jul 2, 2003

You know I am not really your father.





necrotic posted:

I think the real horror here is using for-in on an array. (Sorry, a NodeList!)

NodeList is type of Object generated by the DOM, but it has no inherit properties of an Array.

`for (x in obj)` is mainly used by Javascript Objects and not for arrays. And the only reason you'd have to keep using it is for backwards compatibility with older browsers. Otherwise you just iterate over Object.keys()

Mr.Radar
Nov 5, 2005

You guys aren't going to believe this, but that guy is our games teacher.

Plorkyeran posted:

The entire point of the ten-day deadline was to get it into production before the alternative far worse scripting language being worked on.

Could you elaborate? I've never heard that there was something even worse than JavaScript that was being pushed and Wikipedia and Google aren't turning anything up.

tractor fanatic
Sep 9, 2005

Pillbug
I think it was VBScript

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Mr.Radar posted:

Could you elaborate? I've never heard that there was something even worse than JavaScript that was being pushed and Wikipedia and Google aren't turning anything up.
It never made it into a public beta (as avoiding that was the whole point of making JS in two weeks), so there isn't really any information left about it other than various comments from ex-Netscape engineers. Given the constraints JS had (it had to look like Java, but was not allowed to have anything that looked complex like classes), it's certainly easy to imagine how something much worse could have been designed.

tractor fanatic posted:

I think it was VBScript
IE 1 hadn't even been released yet.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

HORATIO HORNBLOWER posted:

Well that's kind of the point, though. An array is iterable so you'd expect for-in to work with it just fine. But there's so many gotchas with the construct in JavaScript that it's best just to avoid it.

Yeah. To be honest I never use it. ES5 shim and iterator methods is my preferred.

Coffee Mugshot
Jun 26, 2010

by Lowtax
PHP: The Good Parts

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

Mr.Radar posted:

Could you elaborate? I've never heard that there was something even worse than JavaScript that was being pushed and Wikipedia and Google aren't turning anything up.

I think it was going to be Tcl. There was an article about it on the 20th anniversary of the language, but I can't find it any more.
The best I've got is two paragraphs in http://sdt.bz/31644.

qntm
Jun 17, 2009

Budum-tsssh

the littlest prince
Sep 23, 2006


Plorkyeran posted:

The entire point of the ten-day deadline was to get it into production before the alternative far worse scripting language being worked on.

Wait, JS was written in 10 days to avoid a terrible scripting language from becoming a standard? Did they really not see the error in this logic?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
By 1995 standards, JS is pretty awesome. It was the first "mainstream" language with first-class functions and good object/array literals, and while I'm not a huge fan of prototype inheritance, it's better than nothing. Just compare JS to VBScript 1.0 (which came after JS) to see how much worse it could have been.

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS
ES6 is going to be even more awesome :)

http://code.tutsplus.com/tutorials/eight-cool-features-coming-in-es6--net-33175

I love JavaScript :D

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

I look forward to never being able to use any of this because everyone will still need to retain compatibility with older browsers.

Also that "object decomposition" thing looks like a horror.

raminasi
Jan 25, 2005

a last drink with no ice

Dessert Rose posted:

I look forward to never being able to use any of this because everyone will still need to retain compatibility with older browsers.

Also that "object decomposition" thing looks like a horror.

What, destructuring? Destructuring is amazing. Once you get used to it you feel straightjacketed without it.

Dren
Jan 5, 2001

Pillbug
Anyone have a recommended tutorial/book for programmers trained in Java who keep loving up the usage of C strings in just about every possible way?

down with slavery
Dec 23, 2013
STOP QUOTING MY POSTS SO PEOPLE THAT AREN'T IDIOTS DON'T HAVE TO READ MY FUCKING TERRIBLE OPINIONS THANKS

Dessert Rose posted:

I look forward to never being able to use any of this because everyone will still need to retain compatibility with older browsers.

IE 8 and IE 9 are really the only things left holding on to the whole "support every browser" crap. How long do you expect their life cycle to last?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Dren posted:

Anyone have a recommended tutorial/book for programmers trained in Java who keep loving up the usage of C strings in just about every possible way?

Learn valgrind, make mistakes, and please don't use C.

pseudorandom name
May 6, 2007

GrumpyDoctor posted:

What, destructuring? Destructuring is amazing. Once you get used to it you feel straightjacketed without it.

Yes, replacing names with implicit numeric labels is certainly an improvement.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Dessert Rose posted:

I look forward to never being able to use any of this because everyone will still need to retain compatibility with older browsers.

Well if you used node for all of your server programming you could use them today! Or at release. Or whatever.

Polio Vax Scene
Apr 5, 2009




That is not eight features, and not all of them are cool.

Adbot
ADBOT LOVES YOU

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Dessert Rose posted:

I look forward to never being able to use any of this because everyone will still need to retain compatibility with older browsers.

https://github.com/google/traceur-compiler

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply