Search Amazon.com:
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 $3,400 per month for bandwidth bills alone, and since we don't believe in shoving popup ads to our registered users, we try to make the money back through forum registrations.
«630 »
  • Post
  • Reply
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.

Plorkyeran posted:

I do think he's overstated the degree to which it's a problem, though. PHP's arrays are pretty obviously the result of a bunch of features being crammed in rather than any sort of design, but the end result isn't all that bad.

I think this is by and large PHP's problem in general, not just that specific corner of it. Instead of the design of the language being carefully thought out and designed with attention to detail and an appreciation of how all the pieces will fit together, PHP has developed as a series of ad-hoc solutions to problems that were considered in isolation. That's why the whole thing comes off as so ill-considered, why myfunction()[0] didn't work for so long, etc. It's just a series of "good enough" improvements that don't gel with one another. In contrast to other languages that are more "curated", PHP just coalesced over time. This also ensures a plentiful supply of odd behaviours that have to be maintained in order not to break existing code, which makes it hard to fix the problem parts of the language. I don't really think there's an easy way to fix things at this stage. The best that can be hoped for is to try to get more advice out on the internet that tells newbies how to do PHP "the right way", in other words getting them to use error reporting, getting them to write maintainable code, avoiding the mysql_* functions and so on. In the end PHP can't be wholly fixed and it will always be something that serves as a bit of an object lesson, something that people can look at and say "ah, so that is why such and such other language is designed the way it is".

Adbot
ADBOT LOVES YOU

Plastic Snake
Mar 2, 2005
For Halloween or scaring people.

code:
parseInt(1/0, 19); //18
I love Javascript so much.

Zamujasa
Oct 27, 2010

Link, some day you will leave this island...
I just know it in my heart...
Please, just don't ever forget this song... or me...


More Tales from The Boss.

Today, one of our external servers stopped working suddenly. It was up, it was running, but for some reason the heartbeat on it wasn't working properly (and the heartbeat drives the whole box, basically; it uses that time to get new jobs. This is a horror all to its own, but I didn't design this.)

Restarting the server didn't help; restarting the program that manages the heartbeat didn't help. Since it talks over SSL, Wireshark was out of the question*. Basically, he was stumped! (I personally stopped caring since I couldn't do anything about it.)

It turns out that the clock on that box was a day ahead. And... It also turns out that our SSL certificates expire tomorrow. Oops. Oh well -- a quick call and our SSL cert is extended and all is good! So surely we'll be setting a reminder or something on our calendars for next year, ri--

quote:

I set it two days ahead! That way next time this happens only this one will go down and we'll have two days to extend it!



You would think after the "One year ahead doomsday" switch he put in a different program that he really would've learned by now. For that one, he needed a date in the future; not too far into the future, but far enough that it would be a ways off. So he set it for a year past that day. Lo and behold, one year later, it suddenly stops working, everything grinds to a halt, and nobody has any idea what went wrong... until he suddenly realizes what day it is, goes in, and then sets it a year ahead again. Even after I told him that he can just take the current date and add a year to make it less bomb-y (VB6).


*: Wireshark can decode SSL if you give it the cert, but I am not allowed to touch this server for whatever reason. I have physical access -- I can literally go to our colocation facility and mess with them -- but I can't actually remote into them for whatever reason.


EDIT: Oh, I should also mention that this wonderous program he wrote has no sort of health/sanity checks or error reporting, either. It's basically a hard-coded black-box of VB6 vomit that somehow manages other programs/scripts and oh god it's just awful. So of course in a failure condition it doesn't actually send out an alert or use a backup method, it just ceases to function.

The sad part is that the fix to this is something I wrote in my spare time that just checks if we've gotten a heartbeat out of it in the last few minutes. If not, it sends out an email and tries to stop anything from assigning jobs to that box. Good times.

Zamujasa fucked around with this message at Jul 6, 2012 around 23:20

KaneTW
Dec 2, 2011

Jones killed Solaire! How could she.



I think it's time to look out for a new job

pokeyman
Nov 26, 2006

What do you like to play?

Plastic Snake posted:

code:
parseInt(1/0, 19); //18
I love Javascript so much.

It took me a minute to figure out what was going on, but once I did, I'm not sure what other result you were expecting.

Zamujasa
Oct 27, 2010

Link, some day you will leave this island...
I just know it in my heart...
Please, just don't ever forget this song... or me...


KaneTW posted:

I think it's time to look out for a new job

Believe me, I'm getting there. It was fun overhearing how the big boss here loves "social misfits" like me because we have trouble finding and keeping jobs, so he gets to pay us poo poo. I found out a few days before that I make $14/hr while my coworker (who does basically the same thing I was doing on the side) makes $20/hr.

Good times.


E: Oh, they're also planning on hiring some "director" who can give us two programmers deadlines to meet, because clearly there's nothing wrong with that idea. Nope.

Gazpacho
Jun 18, 2004



Plastic Snake posted:

code:
parseInt(1/0, 19); //18
I love Javascript so much.
Here's a little advice:

http://www.youtube.com/watch?v=zCh7z5EwYF8#t=1s

Wheany
Mar 17, 2006

By Allah!
White people
are so STUPID!


pokeyman posted:

It took me a minute to figure out what was going on, but once I did, I'm not sure what other result you were expecting.

MDN posted:

The parseInt function converts its first argument to a string, parses it, and returns an integer or NaN. If not NaN, the returned value will be the decimal integer representation of the first argument taken as a number in the specified radix (base). For example, a radix of 10 indicates to convert from a decimal number, 8 octal, 16 hexadecimal, and so on. For radices above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

>>> "" + 1/0
"Infinity"

>>> parseInt("I", 19)
18

>>> parseInt(1/0, 36)
1461559270678

>>> parseInt("Infinity", 36)
1461559270678

pokeyman
Nov 26, 2006

What do you like to play?

We've covered php.js already, right?

phpjs.org posted:

php.js is an open source project that brings high-level PHP functions to low-level JavaScript platforms

phpjs.org posted:

we think of it as a challenge to port everything and decided to also port low-level PHP functions like strpos even though it may have a JavaScript counterpart (String.indexOf).
Cause besides the intellectual challenge for us, porting more also opens up php.js to all kinds of thought excercises and study purposes.

(emphasis in original)

Aleksei Vasiliev
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

quote:

PHP is a language with many high-level functions and while they're not always implemented as consistently as we'd like (mostly to blame on its underlying C parts), it has a huge following familiar with its syntax so it makes sense to pick its API as a reference.
no it loving doesn't and the first half of your sentence says so!

That Turkey Story
Mar 30, 2003



quote:

PHP is a language with many high-level functions and while they're not always implemented as consistently as we'd like (mostly to blame on its underlying C parts)

Err... what??? How can you possibly push the blame onto C.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof


That Turkey Story posted:

Err... what??? How can you possibly push the blame onto C.

Presumably he's saying that PHP functions are inconsistent because so many of them are thin wrappers around C library APIs that are inconsistent with each other.

It's a plausible explanation that excuses nothing.

hobbesmaster
Jan 28, 2008

We are Legion, a terminal of the Geth.


That Turkey Story posted:

Err... what??? How can you possibly push the blame onto C.

It's true though, a lot of php's issues are because the authors are terrible/lazy C programmers.

Aleksei Vasiliev
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

Pretty sure the method naming and parameter order consistency issues are not because of the C API, they are because of the PHP devs. It's stuff like mysql_escape_string that are thin wrappers over the C API. Nevertheless, the php.js people have faithfully replicated those issues for no good reason whatsoever.

Wheany
Mar 17, 2006

By Allah!
White people
are so STUPID!


pokeyman posted:

We've covered php.js already, right?

quote:

porting more also opens up php.js to all kinds of thought excercises and study purposes.

No. gently caress you.

If you're thinking that something like this is remotely desirable
Javascript code:
var literal_poop = [];
array_push(array_push(literal_poop.push('s'), 'h').push('i'), 't');
you are broken.

Look Around You
Jan 19, 2009

You're just lucky my jaw is broken!


pokeyman posted:

We've covered php.js already, right?



(emphasis in original)

The best part is that most of the people who write compilers for other languages to target JS do so because they want clearer syntax and semantics than JS, not worse.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

I've seen things you people wouldn't believe. Servers running PHP off the shoulder of Javascript. I've watched C-strings glitter in the dark near the NAND gate. All those… moments will be lost in time, like tears… in rain. Time to die.

Hughlander
May 11, 2005



Mustach posted:

I've seen things you people wouldn't believe. Servers running PHP off the shoulder of Javascript. I've watched C-strings glitter in the dark near the NAND gate. All those… moments will be lost in time, like tears… in rain. Time to die.

The original spoof version of that was good as well:
"I have seen things you people would not believe... I've seen Sun monitors on fire off the side of the multimedia lab. I've seen NTU lights glitter in the dark near the Mail Gate. All these things will be lost in time, like the root partition last week. Time to die..."

Plastic Snake
Mar 2, 2005
For Halloween or scaring people.

pokeyman posted:

It took me a minute to figure out what was going on, but once I did, I'm not sure what other result you were expecting.

It makes perfect sense once you know what's going on. Less of a horror and more of a funny quirk, I guess. And I wasn't being sarcastic, I actually do love Javascript.

Cirian
Nov 7, 2002


Imagine what you get when you start with a horrible, ugly, slow language (Objective-C), and you selectively discard some (but not all C-isms), replacing them with a sprinkling of JavaScript, Pascal and Ruby. Finish it off with a dash of pure crazy, and you get this, the Eero Programming Language.

Amazingly the guy behind it actually wrote a full Clang module to support it.

Some of the epic features:
- (Mostly-)Optional semicolons
- Removal of braces in favour of indentation-level blocks, except where you have to explicitly put "end" to mark the end of some special blocks
- Removal of certain C language features for "safety" (goto, switch fall-through)
- Magic extraction of variable names from method calls based on the last camel-case word in the method name
- Automatically adding "NS"- prefix to typenames if it can't find the type

Uncomfortable Gaze
Jul 14, 2007



Cirian posted:

Imagine what you get when you start with a horrible, ugly, slow language (Objective-C), and you selectively discard some (but not all C-isms), replacing them with a sprinkling of JavaScript, Pascal and Ruby. Finish it off with a dash of pure crazy, and you get this, the Eero Programming Language.

Amazingly the guy behind it actually wrote a full Clang module to support it.

Some of the epic features:
- (Mostly-)Optional semicolons
- Removal of braces in favour of indentation-level blocks, except where you have to explicitly put "end" to mark the end of some special blocks
- Removal of certain C language features for "safety" (goto, switch fall-through)
- Magic extraction of variable names from method calls based on the last camel-case word in the method name
- Automatically adding "NS"- prefix to typenames if it can't find the type

Anyone who thinks switch fall-through isn't a good feature should write a state machine.

Heh, NSNSSomeType errors.

shrughes
Oct 11, 2008

(call/cc call/cc)


Geekner posted:

Anyone who thinks switch fall-through isn't a good feature should write a state machine.

Even then it's better to goto top; and reenter the switch.

But I like to play dirty and explicitly goto the next switch statement instead of implicitly falling through.

code:
    state = BLAH_STATE;
    goto in_blah_state;
    break;
  case BLAH_STATE;
    in_blah_state:

pseudorandom name
May 6, 2007
INSOLENT


Fall-through should be removed, but in turn you should be able to goto switch labels.

Opinion Haver
Apr 9, 2007



Cirian posted:

- Magic extraction of variable names from method calls based on the last camel-case word in the method name

This is one of those ideas that's great until you think about it.

Huragok
Sep 14, 2011


I gotta say, I like it. Maybe my extended use of JavaScript has corrupted me.

pokeyman
Nov 26, 2006

What do you like to play?

I can't decide if implementing faux namespaces by specifying a default prefix for unknown types is brilliant or insane.

Rothon
Jan 3, 2012


I like the way Go handles switch statements. It's sort of the reverse of C; breaking at the end of a case is the default, and there is a fallthrough keyword if you actually want to continue to the next case.

Suspicious Dish
Sep 24, 2011



Rothon posted:

I like the way Go handles switch statements. It's sort of the reverse of C; breaking at the end of a case is the default, and there is a fallthrough keyword if you actually want to continue to the next case.

But then how will I implement my Duff's Device shortly and succinctly?

bobthecheese
Jun 7, 2006
Although I've never met Martha Stewart, I'll probably never birth her child.

Geekner posted:

Anyone who thinks switch fall-through isn't a good feature should write a state machine.

The other day I wrote a post about possible changes to switch statement flow through. The concept may or may not be a horror (I'll leave that up to you to decide), but not quite as much of a horror as this piece of documentation from PHP:

quote:

Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.

That Turkey Story
Mar 30, 2003




Maybe I'm missing something, but isn't your example just equivalent to a switch nested inside of a while loop:
code:
{
  int s = some_var;
  while(true)
  {
    switch(s)
    {
      // Your stuff here as written with the continue. break by going to the label
    };
  }
}
a_goto_label:

Aleksei Vasiliev
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.

No. He changed the semantics of continue in a switch case. It acts like fallthrough but requires re-evaluation of the variable versus the cases.
So the value of 2 would fall in at case 2, normally fallthrough to case 3, hit continue, and then fall back in at the penultimate case, case $s > 0. It would not match case $s > 4; with normal fallthrough, it would hit that.

Unless I completely misunderstood your question.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.

bobthecheese posted:

The other day I wrote a post about possible changes to switch statement flow through. The concept may or may not be a horror (I'll leave that up to you to decide), but not quite as much of a horror as this piece of documentation from PHP:

While "switch is a looping structure" looks peculiar at first glance, there is a sensible enough reason for it. PHP supports breaking/continuing in nested loops using statements like "break 2" or "continue 3", and with this being the case it makes sense to regard switch as a looping structure for the purposes of "continue", because it is one for "break" by necessity and otherwise the 2 (say) in "break 2" and in "continue 2" would refer to different levels in the nested loop hierarchy, which would be far more confusing. You could argue that allowing developers to name the loops would make more sense, but given that they used numbers instead using "continue sees switch as a loop" is the only sane way to go.

PrBacterio
Jul 19, 2000


pseudorandom name posted:

Fall-through should be removed, but in turn you should be able to goto switch labels.
This seems like the best solution to me. Because that php break/continue thing with switch statements being classified as loops just reminded me that I've always felt that C's syntax for switch statements is fundamentally broken.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.

Rothon posted:

I like the way Go handles switch statements. It's sort of the reverse of C; breaking at the end of a case is the default, and there is a fallthrough keyword if you actually want to continue to the next case.
This is the best way I've seen for it, C# comes second. (Go gets bonus points for allowing non-constant expressions in cases.) Fallthrough can be useful, but it's far from the common case and making it the default behavior is silly. I get that it's supposed to be similar to goto labels, but that doesn't make it better.

BP
Jun 9, 2004

nevermind


Generating an unused record ID as part of creating a new record on our DB can take more than a minute unless the database instance has run some code specific to that record type in the past. This is likely to have been done for common record types for all instances, but for less-common record types? Who knows! And it might vary by DB instance.

It's also difficult to test for because the issue that the workaround code avoids doesn't exist in development databases, meaning if you forget the issue will be caught in release testing at the earliest. [edit: to be fair, it could also be caught on our QA instances, but it's possible for the workaround to be in place on the shared QA instances already]

BP fucked around with this message at Jul 11, 2012 around 19:23

Golbez
Oct 9, 2002

SHATNER SECRETS

BP posted:

Generating an unused record ID as part of creating a new record on our DB can take more than a minute unless the database instance has run some code specific to that record type in the past. This is likely to have been done for common record types for all instances, but for less-common record types? Who knows! And it might vary by DB instance.

It's also difficult to test for because the issue that the workaround code avoids doesn't exist in development databases, meaning if you forget the issue will be caught in release testing at the earliest.

Why not use an autoincrement?

BP
Jun 9, 2004

nevermind


Golbez posted:

Why not use an autoincrement?

That is what is used by most record types. The problem is that we can define ranges of record IDs that can only be used by us (ie a customer record can never use that ID). We have code that checks this & a few other conditions when evaluating whether an ID received from the increment process is appropriate to use. Typically the range of predefined record IDs is the first 100000 or 1000000 IDs--and when you attempt to create a record at a customer site, unless you've manually updated the "next ID" for the autoincrement, it will happily loop through this range, attempting to validate each ID for use and then realizing that it can't use the ID. This can take quite a while.

The right thing to do (IMO) would be for the validation code to be smart enough that when a record ID is checked that is inside of a range of unusable records, increment to the next ID outside the range instead of incrementing by 1. Instead we only increment by 1, and devs get caught off-guard as this fact about ID generation is not very well known.

jarito
Aug 26, 2003



BP posted:

The right thing to do (IMO) would be for the validation code to be smart enough that when a record ID is checked that is inside of a range of unusable records, increment to the next ID outside the range instead of incrementing by 1. Instead we only increment by 1, and devs get caught off-guard as this fact about ID generation is not very well known.

Not sure about your use case, but I don't think so. Don't base business logic decisions from auto-incrementing primary keys. Use a separate field or data-type to indicate whatever business case you have.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Am I the only one who thinks things like Order ID's should just be generated with a UUID? It would solve SO many problems.

Adbot
ADBOT LOVES YOU

jarito
Aug 26, 2003



trex eaterofcadrs posted:

Am I the only one who thinks things like Order ID's should just be generated with a UUID? It would solve SO many problems.

IIRC there are some issues in using UUIDs for auto-generating keys in some databases. It's been a while since I looked into it so that might not be an issue anymore.

Even so, using UUIDs doesn't seem to solve his problem since what they need is a way to differentiate two of the same record types. They are using a 'reserved' part of the PK key space which, with UUIDs, would be about a bajillion times worse. It sounds like they just need a separate field.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply
«630 »