473,684 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading great code

Hello!

In his recent newsletter embedded expert Jack Ganssle says that
programming students, as well as professional developers should readh
"great code" (hight quality/well-crafted code that works). He even
gives to examples. One is uC/OS-II operating system and the other is
TCP/IP stack for said system.
Do you know of other good examples of elegant and high-quality code
that is publicly available so that developers may look at it and learn?

It would be interesting to see it and may be even discuss why it is so
great.

Oct 13 '06 #1
42 2259
Hello!
>
In his recent newsletter embedded expert Jack Ganssle says that
programming students, as well as professional developers should readh
"great code" (hight quality/well-crafted code that works). He even
gives to examples. One is uC/OS-II operating system and the other is
TCP/IP stack for said system.
Do you know of other good examples of elegant and high-quality code
that is publicly available so that developers may look at it and learn?

It would be interesting to see it and may be even discuss why it is so
great.
Most programmers never reach the level where they're capable of writing
"great" code. How you even define "great" is debatable as there's a lot
of artistic license involved. It's not a hard science. However, those who
can consistently do it intrinsically understand how to convert program
requirements into beautiful code similar to the way a grandmaster at chess
intrinsically understands how to move his pieces around the board. It's a
combination of various mental "chunking" skills achieved after years of
practice (i.e., the ability to quickly and effortlessly see through a
problem without having to dwell on the constituent parts comprising that
problem). From this you can create an elegant solution without having to
think about it too much. It's hard to teach this to others however. You can
demonstrate a lot of sound principles but it takes tremendous practice and a
certain innate ability to master it yourself. Unfortunately, based on my own
experience, most people are incapable of it just like most can never become
a great chess player no matter how hard they try (even with Gary Kasparov as
your teacher). My own advice would be simple however. Make all your code as
generic and reusable (and robust) as possible. 95% or more of almost any
program can be made this way but 95% of all programmers don't understand
this fundamental rule. It's the hallmark of a great programmer however (if
you can master it you'll be on your way to writing "great" code - if you
want to take this offline I can send you some well documented C++ samples to
demonstrate).
Oct 13 '06 #2
gt8887b wrote:
Hello!

In his recent newsletter embedded expert Jack Ganssle says that
programming students, as well as professional developers should readh
"great code" (hight quality/well-crafted code that works). He even
gives to examples. One is uC/OS-II operating system and the other is
TCP/IP stack for said system.
Do you know of other good examples of elegant and high-quality code
that is publicly available so that developers may look at it and learn?

It would be interesting to see it and may be even discuss why it is so
great.
It's old (1976) and it's Pascal, but . . .

For my money, the best programming technique book ever is "Algorithms + Data
Structures = Programs", by Wirth (ISBN 0-13-022418-9). Elegant algorithms,
artfully implemented, and he illustrates somewhat the process of creation
(including sometimes the messiness and false starts) rather than just presenting
finished programs which seem to come from thin air.

FWIW, I have used uC/OS-II and agree that it is excellent code as well - it has
that same quality of being "straight to the point". The author (Labrosse)
explains his code well in the accompanying book along with many useful OS concepts.

Regards,
-rick-
Oct 14 '06 #3
John Browning <no_spam@_nospa m.comwrote:

<snip>
My own advice would be simple however. Make all your code as
generic and reusable (and robust) as possible. 95% or more of almost any
program can be made this way but 95% of all programmers don't understand
this fundamental rule.
Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand. I often find
that I then never reuse the component in question, having gone to all
the trouble of making it reusable. These days, I build things in a less
reusable way until I can see that I've got code which *could* be reused
with a bit of a tweak. At that point with the appropriate unit tests in
place, it's usually not too hard to make the changes while keeping the
original use working.

If you know for sure that you actually need the code to be generic from
the start, that's a different matter of course.

This is often known as "YAGNI": "You Ain't Gonna Need It"

See http://c2.com/xp/YouArentGonnaNeedIt.html or
http://en.wikipedia.or g/wiki/You_Ain't_Gonna _Need_It

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 14 '06 #4
"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************** *@msnews.micros oft.com...
>My own advice would be simple however. Make all your code as
generic and reusable (and robust) as possible. 95% or more of almost any
program can be made this way but 95% of all programmers don't understand
this fundamental rule.

Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand.
IMHO, this is only partially true.

In particular, one characteristic of a truly great programmer is to be able
to abstract a problem to the simplest form, which can often be a more
general, reusable solution rather than coding for some specific case.

It just depends on the problem, and I do agree that it's usually more
valuable to get something working first, and then improve, generalize, etc.
as needed. But IMHO some of the most elegant code also turns out to be some
of the most generic.

If the code, in being general, winds up with a bunch of special cases or
other extra conditional handling, then that's not what I'm talking about.
That's not an example of abstracting a problem...that' s an example of
weighing down what ought to be simple code with a bunch of baggage. :) I'm
talking about seeing the forest for the trees and solving something in a
general way because that's the most efficient, least-complicate way to code
it.

It does happen. :)

As an added benefit to this approach, if one has truly abstracted a problem
to its simplest form, that often leads to the simplest implementation, which
has a direct effect on the robustness of the solution.

IMHO it's not an either/or thing. Sometimes it's better to solve the
problem in a very specific way, sometimes it's better to solve it in a more
general way. Part of the art of programming is knowing the difference. :)

Pete
Oct 14 '06 #5
Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand. I often find
that I then never reuse the component in question, having gone to all
the trouble of making it reusable. These days, I build things in a less
reusable way until I can see that I've got code which *could* be reused
with a bit of a tweak. At that point with the appropriate unit tests in
place, it's usually not too hard to make the changes while keeping the
original use working.

If you know for sure that you actually need the code to be generic from
the start, that's a different matter of course.

This is often known as "YAGNI": "You Ain't Gonna Need It"
I couldn't disagree more :) The correlation between generic software and
successful software is simply overwhelming. When things are written
generically from the outset (and properly documented), you soon end up with
a large repository of stable and reusbable code. This is code that you and
your colleagues can become familiar and comfortable with and you can reuse
it over and over again across different projects. Every organization should
have a central library just like this (peer reviewed and properly
controlled). When things aren't done this way (almost always), I guarantee
that it's only a matter of time before you have very serious and expensive
problems on your hands (from code bloat to instability to serious
maintainance issues, etc.). Just about every software organization has these
problems in abundance because they don't follow this rule and I've witnessed
it first-hand over and over and over again (ad nauseam). It far more
expensive (and not just in $) by not doing things this way and it's the most
important thing I've learned after 24 years in the field.
Oct 14 '06 #6
Jon Skeet [C# MVP] wrote:
Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand.
True. On the other hand, code that is supposed to be reusable is often
more robust than code that only seek to solve a specific problem. So
making code more reusable should make it more robust, even if the code
never actually will be reused.

This is of course unless, as you mentioned, making it more reusable also
adds too much complexity to the code.

To solve a part of a problem in a reusable way may also help you to make
the main part of a problem more streamlined, and make the special cases
fit into the standard model instead of adjusting the standard model for
every special case. So sometimes thinking in terms of reusability makes
the code less complex instead of more.
I often find
that I then never reuse the component in question, having gone to all
the trouble of making it reusable. These days, I build things in a less
reusable way until I can see that I've got code which *could* be reused
with a bit of a tweak. At that point with the appropriate unit tests in
place, it's usually not too hard to make the changes while keeping the
original use working.
I experience that too.

I also use that method sometimes to produce code that I know should be
reusable in the end. By first implementing the different cases with
specific code makes it easier to figure out the similarities between the
cases to see what should go into the reusable code.
Oct 14 '06 #7
Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand.
IME, this is not true unless you are trying to solve too many problems at
once. I've found that the best and most efficient way to implement something
is to first create a solution for the generic case (like a list class) and
then derive from that implementation for specific use (like a sorted list
class). This many times results in less complex and more robust code. The
amount of code might be larger compared to writing the specific
implementation directly, but that doesn't automatically indicate that the
code is more complex.
--
Regards, Peter
Oct 14 '06 #8
John,

Your word artistic did hit me, for that it is worth to read the book from
Ogilvy, nothing to do with developing however, in my idea should every
developer read that. It gives more knowledge to a developer than those
thousands of on technique based books it in my idea.

http://www.profitadvisors.com/ogilvy.shtml

He is writing as well about artists, those who he helps in his bureau direct
to find another job at his concurrent.

The job is in my idea to make hings maintainable, if you see discussions on
this dotNet boards between Jon and me it is mostly that Jon is more about
the artistic code and me about the maintainable code (although Jon wants as
well maintainable code is he in my idea staying an artist).

Therefore what is great code has always a point of view. Although I am in
fact as well an artist, and like to write very clever code where less
commands are used, is that in my idea good as hobby, not for real live.

Cor
"John Browning" <no_spam@_nospa m.comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
>Hello!

In his recent newsletter embedded expert Jack Ganssle says that
programming students, as well as professional developers should readh
"great code" (hight quality/well-crafted code that works). He even
gives to examples. One is uC/OS-II operating system and the other is
TCP/IP stack for said system.
Do you know of other good examples of elegant and high-quality code
that is publicly available so that developers may look at it and learn?

It would be interesting to see it and may be even discuss why it is so
great.

Most programmers never reach the level where they're capable of writing
"great" code. How you even define "great" is debatable as there's a lot
of artistic license involved. It's not a hard science. However, those who
can consistently do it intrinsically understand how to convert program
requirements into beautiful code similar to the way a grandmaster at chess
intrinsically understands how to move his pieces around the board. It's a
combination of various mental "chunking" skills achieved after years of
practice (i.e., the ability to quickly and effortlessly see through a
problem without having to dwell on the constituent parts comprising that
problem). From this you can create an elegant solution without having to
think about it too much. It's hard to teach this to others however. You
can demonstrate a lot of sound principles but it takes tremendous practice
and a certain innate ability to master it yourself. Unfortunately, based
on my own experience, most people are incapable of it just like most can
never become a great chess player no matter how hard they try (even with
Gary Kasparov as your teacher). My own advice would be simple however.
Make all your code as generic and reusable (and robust) as possible. 95%
or more of almost any program can be made this way but 95% of all
programmers don't understand this fundamental rule. It's the hallmark of a
great programmer however (if you can master it you'll be on your way to
writing "great" code - if you want to take this offline I can send you
some well documented C++ samples to demonstrate).

Oct 14 '06 #9
Well, if all this debate, each person making some excellent points, and
almost all at odds with one another over those very points, doesn't point up
the greatest difficulty of mastering programming, I don't know what will.

In fact, I view the whole thing as a balancing act. Elegant software is a
beautiful thing to behold, and just as rare. For one thing, it just takes
too long to write, and we developers are constrained by time and money
considerations. Reusability is also a double-edged sword, and although I
believe John and Jon are both correct, their conflict is more one of
emphasis than perhaps they realize.

The real trick is to master skills that enable one to stay more or less
within the limits of what *can* be achieved, and that perfection that any
conscientious programmer desires to achieve in his/her work. Every developer
finds his/her own unique methodology to strive towards that "golden mean,"
and each is unique because we all have a unique combination of gifts and
liabilities.

All that said, reading "good" code is always a good idea. As for "great"
code, it's hard to draw the line between the 2, and even reading "bad" code
can be a worthwhile process, as long as one is looking at it as "bad." One
can observe and learn from the pitfalls that others have fallen into, as
well as from the examples of those who have attained a measure of skill.

The most important aspect of a programmer's personal development is the
drive to become perfect, a goal which, although impossible to attain, is
worth aiming at. What you seek is what you get, in the long run. Aim for the
stars, and someday, you'll at least reach the moon.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.

"John Browning" <no_spam@_nospa m.comwrote in message
news:ew******** ******@TK2MSFTN GP02.phx.gbl...
>Robust I can agree with. Reusable less so - because in my experience,
the more reusable and generic you make it, the more complex it has to
be in order to accomplish the one task you have at hand. I often find
that I then never reuse the component in question, having gone to all
the trouble of making it reusable. These days, I build things in a less
reusable way until I can see that I've got code which *could* be reused
with a bit of a tweak. At that point with the appropriate unit tests in
place, it's usually not too hard to make the changes while keeping the
original use working.

If you know for sure that you actually need the code to be generic from
the start, that's a different matter of course.

This is often known as "YAGNI": "You Ain't Gonna Need It"

I couldn't disagree more :) The correlation between generic software and
successful software is simply overwhelming. When things are written
generically from the outset (and properly documented), you soon end up
with
<snip>
Oct 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
14650
by: Santah | last post by:
hi I'm new to C++ and I'm currently working on Visual C++ 6.0 I'm trying to open a text file, and read some data from it part of the text file looks like this: --------
6
3787
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am trying to read a flatfile. In COBOL, my simple file layout and READ statement would look like below. Question: what is the standard, simple coding convention for reading in a flatfile - one record at a time?? SCANF does not work because of...
4
1426
by: sabads | last post by:
Hello all: I'm a student learning procedure-oriented programming(use C). I want to read some smart programs that perform important aspects of structure programming.so I'm eager to obtain some advices about such codes? BTW, the best are middle-scale and not too complex. I'm willing to elevate my design level of procedure-oriented programming by reading code. Thank you.
3
1583
by: Maxim Vexler | last post by:
Hello I'm looking for reading materials to educate myself on the security measures that should be taken to build a secure web site. What I'm referring to is web sites like the following : 1. http://www.securiteam.com/securityreviews/5DP0N1P76E.html 2. http://www.unixwiz.net/techtips/sql-injection.html 3. http://www.cgisecurity.com/articles/xss-faq.shtml
4
2974
by: n_jaksic | last post by:
I need to store heterogeneous data (for example, a string, a vector of floats and some ints) in an unsigned character array, for the purpose of storing information in some header. I then need to be able to read this data back into their original types. I could store the size of the vector and the string, as well as the number of ints along with the data to help with the reading later on. However, I'm having a hard time storing and then...
12
2896
by: SAL | last post by:
Hello, Is it possible to read a CSV from the Client, and bind my Datagrid to the data in the CSV file without uploading the file to the Server first? I have tried and in Debug mode on my workstation it works fine, but when I publish the page on our DEV server it doesn't fine the CSV file from the client. Has anyone done this before? If so, how do I do it? I'm new to ASP.net so
2
1744
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had to write a program in C++ that would allow the user to enter student information (matriculation number, name, status and mark), which was then stored in an array. They could then search it or list it. Everything was woking (and still is) up to here....
3
1687
by: javalen7 | last post by:
I have some code that reads some datarows into an arraylist (called al), returns this to the calling function, and uses this as the DataSource property of a datagrid. I need to read what's in "al", but it won't let me specify fields. However, if I simply want to see what's in the arraylist as a whole, I can do this in the immediate window by typing ?al, or any other index within the range of the arraylist, and I get something like the following:...
1
4725
by: stoogots2 | last post by:
I have written a Windows App in C# that needs to read a text file over the network, starting from the end of the file and reading backwards toward the beginning (looking for the last occurrence of a couple of strings in one line of text). I do not want to read the entire file, as it is very large, on a highly utilized server, and is updated with hundreds of lines of text every second. So since I am reading backwards, I do a seek, then read,...
0
8569
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8504
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9043
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8924
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7584
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5789
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4521
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.