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
trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

jarito posted:

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.

To that I would say don't have the DB autogenerate the ID, have the middleware generate the UUID for you.
Plus yes they need a separate column. Being clever and doing wizardry on the PK screams "bad architecture."

Adbot
ADBOT LOVES YOU

Zhentar
Sep 28, 2003

Brilliant Master Genius

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.

You are apparently not, since we have a non-trivial number of tables with UUID primary keys.

jarito posted:

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.

Reserving part of the UUID key space isn't very hard (prepending the UUID with a particularl constant, for example)


BP's stretching a bit with the horror though. It's an overlooked edge case in legacy code, and he's probably the first developer to ever be seriously bitten by the issue.

Zhentar fucked around with this message at 01:22 on Jul 12, 2012

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

Zhentar posted:

You are apparently not, since we have a non-trivial number of tables with UUID primary keys.

Thank the baby jesus.

ozymandOS
Jun 9, 2004

Zhentar posted:

BP's stretching a bit with the horror though. It's an overlooked edge case in legacy code, and he's probably the first developer to ever be seriously bitten by the issue.

Probably the first in a while, yes. But there's standard code to set the next ID to a new value, so I suspect it's been a problem in the past.

Also: there are UUID primary key tables??

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
I've done this before for certain cases but we always made the "system" IDs be negative numbers so regular transactions could go on with IDENTITY/auto values and we could do identity inserts for the system records (which are infrequent enough that we can just scan the table for new IDs since it isn't concurrent either).

Of course when it is up to me I just add a column to store the record type like a sane person.

Johnny Cache Hit
Oct 17, 2011

BP posted:

Also: there are UUID primary key tables??

:ssh: using UUIDs as pkeys is really really awesome :ssh:

McGlockenshire
Dec 16, 2005

GOLLOCKS!

Kim Jong III posted:

:ssh: using UUIDs as pkeys is really really awesome :ssh:

Except on InnoDB and other databases that treat the primary key as a clustered index. Those random-rear end IDs are going to get stuck all over the table and waste a lot of I/O time doing so.

EssOEss
Oct 23, 2006
128-bit approved
That is why you use a modified GUID with clustered indexes, so that the GUIDs are sorted by a timestamp that replaces the most significant part of the GUID data.

The GUID data space is so large that this does not lead to any significant loss of uniqueness, while also allowing nice performance with clustered indexes. I have successfully used clustered GUID primary keys with SQL Server tables up to 100 GB (+indexes), with no real downsides. I have not seen integer primary keys in years :)

Which part of the GUID should be the timestamp might depend on the database engine. For example, with SQL Server, you need to make it the last bit, like seen here:
code:
E25AFE33-DB2D-4502-9BF0-919001862D20
83E689D3-8549-4094-B223-919001862D20
CC22A56D-0CD5-43C5-990E-919001862D20
D5149998-1718-468C-B1AD-919001862D21
CBD0182D-4A0E-40AC-9A4C-919001862D21
Here is an old but still relevant article about SQL Server GUID primary key performance: http://www.informit.com/articles/article.aspx?p=25862&seqNum=7

EssOEss fucked around with this message at 08:51 on Jul 12, 2012

KaneTW
Dec 2, 2011

What are the reasons for using UUID primary keys except for doesn't require auto-increment/making ids not guessable?

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

KaneTW posted:

What are the reasons for using UUID primary keys except for doesn't require auto-increment/making ids not guessable?

One example that I've personally dealt with:

If you have a geographically diverse application with multiple local databases that eventually need to be centralized for reporting or whatever, the UUID will make the rollup operation so much easier.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

This is one line of Ruby. I'm not going to use the code tag because it will break tables.

= form.select :id, [["-- Choose --", ""]].concat((@current_user ? @current_user.promotion : @promotion).locations.nested(nested_level, (@current_user||@user).locations(nested_level - 1)).collect{|l| [l.name, l.id]}),{:selected => (@current_user||@user).locations(nested_level).nil? ? nil : (@current_user||@user).locations(nested_level).id}, :name => 'locations[][id]', :class => "required"

390 loving characters

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

trex eaterofcadrs posted:

One example that I've personally dealt with:

If you have a geographically diverse application with multiple local databases that eventually need to be centralized for reporting or whatever, the UUID will make the rollup operation so much easier.

Riak, which is distributed/locally replicated (and supports replication over high-latency links in the expensive version) uses random strings as default keys for the same reason.

Vintersorg
Mar 3, 2004

President of
the Brendan Fraser
Fan Club



Bob Morales posted:

This is one line of Ruby. I'm not going to use the code tag because it will break tables.

= form.select :id, [["-- Choose --", ""]].concat((@current_user ? @current_user.promotion : @promotion).locations.nested(nested_level, (@current_user||@user).locations(nested_level - 1)).collect{|l| [l.name, l.id]}),{:selected => (@current_user||@user).locations(nested_level).nil? ? nil : (@current_user||@user).locations(nested_level).id}, :name => 'locations[][id]', :class => "required"

390 loving characters


Looks like one giant long ternary statement. Not the fault of Ruby as I could do the same in Java.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Vintersorg posted:

Looks like one giant long ternary statement. Not the fault of Ruby as I could do the same in Java.

I'm just saying that it could be written differently and be a hundred times more readable

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bob Morales posted:

I'm just saying that it could be written differently and be a hundred times more readable

Anyone who does something like that in any language should have the living poo poo beaten out of them. I like this example of ternary horror, personally: http://stackoverflow.com/q/9101719/781754

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Bob Morales posted:

This is one line of Ruby. I'm not going to use the code tag because it will break tables.

= form.select :id, [["-- Choose --", ""]].concat((@current_user ? @current_user.promotion : @promotion).locations.nested(nested_level, (@current_user||@user).locations(nested_level - 1)).collect{|l| [l.name, l.id]}),{:selected => (@current_user||@user).locations(nested_level).nil? ? nil : (@current_user||@user).locations(nested_level).id}, :name => 'locations[][id]', :class => "required"

390 loving characters


Oh god and it's done in a template too?

It belongs in a museum a helper:
Ruby code:
def location_selector(form, nested_level)
	promotion = @curent_user.try(:promotion) || @promotion
	user = @current_user || @user

	nested_locations = promotion.locations.nested(nested_level, user.locations(nested_level - 1))
	location_pairs = nested_locations.collect{|l| [l.name, l.id]}

	form.select(
				:id,
				location_pairs,
				include_blank: '-- Choose --'
				selected: user.locations(nested_level).try(:id),
				name: 'locations[][id]', 
				:class => "required"
	)
end
The nested_level poo poo is still hosed, it's probably stored wrong.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

It's in a partial.

It doesn't even work and this site has been live for a year :haw:

Is it wrong that I still cringe when I see HAML?

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost

Ithaqua posted:

Anyone who does something like that in any language should have the living poo poo beaten out of them.
There's a number of enterprise software products that let you embed in small snippets of code hooks (JSTL style normally) that have form fields in the form of text boxes rather than <textarea> style page entries. And as part of their "security" measures you're limited to something arbitrarily small like 2048 characters for your code input. When I worked with them I'd normally write code in an external text editor and pass it into a minification tool and get a character count before pasting it in.

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.
I managed a process that ran from a .bat file nightly and would shuffle some files around, print, and archive them. It's not complex at all.

I was able to transfer managing it to someone else, which also involved having them install all the necessary software on one of their machines.

After a couple days being told multiple times "it doesn't work" and finding out multiple times that the error is "x is not recognized as an internal or external command, operable program or batch file", followed by telling him to google the error, we finally got to the point where all required software was installed and added to the path. In addition, I had to teach him that instead of running the bat file each time, to just run one line at a time to troubleshoot any particular errors, plus to not run things that depend on previous commands to have been completed. This also included training on how to change directories from the command line, among other things.

The bat file also had comments as to what each line did. There was no mystery yet I'd be at his desk helping him, he'd pick a line and ask what it does, or say "this must do X". I'd ask him what the comment said it does.

This is a guy that was hired that had worked in a computer lab for a few years, had a associates in CS with an emphasis in programming, and also claimed to have no problem reading other people's code and taking it over when necessary.

I was questioning the lack of experience compared with what was told in the interview and I get back

quote:

Remember, my experience is writing the scripts and running them as a whole. I have never broken one down to run seperate parts of it.

I've also heard things about how unlike other people, he doesn't need to plan out anything when he programs or builds a database. He just needs to be told what the problem is and he'll build the solution.

Recently, he was having trouble with a query not working right. It was just so bad that I don't even want to imagine what sort of things he's been writing since he started. It's the fact that he's not asking questions and just assuming he knows how all the tables work that drives me crazy when I think about it.

It's the small things like this that just keep building up and stressing me out.

chemosh6969 fucked around with this message at 23:26 on Jul 12, 2012

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"

Bob Morales posted:

Is it wrong that I still cringe when I see HAML?

HAML is a solution to a problem that never existed. The hipster vibe given off on their website about how "poetic" it is is horrible, too. HTML with embedded templates is far more legible to me than any HAML I've seen.

I'm not big on Coffeescript for the same reason, despite the positive things I've heard about it. I don't find Javascript that difficult to express myself in. I haven't dived too far into the latest version of Rails yet but when I created a placeholder project and noticed that it had Coffeescript assets by default, it made me a little sad.

At least SASS adds some meaningful features like mixins, variables, and inheritance, so I don't mind that so much -- especially since I can compile the stylesheets to pure CSS before deploying.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

Flobbster posted:

HAML is a solution to a problem that never existed. The hipster vibe given off on their website about how "poetic" it is is horrible, too. HTML with embedded templates is far more legible to me than any HAML I've seen.

I'm not big on Coffeescript for the same reason, despite the positive things I've heard about it. I don't find Javascript that difficult to express myself in. I haven't dived too far into the latest version of Rails yet but when I created a placeholder project and noticed that it had Coffeescript assets by default, it made me a little sad.

At least SASS adds some meaningful features like mixins, variables, and inheritance, so I don't mind that so much -- especially since I can compile the stylesheets to pure CSS before deploying.

I use hamlpy for my Django templates, it basically compiles haml syntax to a django template.

As long as you break up the templates into reasonable chunks with includes and extends I find it much easier to read what's going on, especially with if else statements and the like. YMMV of course but I do like how I can reorganise html by just shifting the indentation.

It can still accept if else statements in the class and ID attributes as well, if you use the attribute syntax rather than the shorthand.

edit: I do find them waxing lyrical on their front page a little groan worthy though. Actually turned me off bothering with it for a while.

Maluco Marinero fucked around with this message at 23:52 on Jul 12, 2012

Opinion Haver
Apr 9, 2007

Flobbster posted:

HAML is a solution to a problem that never existed. The hipster vibe given off on their website about how "poetic" it is is horrible, too. HTML with embedded templates is far more legible to me than any HAML I've seen.

I'm not big on Coffeescript for the same reason, despite the positive things I've heard about it. I don't find Javascript that difficult to express myself in. I haven't dived too far into the latest version of Rails yet but when I created a placeholder project and noticed that it had Coffeescript assets by default, it made me a little sad.

At least SASS adds some meaningful features like mixins, variables, and inheritance, so I don't mind that so much -- especially since I can compile the stylesheets to pure CSS before deploying.

I don't really care about the bracelessness of Coffeescript or whatever but the list comprehensions and proper support for iterating over the keys of an Object that aren't the built-in properties are really useful.

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
I thought a lot of the point of HAML was mostly about making really drastic structural changes to HTML (re-indenting and pivoting about tables, for example) easier than with most templating languages. I could imagine using it for writing out some HTML shorthand for a quick layout in the early stages and then when I'm done iterating through different designs I'll use an actual templating language like I dunno JSTL or Jinja or whatever.

Flobbster posted:

I'm not big on Coffeescript for the same reason, despite the positive things I've heard about it. I don't find Javascript that difficult to express myself in. I haven't dived too far into the latest version of Rails yet but when I created a placeholder project and noticed that it had Coffeescript assets by default, it made me a little sad.
From what I've seen of Coffeescript, its primary use case is in helping write more OOP-like code using Javascript without getting lost in closure after closure. The current legacy codebase I'm in now could use some automated help in scope for sure and dojo's hitch and ExtJS's equivalents help. A lot of the helpers that can be done with underscore can cut down on the number of extra modules in the project.

Impotence
Nov 8, 2010
Lipstick Apathy
Same bitcoin site hacked againa, Bitcoinica apparently didn't want to change its passwords after being compromised top to bottom.

Oh, and they apparently store their own use passwords/API keys for other sites hardcoded inside the code

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug
HAML is just less typing than HTML for equivalent and well-formed results:
code:
<div id="toolbar" class="top-bar">
  <ul class="nav secondary-nav">
    <li>asdf</li>
  </ul>
</div>
code:
#toolbar.top-bar
  %ul.nav.secondary-nav
    %li asdf
There's just less code there, with all the benefits that entails: more fits on-screen, less to read, less repetition, less house-cleaning (indents are much simpler than closing tags), and it's guaranteed to produce well-formed HTML if it compiles.

CoffeeScript is the same thing: "->" is more succinct than "function", indents are more succinct than counting "}"s, and if your poo poo is so complicated you find yourself having trouble relating the compiled output to the CoffeeScript input, you should learn to program simpler stuff.

Look Around You
Jan 19, 2009

BonzoESC posted:

HAML is just less typing than HTML for equivalent and well-formed results:
code:
<div id="toolbar" class="top-bar">
  <ul class="nav secondary-nav">
    <li>asdf</li>
  </ul>
</div>

code:
#toolbar.top-bar
  %ul.nav.secondary-nav
    %li asdf

There's just less code there, with all the benefits that entails: more fits on-screen, less to read, less repetition, less house-cleaning (indents are much simpler than closing tags), and it's guaranteed to produce well-formed HTML if it compiles.

CoffeeScript is the same thing: "->" is more succinct than "function", indents are more succinct than counting "}"s, and if your poo poo is so complicated you find yourself having trouble relating the compiled output to the CoffeeScript input, you should learn to program simpler stuff.

Is there a good way to write recursive functions in coffeescript? There's no named functions in it so I guess you can use arguments.callee, or obviously a Y combinator would work, but those seem a little ugly-ish for common use.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.
Just name it?

code:
sup = ->
  console.log "sup"
  sup()

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

necrobobsledder posted:

From what I've seen of Coffeescript, its primary use case is in helping write more OOP-like code using Javascript without getting lost in closure after closure. .

I would argue that this is not necessarily a feature... At least not for someone who isn't a JavaScript expert. Forcing your brain to unlearn existing OO class-based systems then to really live and breathe prototypes+closures expands your understanding in the same way learning multiple spoken languages as a child does.

Then you can circle back around and learn to hate JavaScript all over again, like a parent who bent over backwards to give you everything in life, but was also horribly abusive. You love them but you also wish they would hurry up and die.

Look Around You
Jan 19, 2009

pokeyman posted:

Just name it?

code:

sup = ->
  console.log "sup"
  sup()

Oh, I was under the assumption that they were totally anonymous and that it wouldn't bind before that (similar to be behavior of let in scheme).

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Look Around You posted:

Oh, I was under the assumption that they were totally anonymous and that it wouldn't bind before that (similar to be behavior of let in scheme).

Nah, it's just JavaScript. Works identically.

JavaScript code:
var sup = function() {
  console.log("sup");
  sup();
};

Plorkyeran
Mar 22, 2007

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

Look Around You posted:

Oh, I was under the assumption that they were totally anonymous and that it wouldn't bind before that (similar to be behavior of let in scheme).
Javascript only has function-level scope, so variables are in scope before the point of definition:
JavaScript code:
var a = function() { return b(); }
var b = function() { return "b"; }
console.log(a());

Deus Rex
Mar 5, 2005

so if you're ever writing PHP and using in_array or array_search with an associative array that could possibly have a value of 0, don't let yourself think you're going crazy when you run into this wonderful horror:

php:
<?

$wtf = array("whatthechrist" => 0);

var_export($wtf);

echo "\n------\n";

var_export(in_array("baaalllllllssssssssssssssss", $wtf)); // prints TRUE
http://codepad.org/QTJmdRAH

the real answer, as always is, PHP's lovely equality operator ("arbitrary string" == 0 :waycool:)! You can get around it by passing TRUE as a third parameter to either of those functions, which forces a strict comparison, but this is a fine example of why you should always use strict comparisons in PHP. what a poo poo language!! :fuckoff:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Well if you're going to be mixing data types together in PHP you should pretty much be using the identity operator. I mean in general you should be using it anyways.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

quote:

bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )
But... in the situation shown above, we would have no reason to assume we need to set strict. I've never used strict with in_array(), yet I know that scenario could potentially appear in my code.

I guess my point is, maybe $strict should default to TRUE, not FALSE. Or maybe there should be a PHP setting where everything is treated as strict.

PHP.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Golbez posted:

But... in the situation shown above, we would have no reason to assume we need to set strict. I've never used strict with in_array(), yet I know that scenario could potentially appear in my code.

I guess my point is, maybe $strict should default to TRUE, not FALSE. Or maybe there should be a PHP setting where everything is treated as strict.

PHP.

I'm guessing its due to having to maintain backwards compatibility for older PHP scripts.

Golbez
Oct 9, 2002

1 2 3!
If you want to take a shot at me get in line, line
1 2 3!
Baby, I've had all my shots and I'm fine

Strong Sauce posted:

I'm guessing its due to having to maintain backwards compatibility for older PHP scripts.

That's a reason they can't change it now, not why it never worked properly in the first place. And, as shown earlier with that horrific number_format() bug, they obviously don't care about maintaining backwards compatibility if it means cleaning up something in their codebase.

Deus Rex
Mar 5, 2005

putting a setting in php.ini to force in_array and array_search etc. to use strict comparisons wouldn't break existing code, because you could just leave it off for legacy code.

Hammerite
Mar 9, 2007

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

Golbez posted:

That's a reason they can't change it now, not why it never worked properly in the first place. And, as shown earlier with that horrific number_format() bug, they obviously don't care about maintaining backwards compatibility if it means cleaning up something in their codebase.

I think they do care about backwards-compatibility as a general rule. The number_format() thing was just down to it being a poorly-managed project I think.

Look Around You
Jan 19, 2009

Hammerite posted:

I think they do care about backwards-compatibility as a general rule. The number_format() thing was just down to it being a poorly-managed project I think.

No, it was down to a change made to the parser that actually changed the return value of a function. Which is pretty absurd.

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Accidental backwards compatibility changes from code cleanups are okay, but intentional ones to make the stdlib less awful aren't.

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