|
Duncan Edwards Jones wrote:
Private Function gGetMonthByCode(ByVal code As String) As Integer
Select Case code
Case "JUL"
Return 7
Case "SEP"
Return 9
Case Else
Return -1
End Select
End Function Fixed
I'll ignore the fact that it's VB as I like VB (not this particular piece though)
|
|
|
|
|
Duncan Edwards Jones wrote: I'm guessing there are two unit tests for this No, three: don't forget to test for FILE_NOT_FOUND.
|
|
|
|
|
Maybe the code is only in "alpha state" for now.
I miss a comment like:
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Wow. Just two? I can think of at least three more.
|
|
|
|
|
Did you intend to reply to KarstenK or the OP?
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Should have been the OP. Oops.
|
|
|
|
|
It happens.
One site I was on had a developer add a "feature" that caused forum replies to be attached to a random post. He said that it was supposed to "liven up the forums". I don't think he works for that site anymore.
I'd post a link, but this was several years ago, and I can't remember what site it was.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Brisingr Aerowing wrote: One site I was on had a developer add a "feature" that caused forum replies to be attached to a random post. He said that it was supposed to "liven up the forums". I don't think he works for that site anymore.
Uhhhh.... yeah. How was that supposed to "liven up the forms"? The only way we're ever going to know that is to find out what drugs he was on and get some.
|
|
|
|
|
Makes sense if the only valid input is JUL or SEP
|
|
|
|
|
Porting some C code to one microcontroller to another I found this:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0))
#else
)
#endif
This work is unhealthy
|
|
|
|
|
How else would you do it? Other than, of course, eliminating the #else by putting the right-parenthesis outside the #if .
|
|
|
|
|
leaving V_OK = 0 whenever you don't define SEANSAR maybe.
If I could I would put all the code here for you to see what I have to strugle every day. There are violations to every single "good programing practice", starting for the encapsulation, with a lot of variables and defines mixed in separated and "isolated" modules.
|
|
|
|
|
But this way eliminates a test when you don't have SENSAR; ergo it's FFFAAASSSTTTEEERRR...
Why test something that's always true?
|
|
|
|
|
Maybe, but this things makes the code unclear and dificults the scalability.
Anyway you are right in the fact that it is faster, innecesarily and almost insignificaly faster
|
|
|
|
|
But when working with microcontrollers performance and memory management are important, aren't they?
And many small things might lead to a noticeable gain in that.
|
|
|
|
|
I was going to say that. Sometime had to do weird trick, that looked really ugly, just to save program memory (PIC16F84)
I do not fear of failure. I fear of giving up out of frustration.
|
|
|
|
|
You're absolutely right. You ought to write it more concise:
if((error == 0)
#ifdef SENSAR
|| (V_OK == 0)
#endif
) Much cleaner now!
|
|
|
|
|
I would have write it that way.
#ifdef SENSAR
if((error == 0) || (V_OK == 0))
#else
if((error == 0))
#endif
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
I have to agree, it is easier to read that way.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
|
still has double parentheses on the 2nd case. That will slow the compiler massively
|
|
|
|
|
I didn't try to optimise, just to make it easier to read.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Such messie code is dangerous as gasoline. One error and everything blows up.
I wont accept such stuff from my collegues.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Doing some code clean up and found this gem
if ( flag && test_fn() )
{
if ( test_fn() )
{
}
}
test_fn() isn't particularly expensive ... but really?
|
|
|
|
|
So presumably test_fn looks something like this:
private int _testCallCount = 0;
public bool test_fn()
{
_testCallCount++;
return (_testCallCount & 1) == 0;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
At least it is not
if ( ((flag == true) && (test_fn() == true)) == true)
{
if ( test_fn()== true )
{
}
}
modified 19-Jan-21 21:04pm.
|
|
|
|