[Seaside] How generate ID

Nevin Pratt nevin at bountifulbaby.com
Sun Dec 30 15:23:48 UTC 2007

John M McIntosh wrote:
> Assuming you want a unique value, and you don't care if it's in order 
> then you can just do
> UUID new
> -> e0090895-4a12-4ef6-82e0-9acefc76ff9c  -> asString36  ->  
> '9alvh9w807elbql3xdq6l05pc'
> that will be unique.
> buf if you must start at 1 and go to infinity then you need to bother 
> with
> Semaphore forMutualExclusion
> and do things like remember what the last number was...
> more code and options to get it wrong.

Thread safety might not matter.

For example, my site bountifulbaby.com uses the technique Tom suggests, 
via a class variable and a #newID class method, to generate product item 
numbers whenever we add a new product for sale on the website.

Adding a new product for sale is only done via the Administrator page.  
The risk of two different people here at Bountiful Baby both adding a 
new product to the website at the exact same time is virtually nil.

I would also venture a guess that if any other Seaside app wants a 
serially increasing ID like that, there is a pretty good chance it 
likewise would only be accessed from an Admin page, and the risk of two 
people doing it at the exact same time is likewise virtually nil.

Obviously there are exceptions, but Jakub might not need to worry about 
thread safety.

It just depends on what he is doing it for.


More information about the seaside mailing list