Henrik Lundberg (2) [Avatar] Offline
#1
Hello Enrico,

In listing 11.11, which list the class Orders, you use the operator '+' to sum the number of affected rows in the DB queries.

Is the order of execution guaranteed?
If not, foreign key constraints should reveal this as a bug.
If they are, wouldn't it at least improve readability to be explicit about the order of execution?

Thanks for a great book!

Regards
/Henrik
Enrico Buonanno (69) [Avatar] Offline
#2

> Is the order of execution guaranteed?

yes, see https://msdn.microsoft.com/en-us/library/Aa691322

> If they are, wouldn't it at least improve readability to be explicit about the order of execution?

but I am being explicit! smilie

Seriously, "readability" and "explicit" are somewhat subjective properties.
It's true that I'm using '+' in a somewhat unconventional way. But in this case I think the readability is good: we have 4 things that happen in sequence, and they're expressed in 4 lines of code. Also keep in mind that this is an example in a book (must be concise); in real code you may prefer to extract a method, or something.
Henrik Lundberg (2) [Avatar] Offline
#3
The order of execution is obvious if you have "explicit" knowledge of the guaranteed order of evaluation of operands. Without reading the C# specification I wouldn't take for granted the order of evaluation. That's why the use of '+' to chain executions bothered me.
Now that I know about the guaranteed order I agree that the use of '+' is ok. That is, until I recklessly use it in a language without said guarantee. smilie

Regards,
/Henrik