Wednesday, November 08, 2006

Wish I wrote that...

This was really insightful I thought..

Be careful who you learn from - indeed.



Blogger Joel Garry said....

"if I can't remember it, its probably not worth reading it regularily".

Hmmmm. Who was that guy again? Was he looking at my shoes?

Wed Nov 08, 08:45:00 PM EST  

Blogger Peter K said....

Now I know what a "quine" is even though I can't find any formal definition for it.

Interesting...and although you cannot truly generalize but true in a lot of cases.

Wed Nov 08, 10:41:00 PM EST  

Anonymous Jonathan Lewis said....

I think the premise of the article is sound, but the arguments presented poor - for example:
"a very talented programmer I once knew taught me to always write conditionals in reverse order, for example... if (0 == i) instead of if (i == 0)".

That's awful advice from a logical perspective, and a programming hack that was only needed (I think) to work around a bad definition in the C language. It's been more than 20 years since I last wrote some serious C, but I vaguely recall using '.eq.' for '==' and then defining a macro so that the compiler would convert '.eq.' to '=='.

The blogger seems to have learned a very bad practice to solve a temporary, localised, problem - and that's a phenomenon we see a lot of among the self-proclaimed experts in the Oracle world.

Conversely - the while(i++) used to be more efficient than any other option (due to the quality of the compiler) in the days when people needed to write efficient code. But the blogger rejects it as bad, I guess because he finds it hard to interpret fluently (and that's very good reason to avoid it, of course, but the justification/balance is not given).

Neither coding example is 'better' or 'more talented' than the other - unless the rationale is made available. And that's the clue to the good teacher - they try to address the question "why" rather than supplying simple "what to do" directives.

Willard Quine, 19th Century philosopher. Spent time considering the effect of prepending a phrase with itself as a noun-phrase, e.g.
"is not a complete sentence" is not a complete sentence.
This may seem a daft exercise at first, but I believe the technique turned out to be critical to Godel in proving the Incompleteness Theorem.

Thu Nov 09, 03:25:00 AM EST  

Blogger Bill S. said....


"Wish I wrote that...."

You did, just not in the same words. ;-D

Jonathan - Nicely put, and I now know more about quines than I wanted to. ;-D

Bill S.

Thu Nov 09, 10:05:00 AM EST  

Blogger Vidya Balasubramanian said....

"Be careful who you learn from" - well said. Hopefully with the Internet information age we will all be conscious and cautious learners. Wish I had this insight years back – back then , the other side of the globe when information was not so easily available – teachers were more like lawyers or realtors we thought they knew and had access information that none of us had……..and therefore knew what they were telling us

Thu Nov 09, 11:45:00 AM EST  

Blogger Des Traynor said....

Hi Tom, thanks for the link.

Jonathon Lewis, I disagree strongly with your arguments. Firstly I was referring only to the C programming language, and as a student I wasn't aware that I could write a programming macro to perform a search and replace on my own custom definition of the language. If I was, it would still only protect me in certain circumstances, when programming in my own environment.

I am not a self proclaimed expert in anything, so try not to liken me to whatever nuts you have met in the Oracle world.

while(i++) is horrid code in any language, implicit conversions to of ints to booleans don't save you much in terms of optimization when you get down to the machine code level, so I can't see any argument that makes it in any way worthwhile.

If you read the entry "Magicians Don't Teach" you'll see more of why I dislike using tricky coding styles that only work in C, and are difficult to read.

So I'm pretty much in total disagreement to your conclusion. I was saying that writing C code in a if(0 == var) manner is a good habit that avoids a lot of trouble, and writing while(i--) is bad cause it's barely legible, and saves piss all at compile time. You disagree and thats good, cause it's more interesting to hear disagreements.


Thu Nov 09, 01:08:00 PM EST  

Blogger Guy Barry said....

What do you say,lets agree to disagree?

Thu Nov 09, 02:04:00 PM EST  

Anonymous Jonathan Lewis said....


I do hope you're not in total disagreement with me - after all my opening line was: "I think the premise of the article is sound".

Can I just point out one thing - your article states "a very talented programmer I once knew taught me to always write conditionals ..." but in your rebuttal you are now saying "I was only a student ...". Your talented programmer presumably wasn't, yet he/she taught you to do something that was logically incorrect and would make your code harder for someone else to read.

I wasn't intending to suggest, by the way, that you were proclaiming yourself an expert; rather that you had picked up a bad habit from someone you considered to be an expert - and that's what happens a lot in the Oracle world.

Consider this as an alternative approach to reversing your conditionals:

# Program header file
#define equals ==

# Program body
if (var equals 0)

I think I did something a little more subtle when I was programming C, but it's so long ago I can't remember what it was any more.

The point about while(i--) isn't that it makes the compiler go faster; it helps primitive compilers put "i" into a register instead of main memory, which has an impact on runtime if you are trying to write code for real-time systems on the hardware built a quarter of a century ago.


Thu Nov 09, 03:35:00 PM EST  

Anonymous Padders said....

I know this is more about quality of education than quines, but I recalled a quine thread on OTN a while back that may be of interest.󭋬

Thu Nov 09, 03:49:00 PM EST  

Anonymous Gabe said....

So if the talented programmer had a solution for the "accidental assignment bug" in cases like var == cons … what did he/she do for var == var?

Thu Nov 09, 03:50:00 PM EST  

Blogger Des Traynor said....

Thats a fair point Jonathan.

The guy I'm referring to was a lecturer, back when I was a student, in 1999. So obviously I wasn't in much of a position to know the right from the wrong, or the talent from the hacks and had a tendency to follow blindly, in some cases. My main basis for following this guy was that he had wrote a lot of code, had contributed to OSS, and the like. More than you usually get from a college lecturer I guess.

However, having wrote if(i=0) soo many times, the alternative seemed to make a lot of sense to me. The macro you've provided does make sense I guess, and it is a better option. I don't write too much C anymore (luckily I guess :) ).

However having spent a lot of time rewriting while(i--) to say while(i!=0), it got to the stage where I figured screw it, it's a silly way to write code. I accept that back in the day it would be an optimisation, but I think in this case it was being used more in a "look how clever I can be" sort of manner. Similar to the "I can do that in 1 line of Perl" sort of boasts. I don't think there is much reason for teaching students that sort of code, or even exposing it to them while they are still learning.

Thank you for informing me, it's good to get criticism, its the only way to improve.

All the best,

Thu Nov 09, 08:13:00 PM EST  

Anonymous Jonathan Lewis said....


Thanks of the comment; and thanks for the reference the pointer from your site to the summary of Bloom's Taxonomy

Viewed from the speaker's angle it really makes you think carefully about what you're saying and what you're trying to achieve by saying it.


Fri Nov 10, 02:23:00 AM EST  

Anonymous Sokrates said....

Anyone knows nice quines

- in SQL ?
- in PL/SQL ?

First idea is
SQL> select sql_text from v$sqlarea where sql_text like '%this one produces a quine%' and rownum=1
2 /
select sql_text from v$sqlarea where sql_text like '%this one produces a quine%' and rownum=1

Fri Nov 10, 05:29:00 AM EST  

Blogger Thomas Kyte said....

the forum link above had a sql quine in it.

Fri Nov 10, 07:35:00 AM EST  

Anonymous René Nyffenegger said....


If a quine is "a program that prints its own source code without any access to it).", then your
statement is not really a quine,
because v$sql holds the source
code of the query.

I still liked it, though!

Fri Nov 10, 07:43:00 AM EST  

Anonymous Sokrates said....


you are right, of course !

beside the link Thomas gave us (thanks!), which
leads to a real quine (working with REPLACE, very cool), I didn't find any
other on the net so far !

Fri Nov 10, 08:31:00 AM EST  

Anonymous Sokrates said....

hust thought about

SQL> create view quine as
2 select 'select text from quine' as text from dual;

View created.

SQL> select text from quine;

select text from quine

but this also has to access to its own source code, hasn't it ?

Fri Nov 10, 08:36:00 AM EST  

Blogger Robert Vollman said....


I think (0 == i) is a good practise.

I don't consider it a "hack" nor do I consider it logically awful. I really don't see any harm or confusion that will cause.

I think macros are generally bad practise. Programmers have to go hunting for your macros. But yours looks harmless/obvious enough, so I have no issues with your particular example.

Just throwing my voice in.


Fri Nov 10, 10:42:00 AM EST  

Blogger Thomas Kyte said....

I'll weigh in on the

if (0==i)

thought. When I saw it, I first thought "hate it, very different from normality, backwards"

then I thought about it and thought, "neat idea, I sort of like it"

but then came to the conclusion that my brain would never be able to do it - I am so programmed to code:

if ( i==0 )

So, if it was a generally accepted practice - that would be one thing, as it is - neat idea, but probably won't catch on at this point in time.

but it was the PREMISE of the article "be careful who you learn from" that appealed to me.

Fri Nov 10, 11:31:00 AM EST  

Anonymous Anonymous said....

Interesting how your main page makes "zero==i" look like "o==i" instead of "0==i" ... one can see the difference in the Post a Comment page though. The whole thing was about comparing a constant to a variable ... not variable with a variable. Them fonts ...

Fri Nov 10, 01:42:00 PM EST  

Blogger Joel Garry said....

There will always be tension between generally accepted best practices and critical learning. It takes a lot of time to evaluate things critically, and best practices are a distillation of experience, which may be skewed by misapplication of previous distillations.

For example, C may be a good language for writing operating systems (or maybe not), over time a body of practice develops which is a combination of whatever people have figured out that works, some critical analysis, some analogization from other languages, and guesswork. Then a large scale adoption in schools leads to large scale usage of writing C for applications, and derivative languages for the paradigm of the month, since C is now common knowledge on a large scale.

As Des said here, students aren't in "much of a position to know the right from the wrong, or the talent from the hacks and had a tendency to follow blindly."

I'd add, often the best teachers in the long run are those who don't blindly follow the status quo. But what are the odds that their viewpoint will be the status quo in a time frame suitable for the student? It can take decades, or may never happen at all as everyone turns to the easy answers. (Fortunately Tom and Jonathan are notable exceptions to this - but there are many more who may be nutcases coming up with "new paradigms.")

In general there just isn't that much choice in who to learn from.

Sat Nov 11, 02:02:00 PM EST  


<< Home