|
CleaKO wrote: think it is just easier to read when you say say what you want it to equal.
If boolean = True
instead of just saying
If boolean
Funny.
For me its just the opposite: The superfluous = True imposes the nagging feel in me, I have missed something while reading the code.
But then, the whole VB code gives me a screaming fit anyway.
Failure is not an option - it's built right in.
|
|
|
|
|
jhwurmbach wrote: But then, the whole VB code gives me a screaming fit anyway.
I know the feeling.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
jhwurmbach wrote: But then, the whole VB code gives me a screaming fit anyway.
But you see such style in the C-family languages too, though it's probably less common.
Kevin
|
|
|
|
|
Yeah, it's just the opposite for me too. Especially if you name your boolean properties or methods correctly.
If UserIsInRole(user, role) Then
Just the name of the function implies that it returns a True/False value.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
CleaKO wrote: If boolean = True
But then you may have trouble when the code is ported to C, so you really need:
If True = boolean
--| "Every tool is a hammer." |--
|
|
|
|
|
It is a good idea to place the constant value to the left of the equality symbol in any language that supports them, to catch syntax errors.
It just feels so unnatural to type it that way.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
You might still have trouble in C, if you run up against code that uses other non-zero values for "true"...
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
|
If that's how you use booleans, you might as well just use an integer set to 1 or 0 or a string set to "Y" or "N" (or "True" or "False"). How about:
<br />
somethingIsWrong = (type <> "GOOD" AndAlso type <> "Cool")<br />
With a variable name that clearly expresses the condition represented by the boolean, the comparison to True or False becomes clearly redundant.
|
|
|
|
|
The reason for the first is that some people have a fixation about negative conditionals, such that they will try and avoid them at all costs - such as the cost you describe!
Kevin
|
|
|
|
|
boolean = True
but that's a boolean expression again, which could be true.. or false.
So to make absoultely clear you want b = true to be true (not false), you write
If (boolean = True) = True
lather, rinse, repeat
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers! We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP Linkify!|Fold With Us!
|
|
|
|
|
I prefer
If ( isFlag ) Then Continue Succinct.
----
It appears that everybody is under the impression that I approve of the documentation. You probably also blame Ken Burns for supporting slavery.
--Raymond Chen on MSDN
|
|
|
|
|
If there is a complicated method and I want to indicate that I did indeed accomodate both possibilities I will, ocassionaly, leave a blank if. However, I almost never check a boolean variable against a boolean and instead prefer :
<br />
if(isFlagSet){<br />
<br />
}<br />
else if(!isFlagSet){<br />
...<br />
}<br />
else{<br />
}<br />
Just kidding with the File not found!
File Not Found
|
|
|
|
|
|
The code below is part of an eventhandler
Very informative and easy to debug
The worse part is that there are quite a few of these constructions in the application at hand. Shouldn't there be a law against such 'programmers'?
.....
try
{
int startNummer = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
Hashtable ht = Logica.HaalEquipeIDBijStartnummer(editieID);
equipeID = (int) ht[startNummer];
if (!Logica.IsTijdControleIngevoerd(etappeID))
return;
}
catch
{
return;
}
....
Keep smiling,
Marco
|
|
|
|
|
It is in Dutch. I have no problem reading it, and I don't even speak the language (2 minutes at Babelfish will do it). Get a Dutch programmer to translate it for you. Or does program code always have to be in English?
|
|
|
|
|
Can you explain to me what is meant by the catch in this piece of code?
Regards,
Marco
|
|
|
|
|
Sure. It could do with somewhat more comment lines, but the governing logic is clear:
- do some lookups
- return immediately if something is wrong:
---- some data is not found when looking it up in "Logica"
---- an exception is thrown, for example in the conversion of text to int32 (hence the catch)
- proceed if all assumptions are valid
|
|
|
|
|
Aha! so ignore any exception, just return. That is indeed the way to do it. Silly me, what was i thinking?
Regards,
Marco
|
|
|
|
|
Really, what were you thinking. Will the end user report any mysterious issues before you manage to get a new and better job?
Besides, 'some day' we're going to integrate an error capture and/or logging methodology into this business critical high visibility application which re-engineers our business case to leverage best-practice synergies to pro actively actualize our bottom line but at this point we really don't know what features are required and we're REALLY in a hurry to get something done so for now, we'll just put the blocks in place and fill them in later.
Every application I support in this place is filled with this crap. Every programmer who spews this crap out rapidly is a hero (and soon off to bigger and better jobs)
|
|
|
|
|
JohnnySacks wrote: Besides, 'some day' we're going to integrate an error capture and/or logging methodology into this business critical high visibility application which re-engineers our business case to leverage best-practice synergies to pro actively actualize our bottom line but at this point we really don't know what features are required and we're REALLY in a hurry to get something done so for now, we'll just put the blocks in place and fill them in later.
This sounds so scarily like my manager..no wonder we've decided not to listen to him anymore
|
|
|
|
|
arc_10spd wrote: Or does program code always have to be in English?
If you ever want to start a lobby for making a law that states that all code should be in English, I'll make the buttons
|
|
|
|
|
There are about currently about 4,000 unique languages remaining in the world. English will overrun most of them within the next 100 years at the cost of an extraordinary and fascinating diversity in human culture and history stretching back for over 10,000 years (at least that is what some historical linguists claim they can reconstruct). I for one would find it a tragedy if Dutch were to go as well ("not so much a language as an organised method for clearing one's throat"). However, ErikDD, if you MUST have it in English, here is a guess:
....
try
{
int startNumber = Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
Hashtable ht = Logic.ObtainTeamIDAtStartnumber(editID);
teamID = (int) ht[Startnumber];
if (!Logic.IsTimeControlIntroduced(teamID)
return;
}
catch
{
return;
}
...
|
|
|
|
|
Sorry.
Probably should translate etappe as "stage":
...
if (!Logic.IsTimeControlIntroduced(stageID)
...
not
...
if (!Logic.IsTimeControlIntroduced((editID))
...
|
|
|
|
|
*grins* I happen to be one of the relatively few people who actually speak Dutch (aka a Dutchman) but I do appreciate the effort
As for Dutch disappearing, I wouldn't miss it, but I don't enjoy the prospect. It's just that I also believe in code mobility and reusability.
|
|
|
|
|
That would put a new spin on our local culture here outside Phoenix too; we just had our annual "Lost Dutchman Days" festival.
--| "Every tool is a hammer." |--
|
|
|
|