for(int i=0;i<10;i++)
84 Replies - 8658 Views - Last Post: 23 October 2012 - 07:36 AM
#31
Re: OPC (Other People's Code)
Posted 09 February 2009 - 09:10 PM
#32
Re: OPC (Other People's Code)
Posted 09 February 2009 - 09:16 PM
#33
Re: OPC (Other People's Code)
Posted 09 February 2009 - 09:40 PM
I don't see what's wrong with it. If other people hate it, that may explain some of my homework scores
#34
#35
Re: OPC (Other People's Code)
Posted 10 February 2009 - 01:47 AM
#36
Re: OPC (Other People's Code)
Posted 10 February 2009 - 01:55 AM
In some languges you have to do this though (in C before C99).
This post has been edited by LaFayette: 10 February 2009 - 01:57 AM
#37
Re: OPC (Other People's Code)
Posted 10 February 2009 - 01:56 AM
// Another reason is because in the event that I'm going to use the loop variable
// more than once, it prevents the compiler from generating the following instructions
// several times.
//
// sub esp, 4 ; Create space for local variable
//; do loop stuff here
// add esp, 4 ; Get rid of local variable
// Doing it this way means the variable is created once, and discarded once.
// Unless, however, the compiler is smart enough to catch something that normally
// would result in the aforementioned.
//
// I guess I'm stingy when it comes to CPU cycles;)
int index, len;
for (index = 0, len = someFunc(); index < len; index++)
{
doStuffHere();
}
for (index = 0, len = string("some BS").length(); index < len; index++)
{
doStuffHere();
andDoSomeMoreStuff();
}
This post has been edited by thepeoplescoder: 10 February 2009 - 02:02 AM
#38
Re: OPC (Other People's Code)
Posted 10 February 2009 - 03:19 AM
Quote
then you declare it outside.. Otherwise you dont!
And as far as local variables and stuff go, you don't allocate and discard memory for them in sequence.
#39
Re: OPC (Other People's Code)
Posted 10 February 2009 - 05:13 AM
KYA, on 9 Feb, 2009 - 10:40 PM, said:
Agreed. Strangely, I just recently on DIC recommended to someone the "declare and define" practice with variables. In "Effective Java", Bloch gives a pretty good justification for the practice under the item "minimize the scope of local variables". ( I've been hunting about, but can't find it offered as a sample chapter. )
In C, you should declare first and then assign all the values later. You pretty much have to, anyway. However, from C++ forward, and particularly in languages like Java, declaring a variable without an initial value is a poor practice. It's acceptable if scope forces it, like variable defined in constructors or assigned in a sub block. You should never leave a variable value hanging, even if you just have to assign it null.
So I'm afraid I have an opposite peeve to some.
#40
Re: OPC (Other People's Code)
Posted 10 February 2009 - 05:57 AM
#41
Re: OPC (Other People's Code)
Posted 10 February 2009 - 06:50 AM
body
{
background-color:#000000;
background-image:url(pic.jpg);
background-repeat:no-repeat;
}
instead of:
body {background: #000000 url(pic.jpg) no-repeat;}
Or:
$query="SELECT * FROM table"; $result=mysql_query($query); $row=mysql_fetch_array($query);
rather than:
$query=mysql_query("SELECT * FROM table");
$row=mysql_fetch_array($query);
I like code as condensed as possible and as clear as it can be within said condensation. Why add extra steps when you don't have to?
#42
Re: OPC (Other People's Code)
Posted 10 February 2009 - 07:17 AM
BenignDesign, on 10 Feb, 2009 - 01:50 PM, said:
body
{
background-color:#000000;
background-image:url(pic.jpg);
background-repeat:no-repeat;
}
instead of:
body {background: #000000 url(pic.jpg) no-repeat;}
This one has made me unnecessarily angry before. Also, people who feel they have to define things like padding and margin using four lines makes me want to tear their code from the internet. I accept that I may have issues
#43
Re: OPC (Other People's Code)
Posted 10 February 2009 - 09:32 AM
#44
Re: OPC (Other People's Code)
Posted 10 February 2009 - 10:01 AM
#45
Re: OPC (Other People's Code)
Posted 10 February 2009 - 12:16 PM
This post has been edited by bodom658: 10 February 2009 - 12:18 PM
|
|

New Topic/Question
Reply



MultiQuote
















|