0xDEF
-
Anyone using 0xDEF as default value for int? (when you don't really care what value it is, e.g in test for some default value setter)
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe -
Anyone using 0xDEF as default value for int? (when you don't really care what value it is, e.g in test for some default value setter)
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfednh wrote:
Anyone using 0xDEF as default value for int?
Nope. Go wild.
Deja View - the feeling that you've seen this post before.
-
Anyone using 0xDEF as default value for int? (when you don't really care what value it is, e.g in test for some default value setter)
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne MetcalfeThat's um... stupid (unless 3567 somehow indicates something special as a default value to your program). If you're just trying to be clever with hex values, you're not going to accomplish anything more than pissing off real programmers that will be tasked with maintaining your freakish attempts at coding.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
That's um... stupid (unless 3567 somehow indicates something special as a default value to your program). If you're just trying to be clever with hex values, you're not going to accomplish anything more than pissing off real programmers that will be tasked with maintaining your freakish attempts at coding.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thanks. The scenario where I was thinking about this is following: Say I have method void GetSomethingFromConfig(ref int result); When writing unit test for this method, I want to make sure that for input that cannot be parsed the output value of result stay the same as its input value (which is some default value, it's value is irrelevant now). I don't want to use 0, because that happen to be default value of int, so the probability that bug in GetSomethingFromConfig will "reset" output value to 0 is way higher then to 3576. So what number to choose, 42,123,...? I guess I could slam the numeric part of keyboad and add comment saying "this is random default value for test purposes", but it looks like overkill to me. Without the comment, maintainance programmer can wonder why 42, why 123 etc. Yes I am trying to be clever with hex in this case; 0xDEF(ault) value by convention. Yes, it is somewhat cryptic. If I didn't realise it is I wouldn't post here :) I want to point out that I am not using this value in production code, (certailny not because it's looking cool) but I think about using it in tests.
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe -
Thanks. The scenario where I was thinking about this is following: Say I have method void GetSomethingFromConfig(ref int result); When writing unit test for this method, I want to make sure that for input that cannot be parsed the output value of result stay the same as its input value (which is some default value, it's value is irrelevant now). I don't want to use 0, because that happen to be default value of int, so the probability that bug in GetSomethingFromConfig will "reset" output value to 0 is way higher then to 3576. So what number to choose, 42,123,...? I guess I could slam the numeric part of keyboad and add comment saying "this is random default value for test purposes", but it looks like overkill to me. Without the comment, maintainance programmer can wonder why 42, why 123 etc. Yes I am trying to be clever with hex in this case; 0xDEF(ault) value by convention. Yes, it is somewhat cryptic. If I didn't realise it is I wouldn't post here :) I want to point out that I am not using this value in production code, (certailny not because it's looking cool) but I think about using it in tests.
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne MetcalfeIf you cannot parse the config file, then you should probably throw an exception in your method. I don't think using a special return value in debug only code for unit tests is the correct way to do it. Mainly because your Debug and Release code now have different behavior when the config value cannot be parsed. But also because it's not a standard practice.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
-
If you cannot parse the config file, then you should probably throw an exception in your method. I don't think using a special return value in debug only code for unit tests is the correct way to do it. Mainly because your Debug and Release code now have different behavior when the config value cannot be parsed. But also because it's not a standard practice.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
TJoe wrote:
If you cannot parse the config file, then you should probably throw an exception in your method.
I'd agree if it was incorrect data. It's missing data. For configuration file, if you can have sensible defaults, why would you require user of your config to put ALL attributes there? Btw there indeed is method that checks for attributes that MUST be set, that throws config. exception. More later... got to go.
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe -
TJoe wrote:
If you cannot parse the config file, then you should probably throw an exception in your method.
I'd agree if it was incorrect data. It's missing data. For configuration file, if you can have sensible defaults, why would you require user of your config to put ALL attributes there? Btw there indeed is method that checks for attributes that MUST be set, that throws config. exception. More later... got to go.
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne MetcalfeIf you are using 0xDEF as the default value in your unit test, then it's fine. So you pass in 0xDEF into your Get method and expect 0xDEF back out (for missing config entries). Originally, it sound to me like the Get method was going to return 0xDEF for a default if the config entry was missing and it was a debug build.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
-
If you are using 0xDEF as the default value in your unit test, then it's fine. So you pass in 0xDEF into your Get method and expect 0xDEF back out (for missing config entries). Originally, it sound to me like the Get method was going to return 0xDEF for a default if the config entry was missing and it was a debug build.
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com
TJoe wrote:
So you pass in 0xDEF into your Get method and expect 0xDEF back out (for missing config entries).
Yep! Ow wow, I am going to read again what I originally wrote :-O
[My Blog]
"Visual studio desperately needs some performance improvements. It is sometimes almost as slow as eclipse." - Rüdiger Klaehn
"Real men use mspaint for writing code and notepad for designing graphics." - Anna-Jayne Metcalfe -
dnh wrote:
Anyone using 0xDEF as default value for int?
Nope. Go wild.
Deja View - the feeling that you've seen this post before.
I strongly feel this thread deserves an award of some kind.
Mark Churchill Director Dunn & Churchill