|
Bernhard Hiller wrote: it returns a *special* list for Guid.Empty()!
It's expected to, but does it?
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
IIRC guid's are value not reference types so they can't be empty. Doesn't it have hasValue() method or some such?
|
|
|
|
|
They can't be null, but they can be empty, which is the guid equivalent of zero.
http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^]
There's no HasValue property or method; you just need to test whether it's equal to Guid.Empty .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: you just need to test whether it's equal to Guid.Empty
Except for that you probably don't actually need to.
Edit:
I'm also suspicious as to whether or not they're actually using System.Guid . The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.
You'll never get very far if all you do is follow instructions.
modified 27-Jun-14 10:41am.
|
|
|
|
|
Well, you do if you want to know whether or not it's empty.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Except you probably don't actually need to.
You'll never get very far if all you do is follow instructions.
|
|
|
|
|
Google for 'Index Of' instead of 'IndexOf'.
Those are some strange images in the results. (click) NSFW!!!
What the ____?
|
|
|
|
|
I am not sure how to handle that Exception.
Simon Lee Shugar (Software Developer)
www.simonshugar.co.uk
"If something goes by a false name, would it mean that thing is fake? False by nature?" By Gilbert Durandil
|
|
|
|
|
And if you Google 'Parent Directory' you get a different set of similar pictures.
.
|
|
|
|
|
Looks like "parental control" failed in those cases.
|
|
|
|
|
No. It means "get me the contents of the directory meant only for parents"
|
|
|
|
|
Someone's left "directory browsing" turned on for their - ahem - "gentlemen's special-interest" site?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If only I had know what NSFW meant before I tried this... thanks for that
|
|
|
|
|
Newb!
You could have just typed "define NSFW" into Google and found out!
|
|
|
|
|
Dave Kreskowiak wrote: You could have just typed "define NSFW" into Google and found out!
I did... afterwards. During the first read I didn't think much of it
|
|
|
|
|
Well, sounds like you have gotten an education in more ways than one
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
|
Means that 99.9% of all the servers on the internet have porn
|
|
|
|
|
I was in a training course last week where the below code was used as part of an example. It was described as a method that would generate a unique ID and add the specified prefix to it.
public static String generateId(String prefix)
{
int randomNumber = new Random().nextInt();
String id = Integer.toString(randomNumber);
if(id.startsWith("-"))
{
id = id.replace('-', '3');
id = prefix + id;
}
return id;
}
Apart from the flaws that I'm sure you'll spot, I should point out that this was in the context of server-side code that forms part of a workflow. So depending on how often the workflow executes, it could be likely that multiple instances of the workflow would execute at the same time and generate the same "unique" ID.
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
BotCar wrote: ... multiple instances of the workflow would execute at the same time and generate the same "unique" ID. It's worse than that. Many implementations of Random() use a fixed seed by default, so the first value returned is effectively constant.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
That's interesting. I did not realize that.
Do you mean that some languages' implementations of pseudorandom number generators uses fixed seeds, or that some implementations of the Java Virtual Machine uses fixed seeds by default?
What is this talk of release? I do not release software. My software escapes leaving a bloody trail of designers and quality assurance people in its wake.
|
|
|
|
|
Fortunately .NET does it with changing seed...
public Random() : this(Environment.TickCount)
{
}
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
Yep. I'm not sure how fortunate that is, though, because it means you don't trip over this problem until your server is running at high load and you instantiate two requests at the same time. That's really really hard to replicate in a test environment.
|
|
|
|
|
This does not generate UNIQUE ids, only RANDOM ids. There is nothing preventing the generation of an id that has been previously generated.
If you want unique ids, use Guids.
String id = Guid.NewGuid().ToString();
|
|
|
|
|
So I have been working on a replicating database.
Trigger on one of the tables being replicated, used to populate the Data Warehouse.
So, trigger writes record to 'Ids that need to be updated in the DW' table and calls SP that reads through that table for all unprocessed records, and processes them.
Because some related data may not (yet) have been replicated, this SP can legitimately fail to update the DW, and so shouldn't update the 'Ids that need to be updated in the DW' table to set it as processed.
I"d been having a few problems with various bits and bobs, and had created a table, MaxxxsTemporaryTable, just used for logging stuff.
So here was my code
...
Insert into DW.SomeTable
Select col, othercol, morecols
From ReplicatedDatabaseTable join AllSortsOfOtherTables
Insert into MaxxxsTemporaryTable Select @Id, @OtherId, @@ROWCOUNT
IF @@RowCount > 0
BEGIN
Update 'Ids that need to be updated in the DW' table
Set IsProcessed = 1
Where Id = @Id
END
But, for some reason, the IsProcessed flag was always being set, even though I knew it was zero, because that was what was written in my temp table!!
I had to post about it to bluff my shame!
PooperPig - Coming Soon
|
|
|
|