I know its straightforward. It's still clunky and unclear. If you
really want that interpretation, but some brackets in there. Program
as you if expect other people to read your code. Express your intent,
and don't expect everyone to enjoy C's more pointless idioms as much
as you do.
The idiom isn't "pointless". It shows in fact that logic can be as
elegantly expressed as mathematics. It's one step away from Cobol.
You should use the features of the language when there is a benefit to
doing so, other than less typing. That way, Perl Golf lies. There's
no benefit to your code, except that is slightly harder to parse.
If you write code to demonstrate how smart you are, or how much of the
language you have mastered, you'll write unmaintainable code. Master
the language, but then exhibit good taste, and respect for people
who've not reached your level of mastery.
It's an Urban Legend that the software crisis was caused by
"pretentious" programmers using "obscure" constructs in order to "show
how smart they were".
In actuality, it was caused by savage managers who drove programmers
to ship at places like IBM in 1965 and Apple in 1981, not giving a
**** about the damage they caused to people's lives in their greed.
It meant that many programmers were unfamiliar with the languages they
used, being thrown with too little training on Death March projects
with insanse deadlines.
It is now accepted as a condition of employment that managers may make
absurd claims as to the doability of systems by such and such a date
in a forty hour week, and that the programmers will work 120 hour
weeks to make the deadline prediction come true and the manager look
good.
As a result, programmers hate their jobs and their lives, and the
notion of joyously coding
intSignum = intX > 0 ? 1 : (intX < 0 ? -1 : 0)
as opposed to this crap
if (s>0) return 1; return -1;
is now "pretentious". The former code snippet offends brutalized
programmers for the same reason people here confuse complete sentence
structure and accurate spelling with verbosity.
Good programming involves writing code that is easy to understand by
someone who is not a good programmer. Much as good technical writing
is writing that is easy to understand by someone who does not know the
product as well as the writer.
So runs the hymnbook. The problem is that such boilerplate ignores the
fact that "easy to understand" is not itself a simple concept. The
fact is that some programmers are so brutalized and so subject to food
and other forms of addiction, that they labor to understand almost
anything, and efforts to clarify only confuse. They then use a
remythologised Urban Legend of "structured programming" to mean
"something that fits my prejudices and that I understand without
mental effort".
[Such as an implementation of signum that divides by zero when x is
zero.]
It would take a Habermas to show the fundamental contradiction in
software development, but I shall try. Habermas, a German philosopher,
draws a distinction between language used to make money (the language
of business) and language used when discussing affairs between friends
in what he calls "civil" society, a conversation where we try to
arrive at scientific or political truth without worrying about
economic success or failure.
Gerald (The Psychology of Computer Programming) Weinberg discovered
that in the "structured walkthough", the fair, dialogic, and open
conversation typical of friends agreeing, or agreeing to disagree, in
a sidewalk cafe was more productive in commercial software than the
hiding of information, personality destruction, and competitiveness
characteristic of business.
Years later, "open source" found that people were more productive when
coding for free and not looking over their shoulders to see if their
fat salaries were under threat, since the fat salaries weren't there.
In parts of open source, Habermasian civil society makes the process
fairer and less competitive, a common search for truth (something that
works).
Dijsktra, finally, discovered that debugging is a matter of applying
the scientific method; but the prevelance of Fundamentalist religion
and various forms of cultish denial (Holocaust denial, denial that
Shakespeare wrote "Shakespeare", Creationism and Zionism) amongst
technical people show that they are unclear on the concept of
scientific method and prefer a sort of folklore in programming, which
includes saws such as "keep it simple", saws that have the property
that their referents are vague.
Owing to the fact that most software conversations take place in the
competitive business arena, they are ridden by hypercompetitive
nastiness, which also infects these conversations here because so many
people crawl in here brutalized by capitalism and anxious to retrieve
their lost manhood by being bullies. Also, it's quite possible that
some people, who post compulsively and continuously, are being paid to
trash this conversation, transforming it from an adult, civil and
Habermasian search for agreement and truth to howling at the
moon...lest these threads turn out to be a basis for labor solidarity
and organization.
Of course, most Americans and UK subjects have no concept whatsoever
of Habermas' distinction between biz-talk and a common search for
truth in civil society. They are taught instead that in the modern,
globalized-capitalist world, enormous fortunes are made by brilliant
men far more talented than they, despite the fact that Tim Berners-Lee
really screwed up the design of the Internet and that Bill Gates could
not even program Donkey Kong.
Furthermore, popular culture (cf Zizek) can be usefully viewed as
proposing to destroy the space of civil conversation, and replace it
with dreams that in Adorno's words have no dreams: movies, substance
abuse and trivial bullshit instead of a common search for truth.