Re: truly-optimized coding styles & design patterns in C#?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Bob Grommes (bob_at_bobgrommes.com)
Date: 09/18/04


Date: Sat, 18 Sep 2004 06:06:41 -0700

R,

Your honesty (and courage!) are refreshing.

The first thing I would say is that you are to be commended for your
pragmatism. Don't change it. Use what works, yet be curious about ways to
improve it. In that sense you are exactly on-track.

My sense is that you may have a background in structured programming and
haven't quite had your "aha" experience yet with OOD. I would focus on
grokking design patterns but try to find practical examples of each pattern
that you can relate to. I admit, that's easier said than done since far too
many writers fail to provide practical rationales and examples. But with a
fair bit of Googling you can usually some up with something.

Also, consider looking at "anti-patterns" -- things not to do.

Another thing you can do to expand your mind is to learn a new language now
and then. Each one has its own ways of approaching the problem domain and
comparing and contrasting how they work gives you a deeper understanding of
concepts. Sometimes you see that features or concepts that are terribly
important in language X are less important in language Y because of
something inherent in the language, not necessarily something inherent in
OOP. Personally for example I'm pecking away at Ruby right now and find it
rather mind-expanding after two and a half years of steady C# coding.

You are right not to feel obligated to use every feature just because it's
there. Start by naming your number one maintenance headache in the many
apps you've written and seek out the simplest and most elegant ways to
mitigate that problem first.

As to your question whether "all this stuff" is just for "big projects" --
I'd give you a qualified "no". There are often different trade-offs in,
say, creating a small utility app vs coding something that has to fit into
an Enterprise framework vs something destined for commercial release. But,
good design is good design and the best design ideas tend to be generally
applicable to most any non-trivial project.

It's hard sometimes to find the balance between some theoretically "best"
way and the messy real-world demands of deadlines and marketing droids and
so forth. The way you describe the acquiantance who was whipping up all
sorts of elaborate and elegant "software souffles" might be describing some,
any, or all of the following:

1) A really expert guy working "in the zone"
2) Someone trying to build an app that only he can maintain
3) Someone constructing a monument to their ideal of the perfect program, at
the expense of practical matters

I'm a little worried that he creates "everything from scratch". Surely he
has a body of existing work that he leverages as a starting point! If not,
why not?

Does this guy have a track record of producing stable software on time that
the customer is happy with? Then emulate him -- especially if he documents
his work and can explain it coherently. Otherwise take him with a grain of
salt.

--Bob

"R Reyes" <RReyes@discussions.microsoft.com> wrote in message
news:774B2042-27F7-4970-9DBC-4A73C189C74E@microsoft.com...
> Hello All,
>
> I'm always looking for ways to improve my code. Most of the time
(whenever
> I'm working on a project) I write a bunch of functions. Then after the
> project is finished, I put all the similar functions into their own
> module/class/page for neatness:
> -- like a stringsManipulate class which has all string manipulation
methods
> to the project...separated from the whole project into its own library for
> neatness.
> -- like a databaseActions class (or code library) which holds all the
> database methods to the project...also separated from the project into its
> own library for neatness.
>
> By the time my project is separated/sorted, it consists anywhere from 5-10
> pages/libraries of functions so that everything is nice and neat.
>
> However, there are never any delegates, factories, interfaces, extensions,
> exceptions classes, none of that. Sometimes I have some error handlers
but i
> never have any of the other features I just mentioned. So, what i'm
> wondering is...is all that fancy stuff really necessary? Or, is that just
> something you need to worry about when you're working on something you
know
> millions of people will use (like some big business product or application
> like AOL)?
>
> I've been coding for several years now and I've seen many other people's
> coding styles. One guy I knew I think created all his objects from
scratch.
> I've seen him code his own framework of factories, iterators, interfaces,
> structs, event handlers, delegates, creating exceptions here, throwing
> exceptions there, extending something there, implementing something here.
It
> looked very confusing and very time-consuming...yet efficient and neater
than
> the way I was doing things.
>
> So what I want to know is...is this all fancy stuff necessary or any good
> for small-medium website developments or desktop apps? And if so, are
there
> any links where I can learn the best design, strucutres, object models,
and
> the like?
>
> I have been looking up some c# design patterns and there are many of them
> have my mind going in circles. When coding normally, I never know when I
> need to make exceptions, or interfaces, or events...My mind doesn't think
> like that and I'm trying to find a place that will make me understand.
>
> Usually I just write a function that does what I need to do and it works
so
> I take it, break it, and separate it for neatness. But somehow I feel
that's
> not enough. Somehow I feel I need to get my hands even dirtier and create
my
> own framework of factories and all those other concepts I can't really
> understand. But is it really worth it? And would small web development &
> desktop application stuff really have a great improvement in speed and
> cleanliness? Well cleanliness I can see...speed I'm not sure of...I guess
so?
>
> Hope some of you can help me out. Thanks for reading.



Relevant Pages

  • Re: Is top-down design feasible for a coffee-break roguelike?
    ... fundamental design decisions should be settled before doing coding.. ... is strongly linked to the game mechanics itself. ... but simply because it assumes diagonal movement is disallowed. ...
    (rec.games.roguelike.development)
  • Re: mfc pitfalls
    ... In most MFC apps, you are writing code in that kind ... virtual methods usually work better than callbacks for most ... no syntax in the design for function pointers. ... programming in OO environment requires new ...
    (microsoft.public.vc.mfc)
  • Re: Open source alternative for MsAccess?
    ... techniques I use to make sure my apps don't come out looking ugly. ... fonts should use standard Windows fonts most of the time. ... I don't see it as opaque at all. ... don't understand database design generally don't do well with it. ...
    (comp.os.linux.development.apps)
  • Re: Mmmm nobody want to give me an answer here
    ... maintenance tasks because of the choices that were made when it ... Of course if you install windows XP by itself without any ... When in the design of the OS this choice happened and why? ... way to remove everything this apps has installed simply by removing ...
    (microsoft.public.windowsxp.perform_maintain)
  • Re: Handling error/status messages by interface to C++ programs
    ... about how to design a compiler, please tell me where I can find ... exceptions for managing the error detection is rather a bad idea. ... I have to say I have seen a simple example of an object-oriented parser design in some book (unfortunately I forgot ... It would trigger user notification and do recover housekeeping like reseting the current syntax row's token stack because one wants to continue parsing and detect any other errors w/o aborting. ...
    (comp.object)