C obscenities – && and ||

C was never designed as a teaching language, it was designed as a systems language. Part of its issue is the fact that it uses so many shortcut operators in the form of symbols. Symbols confuse novice programmers, more so than words. Take for instance the use of block delimiters. In some languages such as Pascal, a block of code was contained within the words begin and end. This makes complete sense. C changed this to { and }. The problem with this is, it’s sometimes harder for novice programmers to recall whether one should use {, (, or [? Now they all have different names, (=parenthesis, [=bracket, {=brace, but that doesn’t make them any less confusing.

So it’s of no surprise to find && and || confusing as well. In C (and other languages), they represent logical and (&&), and logical or (||). In the first instance, they don’t correspond to the mathematical symbols for and and or, which are  and  respectively. Languages such as Algol used these symbols, but after that they were discarded. The other problem in C is the single operators & and |, the bitwise operators. They are too similar, and therefore too easy to get confused.

Ironically, C99 added facility to use the words and and or (and not), which just makes more sense.


One thought on “C obscenities – && and ||

  1. codeinfig says:

    visual blocks, frames, terminator keywords: any of these are easier for beginners than braces. keywords send a much clearer signal.

    indentation is a fuzzy one. visually it can make plenty of sense (like a visual block or frame) though in practice, a few struggle. im aware that indentation is doing really well, since python has replaced basic for beginners in most cases. keywords are stronger, they have substance: occasionally they can get slightly underfoot.

    for my educational language, ive mixed terminator keywords: one command is the default for all blocks, like in modula-2. but optionally you can use semantic hints: next after for, wend after while, resume as in try/except/resume. all of these translate to dropping the indentation level 4 spaces in python.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s