Never Ever...

  • Thread starter Thread starter xlar54
  • Start date Start date
Agree. Some wise words:

- A protocol design is not complete when there is nothing left to add, it is
complete when there is nothing left to remove.

- Any one can make something complicated, what is hard is to make it simple.

--
William Stacey [C# MVP]

| Remeber Creative Writing 101 in college? I'm sure your instructor told
you
| to write your story and then go back and cut it to about 25% of the words
you
| started with.
|
| The same applies to code though the percentages get better, just as in
| writing, when we've learned by cutting out code so much that we write less
| code that we will just have to remove later.
|
| Dale
| --
| Dale Preston
| MCAD C#
| MCSE, MCDBA
|
|
| "William Stacey [C# MVP]" wrote:
|
| > :-) Good one. I have felt this pain recently. Another reason to just
do a
| > very thin skeleton first and get basic things working to test your
design
| > and shake out many things you did not think about - resist random stream
of
| > thought and the temptation to add more function then minimal (surely we
| > never do that ;). The hard problems (e.g. concurrency, atomic, etc) are
| > much harder to see and debug with all the junk in the way. When it
feels
| > good, then add all those nice overloads and properties and keep unit
testing
| > along the way. Don't push a bad design and think you can "fix" it with
more
| > code.
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
| > --
| > William Stacey [C# MVP]
| >
| > | > | Hi Bruce,
| > |
| > | > The approach is the usual
| > | > one: create the best design you can, use the most appropriate data
| > | > structures you can, then run your program and find the trouble
spots,
| > | > and optimize those.
| > |
| > | And I'd just like to add that it's not unlikely you'll have to ditch
some,
| > or even most, of the
| > | design and start from scratch. When designing high-performance
systems
| > it's difficult to account
| > | for everything without prototyping first and running some tests.
| > |
| > | --
| > | Dave Sexton
| > |
| > | | > | >
| > | > xlar54 wrote:
| > | >> I've been going through the newsgroup, picking up best practices
and
| > | >> things not to do, as I think it helps to make a good programmer a
very
| > | >> good one. But rather than fishing, I figure that there are many
out
| > | >> there who are tired of fixing someone else's poorly written code as
it
| > | >> relates to best practices, architecture, security and such. So to
the
| > | >> group, if you had to post a list of "never ever do this..." or
"always
| > | >> do this..." what would that include? We all know there's many ways
to
| > | >> do something, but some ways are clearly not good solutions. My
| > | >> expectations here is that I will learn quite a bit as will everyone
| > | >> else. Thanks for your replies.
| > | >
| > | > Number one on my list of foolish things to do in any language is "a
| > | > priori" micro-optimization. By that I mean spending hours (or even
| > | > minutes) tweaking your code to "improve its speed" before you've
| > | > determined that it's slow (and what, exactly, is slow) and needs
some
| > | > help. Even then, the solution is usually at a higher level: in the
| > | > design, in the choice of data structures or things like that.
| > | >
| > | > Of course, it's perfectly legitimate to prefer some constructs over
| > | > others if experience has taught you that they're more efficient.
| > | >
| > | > As well, there are areas of computing, and types of problems, that
| > | > require screaming tight code. Even in these areas, however, it's a
| > | > fool's game to optimize every line of code. The approach is the
usual
| > | > one: create the best design you can, use the most appropriate data
| > | > structures you can, then run your program and find the trouble
spots,
| > | > and optimize those.
| > | >
| > | > So many people post in this newsgroup, asking whether classes or
| > | > structs are "more efficient," or stressing over the cost of boxing,
| > | > when in fact they haven't started writing their app yet. (The recent
| > | > discussion on boxing overhead excepted: the OP already had a working
| > | > app in another language and had a specific question.) So many
newbies
| > | > think that the way to write good code is to torture and twist the
| > | > language to "make it fast" while at the same time they create
painfully
| > | > bad designs that introduce massive overhead that code tweaking can't
| > | > begin to address.
| > | >
| > | > The dumbest "optimization" I've ever seen was this (in C)... I quote
it
| > | > complete with comment:
| > | >
| > | > // Unwind loop to save clock cycles incrementing loop counter
| > | > int a[10];
| > | > a[0] = 1000;
| > | > a[1] = 1000;
| > | > ...
| > | > a[7] = 1000;
| > | > a[8] = 1000;
| > | > a[9] = 1000;
| > | >
| > | > Not only was this in the initialization phase of the program (so it
| > | > would occur exactly once per program run) but the rest of the
program
| > | > then built a SQL query and headed off to a database to pull in a few
| > | > thousand rows of data. This guy shaved a few microseconds off a
program
| > | > that ran for five minutes.
| > | >
| > |
| > |
| >
| >
| >
 
Hi Dale,
Remeber Creative Writing 101 in college?

No.

Good "conditioning" analogy though :)

--
Dave Sexton

Dale said:
Remeber Creative Writing 101 in college? I'm sure your instructor told you
to write your story and then go back and cut it to about 25% of the words you
started with.

The same applies to code though the percentages get better, just as in
writing, when we've learned by cutting out code so much that we write less
code that we will just have to remove later.

Dale
--
Dale Preston
MCAD C#
MCSE, MCDBA


William Stacey said:
:-) Good one. I have felt this pain recently. Another reason to just do a
very thin skeleton first and get basic things working to test your design
and shake out many things you did not think about - resist random stream of
thought and the temptation to add more function then minimal (surely we
never do that ;). The hard problems (e.g. concurrency, atomic, etc) are
much harder to see and debug with all the junk in the way. When it feels
good, then add all those nice overloads and properties and keep unit testing
along the way. Don't push a bad design and think you can "fix" it with more
code.
MS had to do this with Vista. I think over million lines of code went in
the basket. Hindsight says that was a great desision as they ended up with
a better product.
--
William Stacey [C# MVP]

| Hi Bruce,
|
| > The approach is the usual
| > one: create the best design you can, use the most appropriate data
| > structures you can, then run your program and find the trouble spots,
| > and optimize those.
|
| And I'd just like to add that it's not unlikely you'll have to ditch some,
or even most, of the
| design and start from scratch. When designing high-performance systems
it's difficult to account
| for everything without prototyping first and running some tests.
|
| --
| Dave Sexton
|
| | >
| > xlar54 wrote:
| >> I've been going through the newsgroup, picking up best practices and
| >> things not to do, as I think it helps to make a good programmer a very
| >> good one. But rather than fishing, I figure that there are many out
| >> there who are tired of fixing someone else's poorly written code as it
| >> relates to best practices, architecture, security and such. So to the
| >> group, if you had to post a list of "never ever do this..." or "always
| >> do this..." what would that include? We all know there's many ways to
| >> do something, but some ways are clearly not good solutions. My
| >> expectations here is that I will learn quite a bit as will everyone
| >> else. Thanks for your replies.
| >
| > Number one on my list of foolish things to do in any language is "a
| > priori" micro-optimization. By that I mean spending hours (or even
| > minutes) tweaking your code to "improve its speed" before you've
| > determined that it's slow (and what, exactly, is slow) and needs some
| > help. Even then, the solution is usually at a higher level: in the
| > design, in the choice of data structures or things like that.
| >
| > Of course, it's perfectly legitimate to prefer some constructs over
| > others if experience has taught you that they're more efficient.
| >
| > As well, there are areas of computing, and types of problems, that
| > require screaming tight code. Even in these areas, however, it's a
| > fool's game to optimize every line of code. The approach is the usual
| > one: create the best design you can, use the most appropriate data
| > structures you can, then run your program and find the trouble spots,
| > and optimize those.
| >
| > So many people post in this newsgroup, asking whether classes or
| > structs are "more efficient," or stressing over the cost of boxing,
| > when in fact they haven't started writing their app yet. (The recent
| > discussion on boxing overhead excepted: the OP already had a working
| > app in another language and had a specific question.) So many newbies
| > think that the way to write good code is to torture and twist the
| > language to "make it fast" while at the same time they create painfully
| > bad designs that introduce massive overhead that code tweaking can't
| > begin to address.
| >
| > The dumbest "optimization" I've ever seen was this (in C)... I quote it
| > complete with comment:
| >
| > // Unwind loop to save clock cycles incrementing loop counter
| > int a[10];
| > a[0] = 1000;
| > a[1] = 1000;
| > ...
| > a[7] = 1000;
| > a[8] = 1000;
| > a[9] = 1000;
| >
| > Not only was this in the initialization phase of the program (so it
| > would occur exactly once per program run) but the rest of the program
| > then built a SQL query and headed off to a database to pull in a few
| > thousand rows of data. This guy shaved a few microseconds off a program
| > that ran for five minutes.
| >
|
|
 
Hi Dave,
check-in cut off time is 7PM, that is the time when the build guys kick
off a build, the build (as long as there are no build breaks) are available
around lunch time the next day :-)

Mark.
--
http://www.markdawson.org


Dave Sexton said:
Hi William,

But then again, I'm not sure if they actually started from scratch at 50M. They may have dumped 1M
and ended up with 50M :)

For nightly builds do they start the day before? ;)

--
Dave Sexton

William Stacey said:
Your probably closer. They still build on an IBM mainframe? I think I
remember they used to do that with NT.

--
William Stacey [C# MVP]

| Hi William,
|
| <snip>
|
| > Don't push a bad design and think you can "fix" it with more
| > code.
|
| Great advice :)
|
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
|
| I read in a blog 50M lines in Vista and 24 hour builds. That's insane :|
|
| --
| Dave Sexton
|
|
 
Bruce Wood wrote:
....
...just be aware that some programmers (including yours truly) do the
two-step method because in VS2003 it's the only way you can see what
the result will be in the debugger. I believe that VS2005 allows you to
see function results at the return statement, but VS2003 definitely
doesn't.

If you open Register window (it is under Debug/Windows), you will
see the return value in EAX register.
 
Hi Andy,

Yes, thank you. I forgot about that - Bruce Wood already pointed that out to me.

--
Dave Sexton

Andy said:
Dave,

The JIT compiler also does some optimization at runtime.

Andy

Dave said:
Hi Cor,

What two optimizing phases do you mean?

I tested this in the Debug configuration without optimization checked in the properties window
for
my VS 2005 project, and in Release mode with optimization checked.

Neither test optimized out the code.

And I agree that code is too verbose for such simple logic.

--
Dave Sexton

Cor Ligthert said:
Dave,

As far as I know, there are two optimizing phases. However, I hate those who set a boolean in a
property with only that, you become crazy of that while debugging.

Just my idea,

Cor





"Dave Sexton" <dave@jwa[remove.this]online.com> schreef in bericht
Hi Stephany,

You could compile both and have a look at the IL, if you are interested.

It's not optimized out.

--
Dave Sexton

It may well do.

You could compile both and have a look at the IL, if you are interested.

The next point is a very good one.

The amount of machine resource available tends to make a bit lazy, because we don't really
have
to worry about such things these days. It's a far cry from the days when we had to code, (in
COBOL), an ALTERED GOTO instaed of a PERFORM to save 8 bytes of core memory.



if (someBooleanCondition)
{
myBool = true;
}
else
{
myBool = false;
}

is bad as compared to:

myBool = someBooleanCondition;

In general I agree, however, both have their uses.

I would see this and immediately think - why doesn't the compiler see
this as a perfect opportunity to optimize? Assuming there is no other
activity within the braces, it _appears_ very reasonable for the
compiler to internally optimize this to:

myBool = someBooleanCondition;

Which does raise the point, when we talk about performance and
optimizations, what do we know about the compiler itself and its
ability to optimize code like the above.
 
Dave said:
Hi Bruce,


How?

That would be great, but it doesn't seem to work for me.

If I remember correctly, it is in Autos window, it has a special icon
which looks like an arrow on the Enter key.
 
Hi Mark,

Do they build the components serially, concurrently or mixed?

--
Dave Sexton

Mark R. Dawson said:
Hi Dave,
check-in cut off time is 7PM, that is the time when the build guys kick
off a build, the build (as long as there are no build breaks) are available
around lunch time the next day :-)

Mark.
--
http://www.markdawson.org


Dave Sexton said:
Hi William,

But then again, I'm not sure if they actually started from scratch at 50M. They may have dumped
1M
and ended up with 50M :)

For nightly builds do they start the day before? ;)

--
Dave Sexton

William Stacey said:
Your probably closer. They still build on an IBM mainframe? I think I
remember they used to do that with NT.

--
William Stacey [C# MVP]

| Hi William,
|
| <snip>
|
| > Don't push a bad design and think you can "fix" it with more
| > code.
|
| Great advice :)
|
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
|
| I read in a blog 50M lines in Vista and 24 hour builds. That's insane :|
|
| --
| Dave Sexton
|
|
 
Hm... I remember a co-worker showing me this, but cannot find it
myself. Probably confused with something else.
 
Dave said:
Hi Stephany,


It's not optimized out.

Is that true of the JIT compiler? It may not be optimized out in the
IL, but it might be optimized out when JIT compiled.
 
what do you mean by components?

Mark
--
http://www.markdawson.org


Dave Sexton said:
Hi Mark,

Do they build the components serially, concurrently or mixed?

--
Dave Sexton

Mark R. Dawson said:
Hi Dave,
check-in cut off time is 7PM, that is the time when the build guys kick
off a build, the build (as long as there are no build breaks) are available
around lunch time the next day :-)

Mark.
--
http://www.markdawson.org


Dave Sexton said:
Hi William,

But then again, I'm not sure if they actually started from scratch at 50M. They may have dumped
1M
and ended up with 50M :)

For nightly builds do they start the day before? ;)

--
Dave Sexton

Your probably closer. They still build on an IBM mainframe? I think I
remember they used to do that with NT.

--
William Stacey [C# MVP]

| Hi William,
|
| <snip>
|
| > Don't push a bad design and think you can "fix" it with more
| > code.
|
| Great advice :)
|
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
|
| I read in a blog 50M lines in Vista and 24 hour builds. That's insane :|
|
| --
| Dave Sexton
|
|
 
Hi Chris,

Yes, others have mentioned that as well.

But Bruce Wood has made a good point that something as simple as this will most likely not be
checked at runtime, but instead checked at compile-time, which it's not. It's probably safe to
assume that the JIT process will not optimize this out if the compiler doesn't already. JIT
performance would be decreased for no good reason to check for innocuous things such as this.

To be perfectly honest though, who really cares? :)

I don't know of any application that it would make any difference in performance using one construct
over the other. My personal preference is for simplicity and readability, however.
 
Hi Mark,

Well Vista doesn't consist of a single C++ project, right?

And I assume there is an elaborate framework of relationships between link libraries that need to be
built in a specific order. So I was wondering if any of these smaller components are built
concurrently, to save time, or if the build process just orders by dependency and builds serially.

--
Dave Sexton

Mark R. Dawson said:
what do you mean by components?

Mark
--
http://www.markdawson.org


Dave Sexton said:
Hi Mark,

Do they build the components serially, concurrently or mixed?

--
Dave Sexton

Mark R. Dawson said:
Hi Dave,
check-in cut off time is 7PM, that is the time when the build guys kick
off a build, the build (as long as there are no build breaks) are available
around lunch time the next day :-)

Mark.
--
http://www.markdawson.org


:

Hi William,

But then again, I'm not sure if they actually started from scratch at 50M. They may have
dumped
1M
and ended up with 50M :)

For nightly builds do they start the day before? ;)

--
Dave Sexton

Your probably closer. They still build on an IBM mainframe? I think I
remember they used to do that with NT.

--
William Stacey [C# MVP]

| Hi William,
|
| <snip>
|
| > Don't push a bad design and think you can "fix" it with more
| > code.
|
| Great advice :)
|
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
|
| I read in a blog 50M lines in Vista and 24 hour builds. That's insane :|
|
| --
| Dave Sexton
|
|
 
Dependencies are specified in the build scripts, whether or not the build is
smart enough to build mutually exclusive modules concurrently, that I do not
know :-)

Mark.
--
http://www.markdawson.org


Dave Sexton said:
Hi Mark,

Well Vista doesn't consist of a single C++ project, right?

And I assume there is an elaborate framework of relationships between link libraries that need to be
built in a specific order. So I was wondering if any of these smaller components are built
concurrently, to save time, or if the build process just orders by dependency and builds serially.

--
Dave Sexton

Mark R. Dawson said:
what do you mean by components?

Mark
--
http://www.markdawson.org


Dave Sexton said:
Hi Mark,

Do they build the components serially, concurrently or mixed?

--
Dave Sexton

Hi Dave,
check-in cut off time is 7PM, that is the time when the build guys kick
off a build, the build (as long as there are no build breaks) are available
around lunch time the next day :-)

Mark.
--
http://www.markdawson.org


:

Hi William,

But then again, I'm not sure if they actually started from scratch at 50M. They may have
dumped
1M
and ended up with 50M :)

For nightly builds do they start the day before? ;)

--
Dave Sexton

Your probably closer. They still build on an IBM mainframe? I think I
remember they used to do that with NT.

--
William Stacey [C# MVP]

| Hi William,
|
| <snip>
|
| > Don't push a bad design and think you can "fix" it with more
| > code.
|
| Great advice :)
|
| > MS had to do this with Vista. I think over million lines of code went
in
| > the basket. Hindsight says that was a great desision as they ended up
with
| > a better product.
|
| I read in a blog 50M lines in Vista and 24 hour builds. That's insane :|
|
| --
| Dave Sexton
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top