473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

best practices

Newsgroupies:

Good guidelines keep source code within a "comfort zone". Programming
languages provide extraordinarily wide design spaces, much wider than
hardware designs enjoy, with many tricks and backdoors that could provide
hours of pleasant diversion writing obfuscated code.

Don't write like that on the job. Always write similar, obvious statements
to do similar, simple things. Engineers learn their working vocabulary from
experience and teammates. A healthy subset of all possible language
constructions keeps everyone sane.

Programming tutorials often contain recommendations like:

* "Make all data private to a class."
* "Program to the interface, not the implementation."
* "No global variables."
* "High level policy should not depend on low level detail."
* "Declare a separate interface for each category of client to a class."
* "No down-casting. Don't use an object's type in a conditional."
* "Don't do too much on one line."
* "Use return to prematurely exit nested loops."
* "Use complete, pronounceable names."
* "Dependencies between modules should not form cycles."
* "Don't allow client objects to tell the difference between servant
objects using the same interface."
* "Don't use anObject.getSomething().getSomethingElse()... too deeply -
tell the target object what your high-level intent is, and let it
pass the message."
* "Different variables holding the same datum should have the same name."
* "Never return null. Never accept null as parameter."
* "In C++, don't abuse #define."
* "Put a class's public things at the top; private things below."
* "Give identifiers the narrowest scope possible."
* Etc...

Such rules are hardly exalted wisdom or exact engineering constraints (and
so is "test-first"). They are easy to remember, and nearly always preserve
code flexibility. All these rules are infinitely debatable. Rules are meant
to be made, followed, and broken.

(Those curious how to follow the rule "never return null" may research a
Refactor called "Introduce NullObject".)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 10 '06 #1
9 1768
Phlip posted:
Newsgroupies:

Good guidelines keep source code within a "comfort zone". Programming
languages provide extraordinarily wide design spaces, much wider than
hardware designs enjoy, with many tricks and backdoors that could
provide hours of pleasant diversion writing obfuscated code.

Don't write like that on the job. Always write similar, obvious
statements to do similar, simple things. Engineers learn their working
vocabulary from experience and teammates. A healthy subset of all
possible language constructions keeps everyone sane.

Programming tutorials often contain recommendations like:

* "Make all data private to a class."
* "Program to the interface, not the implementation."
* "No global variables."
* "High level policy should not depend on low level detail."
* "Declare a separate interface for each category of client to a
class." * "No down-casting. Don't use an object's type in a
conditional." * "Don't do too much on one line."
* "Use return to prematurely exit nested loops."
* "Use complete, pronounceable names."
* "Dependencies between modules should not form cycles."
* "Don't allow client objects to tell the difference between servant
objects using the same interface."
* "Don't use anObject.getSomething().getSomethingElse()... too deeply -
tell the target object what your high-level intent is, and let it
pass the message."
* "Different variables holding the same datum should have the same
name." * "Never return null. Never accept null as parameter."
* "In C++, don't abuse #define."
* "Put a class's public things at the top; private things below."
* "Give identifiers the narrowest scope possible."
* Etc...

Such rules are hardly exalted wisdom or exact engineering constraints
(and so is "test-first"). They are easy to remember, and nearly always
preserve code flexibility. All these rules are infinitely debatable.
Rules are meant to be made, followed, and broken.

(Those curious how to follow the rule "never return null" may research
a Refactor called "Introduce NullObject".)

I rather re-learn the alphabet than read over such a document.

-Tomás
Apr 11 '06 #2
Tomás wrote:
(Those curious how to follow the rule "never return null" may research
a Refactor called "Introduce NullObject".)


I rather re-learn the alphabet than read over such a document.


Why?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 11 '06 #3
Phlip posted:
Tomás wrote:
(Those curious how to follow the rule "never return null" may research a Refactor called "Introduce NullObject".)


I rather re-learn the alphabet than read over such a document.


Why?


I was referring to the overall idea of "Good practise code". I've been
programming long enough to take my own advice.

When I hear something like "don't use global variables", I don't even
laugh, I just tune out.
-Tomás
Apr 11 '06 #4
In article <Y2*****************@newssvr24.news.prodigy.net> ,
Phlip <ph*******@gmail.com> wrote:
Newsgroupies:

Good guidelines keep source code within a "comfort zone". Programming
languages provide extraordinarily wide design spaces, much wider than
hardware designs enjoy, with many tricks and backdoors that could provide
hours of pleasant diversion writing obfuscated code.

Don't write like that on the job. Always write similar, obvious statements
to do similar, simple things.
The best part about following the above advice is that it makes it easer
to find abstractions. Looking for ways to make two bits of code look the
same goes a long way toward finding new abstractions to exploit.
Engineers learn their working vocabulary from
experience and teammates. A healthy subset of all possible language
constructions keeps everyone sane.

Programming tutorials often contain recommendations like:

* "Make all data private to a class."
* "Program to the interface, not the implementation."
* "No global variables."
* "High level policy should not depend on low level detail."
* "Declare a separate interface for each category of client to a class."
* "No down-casting. Don't use an object's type in a conditional."
* "Don't do too much on one line."
* "Use return to prematurely exit nested loops."
* "Use complete, pronounceable names."
* "Dependencies between modules should not form cycles."
* "Don't allow client objects to tell the difference between servant
objects using the same interface."
* "Don't use anObject.getSomething().getSomethingElse()... too deeply -
tell the target object what your high-level intent is, and let it
pass the message."
* "Different variables holding the same datum should have the same name."
* "Never return null. Never accept null as parameter."
* "In C++, don't abuse #define."
* "Put a class's public things at the top; private things below."
* "Give identifiers the narrowest scope possible."
* Etc...

Such rules are hardly exalted wisdom or exact engineering constraints (and
so is "test-first"). They are easy to remember, and nearly always preserve
code flexibility. All these rules are infinitely debatable. Rules are meant
to be made, followed, and broken.


These rules are much like what "The Little Brown Handbook" is to English
composition. When writing in any language, there are many ways to say
the same thing. Some are more creative, while some are more proper.

Our goal should be to write "proper" C++, which is much more restrictive
than simply "it compiles and the result is correct."
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Apr 11 '06 #5
Tomás wrote:
When I hear something like "don't use global variables", I don't even
laugh, I just tune out.


Did you notice the verbiage "Such rules are hardly exalted wisdom or exact
engineering constraints"?

If you wrote code with a team, would you expect them to adjust your style?

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 11 '06 #6

Tomás wrote:
Phlip posted:
Tomás wrote:
(Those curious how to follow the rule "never return null" may research a Refactor called "Introduce NullObject".)

I rather re-learn the alphabet than read over such a document.


Why?


I was referring to the overall idea of "Good practise code". I've been
programming long enough to take my own advice.

When I hear something like "don't use global variables", I don't even
laugh, I just tune out.


True that, but on the other hand I run into code that uses globals
often enough to warrant reiterating the idea that they are bad. Not
only that, but I run into such aweful constructs as globals being used
for more than one purpose by different sections of code....shudder.

On the other hand, I don't agree with all of the "best practices"
listed...for instance never returning null as, in C and C++ at least,
null is quite often used for "not found" or "unavailable" and is a
great way to return such a concept without having to use return codes
and output parameters or getting stuck with the quite questionable idea
of throwing an exception for such a normal event. I don't see much
point creating an object to represent null just to ask it if it is null
when such an object already exists: 0.

Apr 11 '06 #7
In article <tO******************@news.indigo.ie>,
"Tomás" <NU**@NULL.NULL> wrote:
When I hear something like "don't use global variables", I don't even
laugh, I just tune out.


By all means Tomas, globals are good. In fact I kind of wonder why a
rather large chunk of the language is devoted to limiting the scope of
variables when globals can do it all.

This I know, if you write a program using only globals, you are doomed
to failure. Writing a program with no globals will (all other things
being equal) produce a better program in every way.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Apr 11 '06 #8

Daniel T. wrote:
In article <tO******************@news.indigo.ie>,
"Tomás" <NU**@NULL.NULL> wrote:
When I hear something like "don't use global variables", I don't even
laugh, I just tune out.


By all means Tomas, globals are good. In fact I kind of wonder why a
rather large chunk of the language is devoted to limiting the scope of
variables when globals can do it all.

This I know, if you write a program using only globals, you are doomed
to failure. Writing a program with no globals will (all other things
being equal) produce a better program in every way.


I think Thomas was refering to the fact that the "no globals" concept
is pretty old-hat, not that he disagreed with it.

Apr 11 '06 #9
Noah Roberts wrote:
I think Thomas was refering to the fact that the "no globals" concept
is pretty old-hat, not that he disagreed with it.


Ah, but now we have Singletons to abuse!

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
Apr 11 '06 #10

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

Similar topics

2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
13
by: john doe | last post by:
A quick question, about so-called 'best practices', I'm interested in which of A/B of the two examples people would choose, and why. public enum MyEnum { Option1 = 0, Option2 = 1, Option3 =...
1
by: | last post by:
Hi can someone send or point me to Any nice Material on .NET Best Practices -regards
2
by: Amelyan | last post by:
Could anyone recommend a book (or a web site) that defines best practices in ASP.NET application development? E.g. 1) Precede your control id's with type of control btnSubmit, txtName, etc. 2)...
4
by: Luis Esteban Valencia | last post by:
Hello. Can somebody recomend me books of design patterns in c# and best practices too.
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
0
by: Louis Aslett | last post by:
I hope this is the correct newsgroup for this query (if not please give me a pointer to where is best): I understand the theory of normalisation etc and am trying to follow best practices in the...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
3
by: John Dalberg | last post by:
I am looking for an ASP.NET application on CodePlex which exemplifies best practices for the following: - Use of interfaces - Seperation of the UI, business and data tiers - Data Tier that uses...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...

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.