473,698 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Coding style article with interesting section on white space

Thought some folks here might find this one interesting. No great revelations,
just a fairly sensible piece on writing readable code :)

The whole article:
http://www.acmqueue.com/modules.php?...pid=271&page=1

The section specifically on white space:
http://www.acmqueue.com/modules.php?...pid=271&page=3

Cheers,
Nick.

--
Nick Coghlan | nc******@email. com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #1
15 2090
Thanx Nick

Jul 18 '05 #2
Nick Coghlan wrote:
Thought some folks here might find this one interesting. No great revelations, just a fairly sensible piece on writing readable code :)

The whole article:
http://www.acmqueue.com/modules.php?...pid=271&page=1
The section specifically on white space:

http://www.acmqueue.com/modules.php?...pid=271&page=3

The suggestions in the cited article, "How Not to Write FORTRAN in Any
Language", are reasonable but elementary and can be followed in Fortran
90/95/2003 as well as any other language. What infuriates me is that
the author writes as if Fortran has not evolved since the 1960s. It
has. To be specific, Fortran 90

(1) allows variable names up to 31 characters long
(2) has a free source form where
(a) there are no rigid rules about starting code in a certain
column
(b) white space is significant
(3) has a full set of control structures -- goto's are almost never
needed

More detailed rebuttals of the article are in the archives of the
Fortran 90 discussion group at
http://www.jiscmail.ac.uk/cgi-bin/we...omp-fortran-90
-- search for "Fortran bashing".

Python looks more like Fortran 90 than one of the curly-brace/semicolon
languages, and both languages have modules and array slices.

One ought to do a little research before publishing an article.
Apparently, many authors and editors are too lazy to do so.

Jul 18 '05 #3
In article <11************ *********@z14g2 000cwz.googlegr oups.com>,
<be*******@aol. com> wrote:
Jul 18 '05 #4
be*******@aol.c om wrote:
The suggestions in the cited article, "How Not to Write FORTRAN in Any
Language", are reasonable but elementary and can be followed in Fortran
90/95/2003 as well as any other language. What infuriates me is that
the author writes as if Fortran has not evolved since the 1960s. It
has. To be specific, Fortran 90


For myself, I'd be more inclined to say you can write Perl in any language, but
the fact that the author used Fortan as his own hated source of unreadable code
is beside the point - the entire point of the article is that readability
counts, no matter what language you're writing in :)

And that's why the article got published in spite of the jabs at Fortran - those
jabs served to explain the source of the author's detestation of unreadable
code. Anyone taking such an admittedly biased opinion and using it to form an
opinion on _current_ Fortan has problems far bigger than a single article.

Cheers,
Nick.

--
Nick Coghlan | nc******@email. com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
Jul 18 '05 #5
(unwisely taking the bait...)

If you like your language to look like this
http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
then more power to you.

I prefer my languages to be portable, terse and expressive. That's why
I like Python. If you want your language to be obscure, ill-defined and
inconsistent across platforms, by all means go to comp.lang.fortr an .

There is no fundamental reason why a language with expressive power
much like Python's cannot have run-time performance comparable to
Fortran's. Unfortunately, Fortran's dominance of the relatively small
scientific computation universe has prevented such a language from
emerging. The solutions which interest me in the short run are 1)
writing a code generation layer from Python to a compiled language
(possibly F77 though I will try to get away with C) and 2) wrapping
legacy Fortran in Python. The latter is quite regularly subverted by
non-standard binary data structures across compilers and a pretty
profound disinterest in interoperabilit y by the people designing the
Fortran standard that makes their interest look more like turf
protection and less like an interest in the progress of science.

In the long run, hopefully a high-performance language that has
significant capacity for abstraction and introspection will emerge.
People keep trying various ways to coax Python into that role. Maybe it
will work, or maybe a fresh start is needed. Awkwardly bolting even
more conetmporary concepts onto Fortran is not going to achieve
bringing computational science up to date.

Python fundamentally respects the programmer. Fortran started from a
point of respecting only the machine, (which is why Fortrans up to F77,
having a well-defined objective, were reasonable) but now it is a
motley collection of half-baked and confusing compromises between
runtime performance, backward compatibility, and awkward efforts at
keeping up with trends in computer languages. So-called "object
oriented Fortran" makes the most baroque Java look elegant and
expressive.

For more see http://www.fortranstatement.com
Language matters. You can't really write Python in any language.

mt

Jul 18 '05 #6
Michael Tobis wrote:
(unwisely taking the bait...)

If you like your language to look like this
http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
then more power to you.
Thanks for pointing out that interesting article on Fortran 90 bugs.
How long would a comparable C++ list be? Even Python has gotchas, for
example the difference between deep and shallow copies.
I prefer my languages to be portable, terse and expressive.
Fortran programmers are generally happy with the portability of the
language. A difficulty with Python portability and maintainability is
that some needed functionality is not in the core language but in C
extensions. For scientific computation, consider the case of Numeric
and Numarray. I don't think Numeric binaries are available for Python
2.4, and Numarray is not perfect substitute, being considerably slower
for small arrays, having slightly different functionality in some
areas, and
as recently as Nov 2004 (c.l.py thread "numarray memory leak") leaking
memory when multiplying matrices.

The recent "Pystone Benchmark" message says that Python is only 75% as
fast on Linux as on Windows. Fortran programs do not suffer this
performance hit and are in this respect more portable. In theory, as
has been mentioned, one could use a faster compiler to compile CPython
on Linux, but AFAIK this has not yet been done.

<snip>
There is no fundamental reason why a language with expressive power
much like Python's cannot have run-time performance comparable to
Fortran's. Unfortunately, Fortran's dominance of the relatively small
scientific computation universe has prevented such a language from
emerging.
Nobody is stopping Python developers from working on projects like
Psyco.
The solutions which interest me in the short run are 1)
writing a code generation layer from Python to a compiled language
(possibly F77 though I will try to get away with C) and 2) wrapping
legacy Fortran in Python. The latter is quite regularly subverted by
non-standard binary data structures across compilers and a pretty
profound disinterest in interoperabilit y by the people designing the
Fortran standard that makes their interest look more like turf
protection and less like an interest in the progress of science.
So uninterested in interoperabilit y is the Fortran standards committee
that they added interoperabilit y with C in Fortran 2003 standard.

<snip>
Python fundamentally respects the programmer.
What does that mean?
Fortran started from a point of respecting only the machine, (which is > why Fortrans up to F77, having a well-defined objective, were reasonable)
I have found that Fortran 90/95 is better at the objective of FORmula
TRANslation for array expressions (mostly what I need) than previous
versions.
but now it is a motley collection of half-baked and
confusing compromises between runtime performance, backward
compatibility, and awkward efforts at keeping up with trends in
computer languages.
This is true to some extent of any language "of a certain age",
including C++.

<snip>
For more see http://www.fortranstatement.com


And the rebuttal at http://www.fortranstatement.com/Site/responses.html
..

Jul 18 '05 #7
be*******@aol.c om wrote:
The recent "Pystone Benchmark" message says that Python is only 75% as
fast on Linux as on Windows.


no, it really only says that the Pystone benchmark is 75% as fast as Linux as on
Windows, on the poster's hardware, using his configuration, and using different
compilers.

</F>

Jul 18 '05 #8
<be*******@aol. com> wrote:
Michael Tobis wrote:
(unwisely taking the bait...)

If you like your language to look like this
http://www.cs.rpi.edu/~szymansk/OOF90/bugs.html
then more power to you.
Thanks for pointing out that interesting article on Fortran 90 bugs.
How long would a comparable C++ list be? Even Python has gotchas, for
example the difference between deep and shallow copies.


C++ "gotchas" spawn whole books. So, once, did C ones -- Koenig's "C
Traps and Pitfalls" is a wonderful book; to be honest, that was only
partly about the _language_... Koenig's advocacy of half-open loops and
intervals is just as valid in any language, but it was still a point
WELL worth making.

The referenced page, in part, is simply pointing out places where
Fortran might prove surprising to a programmer just because it works
differently from some other language the programmer might be used to.
For example, the very first entry just says that '.and.' does not
short-circuit, so when you need guard behavior you should rather use
nested IF statements. This is no bug, just a reasonable language design
choice; anybody coming from (standard) Pascal would not be surprised;
Ada even has two different forms ('and' doesn't short-circuit, if you
want short-circuit you use 'and then').
In some sense it can be a gotcha for some programmers, but it would be
silly to count it as a "fortran bug"! Or even "wart" for that matter.

So, I would try to classify things in three classes:

a. some things are important techniques which one may choose to
highlight in the context of a given language, yet it would simply
be silly to classify as gotchas, warts, or bugs _of that language_;

b. some aspects of a language's behavior are surprising to people
familiar w/other languages which behave differently, and thus are
worth pointing out as "gotchas" though they're surely not bugs (and
may or may not be warts);

c. lastly, some things are irregularities within the language, or
truly unexpected interactions among language features, or vary
between implementations in ways most programmers won't expect;
these can be described as warts (and maybe even bugs, meaning
things that may well be fixed in the next version of a language).

The advantages of half-open intervals (per Koenig's book), the fact that
copies exist in both shallow and deep senses, or the fact that with
pointers to pointers you need to allocate the parent pointers first (the
last entry in the referenced page) are really about [a] -- of course if
a language doesn't have pointers, or doesn't offer a standardized way to
make copies, you won't notice those aspects in that language (the issue
of half-open loops and intervals is wider...), but really these kinds of
observations apply across broad varieties of languages.

Point (b) will always be with us unless all languages work in exactly
the same way;-). 'and' will either short-circuit or not (or the
language will be more complicated to let you specify), array indices
will start from 0 or from 1 (or the language will be more complicated to
let you specify, etc etc), default values for arguments will be computed
at some specified time -- compile-time, call-time, whatever -- or the
language will be poorer (no default values, or only constant ones) or
more complicated (to let you specify when the default gets computed).
Etc, etc.

Point (c) is really the crux of the matter. Generally, simple languages
such as C or Python will have relatively few (c)-warts; very big and
rich ones such as C++ or Perl will have many; and ones in the middle, as
it appears to me that Fortran 90 is, will have middling amounts. I'm
not saying that lanugage size/complexity is the only determinant --
there are other aspects which contribute, e.g., the need for backwards
compatibility often mandates the presence of legacy features whose
interaction with other features may cause (c) moments, so, a language
which is older, has evolved a lot, and is careful to keep compatibility,
will be more at risk of (c)-level issues. Still, size matters. It's
just like saying that a big program is likely to have more bugs than a
small one... even though many other factors contribute (backwards
compatible evolution from previous versions matters here, too).

I prefer my languages to be portable, terse and expressive.


Fortran programmers are generally happy with the portability of the
language. A difficulty with Python portability and maintainability is
that some needed functionality is not in the core language but in C
extensions. For scientific computation, consider the case of Numeric
and Numarray. I don't think Numeric binaries are available for Python
2.4,


<http://www4.ncsu.edu/~jdbrandm/Numeric-23.6.win32-py2.4.exe> ? Just
googled and visited the first hit -- I don't currently use Windows so I
don't know if it's still there, works well, etc.
The recent "Pystone Benchmark" message says that Python is only 75% as
fast on Linux as on Windows. Fortran programs do not suffer this
performance hit and are in this respect more portable. In theory, as
You're saying that using a different and better compiler cannot speed
the execution of your Fortran program by 25% when you move it from one
platform to another...?! This seems totally absurd to me, and yet I see
no other way to interpret this assertion about "Fortran programs not
suffering" -- you're looking at it as a performance _hit_ but of course
it might just as well be construed as a performance _boost_ depending on
the direction you're moving your programs.

I think that upon mature consideration you will want to retract this
assertion, and admit that it IS perfectly possible for the same Fortran
program on the same hardware to have performance that differs by 25% or
more depending on how good the optimizers of different compilers happen
to be for that particular code, and therefore that, whatever point you
thought you were making here, it's in fact totally worthless.
has been mentioned, one could use a faster compiler to compile CPython
on Linux, but AFAIK this has not yet been done.


We're cheapskates, so we tend to go for the free compilers -- with the
exception of Windows, where I believe Microsoft donated many copies of
their newest commercial compiler to Python core developers working on
Windows (smart move on MS part, makes their platform look better at no
real cost to them).

But the more compilers are in use, the LARGER the variation of
performance I expect to see for the same code on a given box. There
will surely be cheapskates, or underfunded programmers, in the Fortran
world, too, using free or very cheap compilers -- or is your claim that
anybody using Fortran MUST be so flush with money that they only ever
use the costliest tools, and thus that Fortran should not be considered
unless your project's budget for programming tools is Rubenesque? Do
you think the costliest professional compilers cannot EVER find, on any
given benchmark, some optimization worth a 25% speedup wrt the cheapest
or free compilers...?! I really can't believe you'd claim any of this.
Maybe you will want to clarify what, if anything, you mean here.
Alex
Jul 18 '05 #9

Alex Martelli wrote:

<snip>
For scientific computation, consider the case of Numeric
and Numarray. I don't think Numeric binaries are available for Python 2.4,
<http://www4.ncsu.edu/~jdbrandm/Numeric-23.6.win32-py2.4.exe> ? Just
googled and visited the first hit -- I don't currently use Windows so

I don't know if it's still there, works well, etc.
I should have Googled. I will investigate that link. At SourceForge,
http://sourceforge.net/project/showf...?group_id=1369 I see a
Numarray but not a Numeric Windows binary for Python 2.4. The latest
Numeric Windows binary there is for Python 2.3.
The recent "Pystone Benchmark" message says that Python is only 75% as fast on Linux as on Windows. Fortran programs do not suffer this
performance hit and are in this respect more portable. In theory,
as
You're saying that using a different and better compiler cannot speed
the execution of your Fortran program by 25% when you move it from one platform to another...?! This seems totally absurd to me, and yet I see no other way to interpret this assertion about "Fortran programs not
suffering" -- you're looking at it as a performance _hit_ but of course it might just as well be construed as a performance _boost_ depending on the direction you're moving your programs.


I had in mind the Polyhedron Fortran 90 benchmarks for Windows and
Linux on Intel x86 at
http://www.polyhedron.co.uk/compare/...0bench_p4.html and
http://www.polyhedron.co.uk/compare/...0bench_p4.html . The speed
differences of Absoft, Intel, and Lahey between Linux and Windows for
individual programs, not to mention the average differential across all
programs, is much less than 25%. The differences on a single OS between
compilers can be much larger, but that has less bearing on portability
across OS's.

Thanks for your earlier informative comments on languages. Sparring
with Alex Martelli is like boxing Mike Tyson, except that one
experiences brain enhancement rather than brain damage :).

Jul 18 '05 #10

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

Similar topics

31
2491
by: bart | last post by:
Why is it that everybody likes the follwowing curly braces syntax function() { implementations; } I find the following much better to read (C style) function() {
1
2561
by: Mark | last post by:
Hi all, I have a report that prints quotations with images of the stock item if there is an image. images are externally stored. My problem is that when there is an image to display and the description text box which is to the left of the image is more then one line of text(can grow = true), the report section increases in size and leaves a white space between the next record below. If there is an image to display with only one line of...
63
3505
by: Papadopoulos Giannis | last post by:
Which do you think is best? 1. a) type* p; b) type *p; 2. a) return (var); b) return(var); c) return var;
60
3169
by: Eric | last post by:
I thought it might be fun to run a simple vote to discover the most preferred spacing style for a simple if statement with a single, simple boolean test. By my count, there are 32 possible variations for this case. Here is a complete list. AA: if ( a > b ) AB: if ( a > b) AC: if ( a >b ) AD: if ( a >b) AE: if ( a> b )
144
6859
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this initiative. Typically I find that coding standards are written by some guy in the company who has a way of coding that he likes and then tries to force everybody else to write code the way he likes it, not for any rational reason, but simply for the...
29
2270
by: Ron Burd | last post by:
Hi, As my company is moving into C# they are enforcing the use of styling convention in the source code, such as methods naming conventions, newlines, etc. Does someone know of products that are good at this job? (free and/or commercial)
6
24727
by: Tim Cartwright | last post by:
I am trying to figure out how to change the gridview caption style, but I can not figure out how. I added table caption { background-color: #5D7B9D; color: White; font-size: 16pt; } to my CSS, yet when the page renders, the grids style take precendence, as
4
1698
by: cmay | last post by:
It seems that when you are creating a page that uses a Master Page, there is no place to put a style block w/o VS.Net saying that you are putting in an incorrect tag. Where should a style block go on a page that uses a Master Page?
10
226
by: Torsten Mueller | last post by:
Where does it come from to make spaces everywhere but not between a keyword and a condition? I'm confronted with code looking like that: if( x == 3 && y == 7 && z == 1024 ) { for( int i = 0; i < 1000 ; i++ ) { } }
0
9152
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
9014
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...
1
8885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5857
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
4358
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
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
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.