|
|
So you think (compiler) optimization is unpleasant?
|
|
|
|
|
i think allowing anonymous variables outside the context of a function call is unpleasant.
|
|
|
|
|
I'm not sure what you mean by anonymous variables. It is quite normal in C to have expressions yield a value which is ignored. Even "intvar=5" is an expression which yields the value five. It is also quite common to have functions return a value which is ignored. To be sure, there are places where return values shouldn't be ignored but are anyway; on the other hand, it would be annoying if one always had to explicitly use the return value of something like memcpy() instead of just letting it vanish into the ether.
|
|
|
|
|
supercat9 wrote: I'm not sure what you mean by anonymous variables.
anonymous = "without a name".
supercat9 wrote: It is quite normal in C to have expressions yield a value which is ignored.
right. but that has nothing to do with the code i posted above. this isn't about return values.
in C++ you can do this:
CPoint(5,15);
that will construct a CPoint object and immediately destruct it because the variable is anonymous, it has no name, and it isn't used anywhere.
you can also do this:
MyFunc(CPoint(5,15));
this will create a CPoint and pass it to MyFunc.
the latter case us useful - and it's very common to do this when you need to re-package some data that you already into the types that the function expects.
but the former case is much less useful. if the c'tor and d'tor have side-effects, you could possibly use that to take advantage of those side-effects. but it's very non-intuitive. you would be better off moving those side effects to a function that you could call explicitly.
|
|
|
|
|
this will create a CPoint and pass it to MyFunc.
A constructor is essentially a function call. The function returns a value, which may be used like any other rvalue. The expression "somevariable = CPoint(5,15)" has a value which would typically be ignored, but could be used as part of a larger expression. The compiler doesn't particularly care whether or not it makes sense for the result of a particular expression to be ignored; while one typically ignore the value of an assignment expression, and would not typically ignore the value of a constructor, there are situations where one might very reasonably want to do the opposite of the usual case. One may, for example, wish to follow a 'next' pointer and check whether it points anywhere, or force the early creation of a singleton object one is not immediately interested in using.
|
|
|
|
|
i'm not sure why you refuse to acknowledge my point.
supercat9 wrote: The compiler doesn't particularly care whether or not it makes sense for the result of a particular expression to be ignored
i'm not complaining about what the compiler does. i'm complaining about the fact that the language allows such a thing to happen.
it makes no sense at all to construct an anonymous object outside of the context of a function call.
this makes sense:
CString t1 = CString ("sdfs");
this also makes sense:
MyFunc(CString ("sdfs"));
this makes no sense:
CString ("sdfs");
|
|
|
|
|
Chris Losinger wrote: i'm not sure why you refuse to acknowledge my point.
I am.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
Or, "How not to do your release notes.":
str3 = str3 + "<tr><td align='center'><b> Version 2.1.101 • 15 Sep 2007 </b></td></tr>" +
"<tr><td> </td></tr>" +
"<tr><td> </td>• Resolved script error on Reports Viewed List Report</tr>" +
"<tr><td> </td>• Resolved error when adding level using MSSQL</tr>" +
... [snip]
"<tr><td> Corrected Directory Listing query to display Extension Number of Parent Extension </td></tr>" +
"<tr><td> </td></tr>"; 730 lines have been removed from the string literal to protect everyone, not just the innocent.
You really gotta try harder to keep up with everyone that's not on the short bus with you.
- John Simmons / outlaw programmer.
|
|
|
|
|
Wow... just wow.
As me and my brother debate about regularly, at what point would a 'normal' person stop, take a step back, and say "really... wtf am i doing?". And what should we do with the non-normal people that either keep going for a REEEEEAAAALLLLYY long time, or worse yet, never hit that mark?
From both our experience, it would appear to be - make them CTO.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
So not only did he use over 700 unnecessary string concatenations, but he couldn't even put the text INSIDE the table cells?
I must say I'm impressed... It takes real talent to make a coding horror that spans two languages! (Three, if you count English -- Extension Number of Parent Extension? Is that from the Department of Redundancy Department?)
|
|
|
|
|
That's highly inefficient too. This is much more efficient:
str3 = "<tr><td align='center'><b> Version 2.1.101 • 15 Sep 2007 </b></td></tr>"
"<tr><td> </td></tr>"
...
"<tr><td> </td></tr>";
That way, the compiler will be able to do the string joins at compile time, rather than at runtime using the overloaded + operator. I'm assuming this is C++ and not C#. The initial str + would not have been needed in C#...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
It's decompiled C#.
You really gotta try harder to keep up with everyone that's not on the short bus with you.
- John Simmons / outlaw programmer.
|
|
|
|
|
Whoa.. It didn't even optimize the literals when it was compiled? Did someone forget to turn on the optimizer?
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
I found this function in the service I'm having to debug. I've omitted a few hundred lines of the code so that you may more clearly see the control flow.
void ProcessMessage()
{
if ( )
{
}
if ( )
{
}
if ( )
{
}
if ( )
{
}
while ( )
{
if ( )
{
continue;
}
if ( )
{
continue;
}
if ( )
{
continue;
}
if ( && )
{
if ( || )
{
if ( )
{
}
else
{
}
continue;
}
}
if ( )
{
continue;
}
for ( ; ; )
{
if ( )
{
}
if ( )
{
if ( )
{
}
continue;
}
if ( )
{
if ( )
{
}
continue;
}
if ( )
{
if ( )
{
}
else
{
}
if ( || || ( && ))
{
if ( )
{
}
}
else
{
if ( )
{
}
}
continue;
}
if ( )
{
for ( ; ; )
{
if ( )
{
continue;
}
if ( )
{
if ( )
{
}
else
{
}
if ( )
{
}
break;
}
else if ( )
{
if ( || )
{
if ( )
{
if ( )
{
}
}
}
if ( )
{
}
else
{
}
continue;
}
else
{
if ( )
{
}
break;
}
}
}
else
{
if ( )
{
}
}
if ( )
{
if ( )
{
}
}
else
{
for ( ; ; )
{
}
}
if ( || || )
{
if ( )
{
}
else if ( )
{
}
else
{
}
if ( )
{
}
else
{
if ( )
{
}
else
{
}
if ( || ( && ))
{
if ( )
{
if ( )
{
}
else
{
}
}
}
else
{
if ( )
{
if ( )
{
}
else
{
}
}
}
}
}
}
for ( ; ; )
{
if ( )
{
}
}
if ( )
{
if ( )
{
}
if ( )
{
if ( )
{
}
}
else
{
if ( )
{
}
}
}
else
{
}
}
}
|
|
|
|
|
add a couple of gotos and it'll be perfect
|
|
|
|
|
(In Homers voice)[sobber][drool]Mmmm! Modular![/drool][/slobber]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Holy Cow Im suprised the debugger didnt have a stack overflow when it saw this!
|
|
|
|
|
I'm more surprised that the debugger didn't miraculously become intelligent and decided to commit sumicide
GSoC 2009 student for SMW!
---
My little forums: http://code.bn2vs.com
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
That looks strangely familiar, did you delete 4 long case statements and about 10 foreach enumerator loops?
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
OK, what did you replace it with?
|
|
|
|
|
CTRL+A, DELETE. Then start it afresh. That would be a safer start than a buggy restart into the crazy maze.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
Right, so what does it look like now?
|
|
|
|
|
Probably nothing. I'm assuming he's doing maintenance code of something he didn't write (he wouldn't be posting here if he had!). Since it's maintenance, most people are reluctant to rewrite code. Especially if the code looks like this. God knows how the rest of the code looks like...
--
Kein Mitleid Für Die Mehrheit
|
|
|
|
|
I did eventually decide to move the body of each loop into its own function. Still uglier than I'd like it to be, but yes, I was reluctant to rewrite it, especially when the problem I was trying to fix turned out to be somewhere else.
|
|
|
|