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
JawnV6
Jul 4, 2004

So hot ...

necrotic posted:

Also someObject['!+#%'] works

found one

Adbot
ADBOT LOVES YOU

DimpledChad
May 14, 2002
Rigging elections since '87.

necrotic posted:

Also someObject['!+#%'] works but someObject.!+#% will definitely not.

Can't tell you how many times that's come in handy





































because it never has.

qntm
Jun 17, 2009
You can also set properties dynamically using someObject[someStringVariable]. Since someStringVariable can be any string, including the empty string or something with spaces or slashes, you might need someObject[''] etc. to get the value back out again.

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

DimpledChad posted:

Can't tell you how many times that's come in handy

I'm not saying its useful at all.

Don Mega
Nov 26, 2005
There's plenty of valid reasons to hate on javascript, but this isn't one of them

fritz
Jul 26, 2003

DimpledChad posted:

Can't tell you how many times that's come in handy

because it never has.

You, uh, just did.

Mogomra
Nov 5, 2005

simply having a wonderful time

KARMA! posted:

someObject['name' + i] and someObject[anotherVariable]. ;)

That's obviously the correct use for accessing properties in objects like that, but I specifically said, "You already know the property name." ;)

necrotic posted:

Also someObject['!+#%'] works but someObject.!+#% will definitely not.

That... Sorta makes sense. :negative:

Illusive Fuck Man
Jul 5, 2004
RIP John McCain feel better xoxo 💋 🙏
Taco Defender
code:
    if (!IS_BIG_ENDIAN) {
        i = 0;
        while (i < ret / sizeof(uint32_t)) {
            *((uint32_t *) ((*raw) + (i * sizeof(uint32_t)))) = htobe32(
                    *((uint32_t * )((*raw) + (i * sizeof(uint32_t)))));
            i++;
        }
    }
im cryeing

Deus Rex
Mar 5, 2005

DimpledChad posted:

Can't tell you how many times that's come in handy





































because it never has.

Oh really, you've never accessed a Javascript array like xs[0]?

raminasi
Jan 25, 2005

a last drink with no ice

Deus Rex posted:

Oh really, you've never accessed a Javascript array like xs[0]?

JavaScript array indexing and JavaScript object property access are different things, despite having identical syntax. :haw:

DimpledChad
May 14, 2002
Rigging elections since '87.

Deus Rex posted:

Oh really, you've never accessed a Javascript array like xs[0]?

I meant accessing an object property like foo['*&Q#$^*'].

I'm not really saying that in particular is a misfeature. It's actually sometimes useful to access an object property as a string. But if someone gave a property a name that could ONLY be accessed that way, I would punch them in the face.

TURTLE SLUT
Dec 12, 2005

You'd punch me in the face if I ever used a hash map in JS?

DimpledChad
May 14, 2002
Rigging elections since '87.
No, if you deliberately named an object property with special characters like that. It's petty, I know, but it offends my sensibilities. Okay, if you had a really good reason...

But yeah I guess it would be fine in the context of a plain hash map, if you needed special characters in the keys. The thing I was thinking of that would make me mad is the following:

code:
var foo = {};
foo['*$(%*W$&)@'] = function() { return 'bar'; };
console.log(foo['*$(%*W$&)@']());

comedyblissoption
Mar 15, 2006

In older versions of javascript, you needed to de-reference an object property in that way if it was a javascript reserved word. This was an unnecessary flaw in the original language spec. This flaw is also the reason why the json spec requires you to put quotes around the object property.

Suspicious Dish
Sep 24, 2011

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

GrumpyDoctor posted:

JavaScript array indexing and JavaScript object property access are different things, despite having identical syntax. :haw:

Probably sarcasm considering the smiley, but nope. Try arr["0"].

Suspicious Dish
Sep 24, 2011

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

"... and a 534 other ways to reload the page with JavaScript"

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

GrumpyDoctor posted:

JavaScript array indexing and JavaScript object property access are different things, despite having identical syntax. :haw:

No, they are the same get-property operation. Try arr["0"], for example.

e: :hf: Sir Dish

TheresaJayne
Jul 1, 2011

Ithaqua posted:

The people who don't care about being paid a fair market value for their skills are almost always lovely; the reason they don't care is because they're just grateful that they were able to convince someone to hire them.

Well i took my current medium paid role in a large enterprise company for job security.
I was on 50,000 UKP a year on previous jobs and have taken a 15,000 UKP pay cut for my current job, but i am guaranteed a position until the end of 2015 and very probably for the next 10 years if i want it.

I have had too many jobs where i have been in a short term role for 6 months to a year. but its time to settle down.
the pay was nice but hey job security is even better.

linusBorlaug
Aug 1, 2013
I found this gem yesterday.
code:
 <cfset Today = CreateDate(Year(Now()),Month(Now()),Day(Now()))> 

Athas
Aug 6, 2007

fuck that joker

Illusive gently caress Man posted:

code:
    if (!IS_BIG_ENDIAN) {
        i = 0;
        while (i < ret / sizeof(uint32_t)) {
            *((uint32_t *) ((*raw) + (i * sizeof(uint32_t)))) = htobe32(
                    *((uint32_t * )((*raw) + (i * sizeof(uint32_t)))));
            i++;
        }
    }
im cryeing

This is what I don't understand. Dealing with endianness is so bloody easy in C, so why do people gently caress it up? Here, do it like this:

code:
#ifdef SMALL_ENDIAN
uint32_t from_big_endian(uint32_t in)
{
  uint32_t out;
  char *p_in = (char *) &in;
  char *p_out = (char *) &out;
  p_out[0] = p_in[3];
  p_out[1] = p_in[2];
  p_out[2] = p_in[1];
  p_out[3] = p_in[0];

  return out;
}
#else
uint32_t from_big_endian(uint32_t in)
{
  return in;
}
#endif
Now, there's still plenty of room to bikeshed over this code, but the two basic principles of handling endianness are:

  • Talk about what the serialised representation is/should be, not what the in-memory representation this.
  • Define some bloody functions.

It's really not hard to get right. Why do people gently caress it up?

sarehu
Apr 20, 2007

(call/cc call/cc)
Doesn't that violate aliasing or something? Use a union.

pseudorandom name
May 6, 2007

Why are you reimplementing be32toh() and what does that have to do with the coding horror posted?

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

sarehu posted:

Doesn't that violate aliasing or something? Use a union.

Or use masks and shifts like god intended.

astr0man
Feb 21, 2007

hollyeo deuroga

With regard to using macros here, you might not always know the endianness of your target system at compile time. Some processor architectures (I'm looking at you PowerPC) can run in both little and big endian modes depending on a flag you can set in a register.

Hiowf
Jun 28, 2013

We don't do .DOC in my cave.

quote:

It's really not hard to get right.

quote:

Doesn't that violate aliasing or something?

quote:

Why are you reimplementing be32toh()

be32toh is nonstandard. The Android libc/NDK didn't (use?) to have it, for example.

astr0man posted:

With regard to using macros here

It would've worked (or not) with an if just as well. Totally orthogonal to the issue.

NFX
Jun 2, 2008

Fun Shoe

astr0man posted:

With regard to using macros here, you might not always know the endianness of your target system at compile time. Some processor architectures (I'm looking at you PowerPC) can run in both little and big endian modes depending on a flag you can set in a register.

Now I want a solution that just sets the appropriate flag instead of byte swapping.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

sarehu posted:

Doesn't that violate aliasing or something?

Not if the referencing pointer is char *, right? I think that's the C99 rule.

astr0man
Feb 21, 2007

hollyeo deuroga

NFX posted:

Now I want a solution that just sets the appropriate flag instead of byte swapping.

An operating system that regularly did this would be appropriate for this thread :v:

fritz
Jul 26, 2003

Skuto posted:

be32toh is nonstandard. The Android libc/NDK didn't (use?) to have it, for example.

htonl?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

astr0man posted:

An operating system that regularly did this would be appropriate for this thread :v:

To my hilariously non-expert knowledge, if you were byte-swapping a ton of data and the penalty for changing the current CPU mode was low enough, it might make sense to do it.

But I'm guessing you're right.

Admiral H. Curtiss
May 11, 2010

I think there are a bunch of people who can create trailing images. I know some who could do this as if they were just going out for a stroll.

Subjunctive posted:

Not if the referencing pointer is char *, right? I think that's the C99 rule.

I think you can cast it to char* but after that aren't allowed to touch it again as the int? There's some reason why it's not recommended, anyway. Just use unions.

e: http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
Ah, what I was thinking of is casting the char* back to something else.

Admiral H. Curtiss fucked around with this message at 18:43 on Nov 19, 2014

pseudorandom name
May 6, 2007

Skuto posted:

be32toh is nonstandard. The Android libc/NDK didn't (use?) to have it, for example.

The original horror is using it, the reason why it is a horror is the overly convoluted pointer manipulation to byteswap the array.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Admiral H. Curtiss posted:

I think you can cast it to char* but after that aren't allowed to touch it again as the int? There's some reason why it's not recommended, anyway. Just use unions.

No, char * is special as char is always assumed to alias other types.

Athas
Aug 6, 2007

fuck that joker

pseudorandom name posted:

Why are you reimplementing be32toh() and what does that have to do with the coding horror posted?

The bikeshed in question was for a freestanding kernel (no standard library and certainly no POSIX implementation), so I had to write the code.

And isn't the original horror a byte-swapper? I actually didn't read it too closely, but whenever I see impenetrable code saying something about "endian" followed by weird address and/or shift manipulations, I assume that someone misunderstood endianness.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
EDIT: nvm

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

rjmccall posted:

EDIT: nvm

aw, c'mon man, I can take it.

Edison was a dick
Apr 3, 2010

direct current :roboluv: only

astr0man posted:

With regard to using macros here, you might not always know the endianness of your target system at compile time. Some processor architectures (I'm looking at you PowerPC) can run in both little and big endian modes depending on a flag you can set in a register.

ARMv7 allows this too. My employer did a big-endian ARM port of a Linux distribution for a customer where that was easier than porting all their existing software.
The fun bit was that rather than building a Linux compiled for big-endian and doing some magic to make the CPU start in big-endian mode, rather than defaulting to little, as part of boot the first thing the kernel did was to swap the endianness to big, so the majority of the kernel and all of the userland could operate in big-endian mode.

I think we could even switch to little-endian in userland, but you'd have to switch back to big to make system calls.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

linusBorlaug posted:

I found this gem yesterday.
code:
 <cfset Today = CreateDate(Year(Now()),Month(Now()),Day(Now()))> 
Coldfusion? You poor bastard.

DimpledChad
May 14, 2002
Rigging elections since '87.
Does this qualify as a coding horror? https://github.com/naetech/nightrain

quote:

Create your next OS X, Windows or Linux desktop application in pure PHP, CakePHP, Laravel, or whatever PHP framework you like. PHP Nightrain is a packager written in Python for the PHP Programming Language. Using this tool you can convert your PHP/HTML/CSS/Javascript application to a Native Desktop Application. Currently, PHP Nightrain supports the Windows, Mac (OS X) and the Linux operating systems.

Adbot
ADBOT LOVES YOU

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
My only question is why

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