views:

4291

answers:

52

Excluding Whitespace, BrainF*ck (and all those other languages not designed for practical usage), and assembly, what do you think is the most difficult real programming language to write readable code in, and why?

I find that I'm very comfortable reading code with C/C++ style braces and brackets. I can easily scan a file for method and class definitions, however in a language which does not use braces I find it extremely hard to read, eg: BASIC variants, specifically Visual Basic.

+31  A: 

brainfuck.

forrest
+5  A: 

I agree. VB is for me the most difficult language to read... even though it was designed to be exaclty the opposite

Juan Manuel
+3  A: 

Brainfuck, the esoteric language in Klingon, the Shakespearian esoteric language...

As for "real" languages, I find curly brace languages the easiest to read, followed by languages that use keywords instead of braces (Ruby comes to mind, using things like END LOOP or something like that), followed by languages that use indentation for code blocks.

Thomas Owens
In ruby, code blocks can be delimited with either 'end' or braces most of the time. The only time I can think of where a keyword is forced is for a do-while loop.
nilamo
"that use indentation for code blocks" - Guido is watching you.
new123456
+4  A: 

Perl, especially when written by my old boss.

nachojammers
More people should realize that languages such as Perl, PHP, Lisp, ... are write-only languages. Funny to see how some people seriously try to "master" such languages, believing that this would lead them to the programming-nirvana.
ivan_ivanovich_ivanoff
+6  A: 

Ook!

danb
If only orang-utans could actually program in it....... I want to see hello world in it.
Mark
+4  A: 

I find that it's easy to build systems that are hard to figure out in C++. Most of this is due to operator overloading; it's great for certain cases, but I've seen some class libraries that have used operators in really wrong ways. Templates also can uglify code a lot, although some of the type inference tweaks being added in C++ 0x will help (they overload "auto" to declare variables where the type comes from the initializing expression). If you're digging into an unfamiliar C++ system, it's essential to have some sort of good IDE with a cross-referencing database just to have a chance to decipher all the method references.

Ben Combee
+12  A: 

(((((Lisp))))))

Michael Sharek
Unable to resolve symbol: Lisp in this context. Unmatched delimiter: )
Kent Fredric
If I could, I would've voted that comment up... :)
roe
@roe woot, now you can.
Adam Backstrom
+17  A: 

I think it is subjective - you can write good and bad code in pretty much any language. Spending most of my time with PHP, C and Objective C, I like to see brackets in code to make control structures, function definitions and such clear at a quick glance. As a result, I find languages like Python difficult to read, even though they are supposed to be easier to create clean code with through their requirement for tabs/whitespace.

Objective C has some nice features with the @property / @synthesize which gets rid of a lot of generic setter/getter code. Shortcuts like that are very handy and make code cleaner, and speed things up!

DavidM
+11  A: 

Not exactly a language but I find Regex very unfriendly to read.

brendan
You should look at Perl6's version.
Brad Gilbert
Some regex dialects allow comments and whitespace, which is *quite* readable -- see example above.
BobMcGee
Yeah.... I'll 2nd that. It's pretty easy to write once you know it, but I still wouldn't want to re-read anything I wrote.
Mark
+3  A: 

I think it is ASP

Niyaz
+1  A: 

rpg by far wins for me although it is getting better with rpgle and free format.

Here's a good example of an early version of rpg

Mickey
A: 

Perl is incomprehensible to me because it's a language I haven't learned, like Thai, Greek, or Klingon. Looks like cartoon characters swearing. :)

Steven Murawski
+1  A: 

I second LISP. Had a class in college that used Scheme which is a LISP Dialect. The Polish (prefix) notation and seemingly infinite parenthesis make it a drastic departure from the C and Java I'm used to.

Cade
I'd say Java. Had a class in college that used Java. The "sometimes-prefix sometimes-infix" notation and seemingly infinite grouping characters of all kinds `()[]{}` which C and Java use make it a drastic departure from the Lisp I'm used to.
Ken
+4  A: 

Assuming non-malicious code, I can read C, Pascal, VB, Java, C#, python, C++, SML, Haskell without colour coding. I can't do the same for lisp or scheme; those ones need assistance from the editor. So they "win", as far as I'm concerned.

DrPizza
+7  A: 

I'd vote for APL.

Forth is a contender as well.

Kristopher Johnson
+3  A: 

This is C and it prints the words of 'first day of Christmas' (try it if you don't believe me). Any questions?

main(t,_,a )
char
*
a;
{
       return!

0<t?
t<3?

main(-79,-13,a+
main(-87,1-_,
main(-86, 0, a+1 )


+a)):

1,
t<_?
main( t+1, _, a )
:3,

main ( -94, -27+t, a )
&&t == 2 ?_
<13 ?

main ( 2, _+1, "%s %d %d\n" )

:9:16:
t<0?
t<-72?
main( _, t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# ){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c ;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/")
:
t<-50?
_==*a ?
putchar(31[a]):

main(-65,_,a+1)
:
main((*a == '/') + t, _, a + 1 )
:

0<t?

main ( 2, 2 , "%s")
:*a=='/'||

main(0,

main(-61,*a, "!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry")

,a+1);}
Ron Harlev
Yes, but you can write obfuscated code in *any* language. The question was about which languages come "pre-obfuscated". :-)
phyzome
I think we've all seen IOCCC.
roe
A must read for this is the reverse engineering and explanation of how it works: http://research.microsoft.com/en-us/um/people/tball/papers/xmasgift/
MBCook
@phyzome: I think there's a difference in code obfuscation due to bad coding and code obfuscation due to language features. You can write the first in any language, yes, but only with some languages you can do the second: C and perl are examples. It's hard to write the second class of obfuscation with python, fortran or lolcode.
Stefano Borini
+56  A: 

I find it easier to read languages which use brackets for breaking up blocks of code. For example C/C++, C#, D, and Perl.

The language which is in common use today, that I really find difficult to understand, is shell scripting. Plus the keyword you use to end a construct isn't always the mirror of the beginning keyword. I don't think anyone would use it if it wasn't already so widely used.

READABLE:

Perl

if(     $anything == 1 ){
    # some code
}elsif( $anything == 2 ){
    # some code
}else{
    # some more code
}

UNREADABLE:

Shell

if [ $a == z* ] # File globbing and word splitting take place.
then
  if [[ $a == z* ]] # True if $a starts with an "z" (regex pattern matching).
  then
    echo do-something  # But only if both conditions are valid.
  fi  
fi

I don't know about you, but I keep wanting to end the if block like this:

if [ $Jack && $Beanstalk ]
then
   echo plant beanstalk
fee fi fo fum

Further

Those people who automatically say Perl is a terrible language, generally assume that it is unreadable because they take one look at the Regex sub-language, and assume there is no possible way to rewrite it in a cleaner way. Which is completely wrong. The first thing you must learn is of the /x modifier, which allows whitespace embedded in the Regex to be used to separate out different parts of the Regex.

So we can turn this:

/^([+-]?)(\d+\.\d+|\d+\.|\.\d+|\d+)([eE][+-]?\d+)?$/;

into this:

/
  ^
    ([+-]?)        # first, match an optional sign

    (              # then match integers or f.p. mantissas:
         \d+\.\d+  # mantissa of the form a.b
        |\d+\.     # mantissa of the form a.
        |\.\d+     # mantissa of the form .b
        |\d+       # integer of the form a
    )

    ([eE][+-]?\d+)?  # finally, optionally match an exponent
  $
/x;

Which I might add (as far as I know) is not available in any other general purpose Regular Expression librarys, accessible within other languages. So in other words if you are using another language you are stuck with the first form, or you have to write significantly more code to achieve the same ends, which will be error prone. See here for more information.

Actually Perl can be very powerful, imagine running arbitrary code, from within a Regex. Don't worry you're not allowed to use interpolation with this feature, by default. Also this feature, last I heard is experimental, although I would bet it will stay in the language in some form or another. I know for a fact, it is a feature of Perl 6.

$x =~ /(?{print "Hi Mom!";})/;       # matches,
                                     # prints 'Hi Mom!'

Yet another useful feature:

Named back-references

( copied directly from perldoc perlretut )

Perl 5.10 also introduced named capture buffers and named backreferences. To attach a name to a capturing group, you write either (?<name>...) or (?'name'...). The backreference may then be written as \g{name} . It is permissible to attach the same name to more than one group, but then only the leftmost one of the eponymous set can be referenced. Outside of the pattern a named capture buffer is accessible through the %+ hash.

Assuming that we have to match calendar dates which may be given in one of the three formats yyyy-mm-dd, mm/dd/yyyy or dd.mm.yyyy, we can write three suitable patterns where we use 'day', 'month' and 'year' respectively as the names of the buffers capturing the pertaining components of a date. The matching operation combines the three patterns as alternatives:

$fmt1 = '(?<year>\d\d\d\d)-(?<mon>\d\d)-(?<day>\d\d)';
$fmt2 = '(?<mon>\d\d)/(?<day>\d\d)/(?<year>\d\d\d\d)';
$fmt3 = '(?<day>\d\d)\.(?<mon>\d\d)\.(?<year>\d\d\d\d)';

for my $d qw( 2006-10-21 15.01.2007 10/31/2005 ){
    if ( $d =~ m{$fmt1|$fmt2|$fmt3} ){
        print "day=$+{day} month=$+{mon} year=$+{year}\n";
    }
}

prints:

day=21 month=10 year=2006
day=15 month=01 year=2007
day=31 month=10 year=2005

If any of the alternatives matches, the hash %+ is bound to contain the three key-value pairs.

Perl 6

If we take the number matching Regex from above and convert it to a Perl 6 Grammar, it becomes even easier to read.

Perl 6

grammar Date {
  rule year{  \d{4}   }
  rule day{   \d{1,2} }
  rule month{ \d{1,2} }

  rule ymd{ <year>-<month>-<day> }
  rule mdy{ <month>/<day>/<year> }
  rule dmy{ <day>.<month>.<year> }

  rule match{
     <(ymd)>
    |<(mdy)>
    |<(dmy)>
  }
}

Note: I probably have some mistakes in this last bit of code, due to the Perl 6 design changing, and because I also haven't written a lot of Perl 6 code yet. It is also a bit of a contrived example

You would also need to change the for loop also.

for [qw( 2006-10-21 15.01.2007 10/31/2005 )] -> $d {
    if ( $d =~ Date.match ){
        print "day=$<day> month=$<mon> year=$<year>\n";
    }
}

prints:

day=21 month=10 year=2006
day=15 month=01 year=2007
day=31 month=10 year=2005
Brad Gilbert
I can do this whole post in one line :I love perl! Perl perl perl! A #1 go team hooyray we're the best!
Andrew Backer
meh. Whale guts - http://steve.yegge.googlepages.com/tour-de-babel
Evan
Yes, yes, PERL is the #1 readable language ;) Of course ;) Are you kidding? Scripting languages such as Perl, PHP, Shell are considered as write-only languages (because of their unreadability).
ivan_ivanovich_ivanoff
If you're read bad code, it'll be unreadable in any language. If you read well written code, any of the above will be perfectly readable. Perl is just fine.
Artem Russakovskii
This reads like more like a perl advertisement than an answer. Only the second block of code is relevant to the question.
orlandu63
Who says I can't advertise Perl, while also answering a question.
Brad Gilbert
Interesting. I certainly didn't know you could break up regexps like that before.
BigBeagle
Actually, I wasn't aware of a language that *doesn't* allow multi-line regexes. I'm pretty sure PHP does, but I think they based on that on Perl regexes, but C# does too, and that's it's own thing.
Mark
Python has supported this, too, since at least Python 2.0 (October 2000).
Ken
+1  A: 

I would have to say COBOL. I've never actually programmed anything in it, but given examples like:

Multiply Price By Quantity Giving SubTotal
Multiply SubTotal By TaxPercent Giving TaxTotal
Add Subtotal To TaxTotal Giving Total

As opposed to

Subtotal = Price * QUantity
TaxTotal = SubTotal * TaxPercent
Total - SubTotal + TaxTotal

Or Even

Total = Price * Quantity + Price * Quantity * TaxPercent

I'm not sure how anybody thought COBOL was a good idea.

Kibbee
"I've never actually programmed anything in it..." Then why comment like that? I never had a problem with COBOL. Worked with it for 20 years. It has made me a LOT of money in that time. Everything has its place.
Optimal Solutions
I thought the question was if it was unreadeable, not if it made you money.
fortran
You actually think it's unreadable? Yep, it's very long-winded, andMultiply Price By Quantity Giving SubTotal may take longer to read than Subtotal = Price * Quantitybut I've never done any programming in Cobol and I'm pretty sure I understand what it means.
HMcG
I think I'm with Kibbee on this one. Yes, it's readable, but it'll take you 2 or 3 times longer to read it and understand it than some simple mathematical expressions.
Mark
So use `COMPUTE Subtotal = Price * Quantity` instead. You don't *have* to write unreadable code just because it's COBOL. I can come up with obscure 3-line ways to do arithmetic in any language. There are good reasons to hate COBOL, and this is not one of them.
Ken
The example is very readable. It's not particularly **writable** though, is it?
DLH
COBOL is wonderfully readable *and* writable. In most languages, you write code; in COBOL you write a novel about code. Well, unless you really want to spoil it all with statements like `COMPUTE`.
Stan Rogers
+18  A: 

LOLCODE!

http://lolcode.com/

HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10?
YARLY
 BTW this is true
 VISIBLE "BIG NUMBER!"
NOWAI
 BTW this is false
 VISIBLE "LITTLE NUMBER!"
KTHX
KTHXBYE
Ed
Isn't that readable?
Filip Ekberg
I understood it pretty well.
lamcro
COBOL is more verbose than that
Alister Bulman
Readable, yet somehow still manages to be painful.
Jeffrey Hantin
Makes perfect sense to me. Compared to some things, that's positively pleasant.
Marcus Downing
I already see resumes: I has kitteh-fu skillz in lolcode. can has job ?
Stefano Borini
If you can't read this you should spend more time on /b/
bowenl2
Fake book cover: http://i.imgur.com/CInDF.jpg
Peter Mortensen
A better question is why does this language exist?
Jack
A: 

It still depends on whoever is coding. I mean, someone somewhere in the world can still understand LOLCODE or Brainfuck or Haskell or whatever..

I still vote for Brainfuck, though.

allan
+1  A: 

@Kibbee - The people who coded in assembler (the other choice of that era) thought COBOL was a great idea for the programmers who couldn't handle assembler. :P

My vote is for stuff like RegEx's or anything a programmer manages to code as unreadable be it C, Pascal, BASIC ... or even COBOL.

Peter Meyer
+81  A: 
slm
For anyone who's interested in APL, consider looking at J or K.
Terhorst
Wow, APL, J, and K are unbelievable. See the Wikipedia articles for more examples along these lines ...
A. Rex
Agreed. APL boggles my mind.
BoltBait
Definitely APL. If you want to go back and read it later (and understand it), you have to write comments that exceed the length of the code! I've seen a pair of functions that convert to and from Roman numerals. The conversion one way was was a 1-liner, and the conversion the other way used 3 lines.
RobH
Check out the APL keyboard: http://stackoverflow.com/questions/268751/what-ever-happened-to-apl/316354#316354
lkessler
I imagine it's more readable if you actually knew what all those symbols meant...... they have more meaning in math. But still, I completely agree with you :)
Mark
@Terhorst: you should have phrased it "For anyone who's interested in APL, consider looking at J/K." ;)
RCIX
That's like saying "You can't get any more unreadable than algebra" or "You can't get any more unreadable than Japanese". Yes, if you're not familiar with the characters, it looks like gibberish. And English looks like gibberish to someone who only knows Arabic. That just means the character set is unfamiliar, not that the code is unreadable. The language could also be unreadable, but having an unknown character set is orthogonal to this issue.
Ken
+1  A: 
OysterD
+6  A: 

I vote for Malbolge

André
Seriously. Nothing even comes close.
Daniel Straight
It's cheating if it was *designed* that way though! That makes it not a "real" language.
BobMcGee
+6  A: 

Piet. Hard to read, but easy to look at.

Paul Reiners
+4  A: 

In farcical languages, Ook! and Brainfuck are at the top of the list.

In terms of real languages, I would say that Perl is definitely a top contender due to it's support of so many different syntax methods. But really, a lousy programmer can turn any language into unreadable crap.

JMack
A: 

Give a million monkeys a million years on a million compilers and one of them will come up with a useful application in LISP.

About half of the rest will generate compilable Perl. For me, Perl wins hands down because I'm just a coding monkey banging away on my keyboard.

Jekke
+1  A: 

The Shakespeare Programming Language

eMilk
That is one weird language.
Brad Gilbert
A: 

regex by far.

<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>

what is that?

edit: formatted regex to avoid markup munging

The.Anti.9
Looks like it's trying to match an xml tag followed by any number of characters, with capture, but I'm not sure 'cos markdown seems to have munged it.How would _you_ write something that matches the same thing?
pdcawley
This looks like a job for /x.
Brad Gilbert
A: 

lisp-like languages really annoy me personally... as for intentionally unreadable languages my all time favorite is False, here's an example:

{
This one formats input and puts each line into a 4 columns wide row in an 
HTML-table. (Nice for automatically generated web-pages.)

Steinar Knutsen <[email protected]>
}

"<table>
"["<td>"[^$1_=~$[%$10=~]?][,]#%"</td>"]p:[^$1_=~]["<tr>
<td>",[^$1_=~$[%$10=~]?][,]#%"</td>"p;!p;!p;!"
"]#%"</table>
"
Toni Ruža
A: 

JOVIAL - which is used in some military apps.

With this language you can redefine every single keyword to be represented by another word - so you could change the whole look of the language.

MikeL
... and make it unmaintainable in the process.
Brad Gilbert
#define BOMB_IRAQ DROP_HUMANITY_SUPPLIES#define MISSION_ACCOMPLISHED STAY_2_MORE_YEARS
ivan_ivanovich_ivanoff
+1  A: 

I'd have to agree with APL. I even had a separate keyboard, labeled with the APL chars for working in it.

But looking at some of the examples here, I think the ultimate winner is "anything that has to output web pages" - take the language of your choice, and embed javascript and HTML, and it's going to be unreadable.

chris
+4  A: 

I suppose binary code.

+7  A: 

Even very well-written Scheme code can be extremely unreadable. For example, this snippet from a real-world Scheme application.

 ((n.lisp_token_pos_guess is to)
  ((year))
  ((p.lisp_token_pos_guess is sym)
   ((pp.lisp_token_pos_guess is sym)
    ((cardinal))
    ((lisp_num_digits < 4.6) ((year)) ((digits))))
   ((lisp_num_digits < 4.8)
    ((name < 2880)
     ((name < 1633.2)
      ((name < 1306.4) ((cardinal)) ((year)))
      ((year)))
     ((cardinal)))
    ((cardinal)))))))))

Andrew
After some training, you don't find it that bad.
Martin Cote
Far too many parenthesis.
Erik Forbes
I have the source code of Skynet - I'll prove it. Here's the last page of the source:))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
Alister Bulman
+1 Even though you stole that from bash.org
Zenshai
I've written far more Common Lisp than Scheme, but: is that an example of "very well-written Scheme code"? I'm not seeing it.
Ken
A: 

Lisp is pretty bad. But of the popular ones, I think perl is worst.

lajos
Perl, lol... I wouldn't even dare to call this a real programming language. A big pile of characters.
Turing Complete
A: 

Unlambda

Quoting the Unlambda Website:

. . . the language was deliberately built to make programming painful and difficult . . .

_ande_turner_
"the language was deliberately built to make programming painful and difficult" -- hmmm, I suppose you are referring to PHP rather than unlambda? ;)
ivan_ivanovich_ivanoff
A: 

A+. http://www.aplusdev.org/

You can see example code (for A+ and many other languages) here: 99 bottles

I use this to write trading systems. The code is utterly mind boggling at times. Definitely a WORN (Write Once Read Never) language. Would be interested to know if anyone else is using A+ or a similar APL derived language.

graveca
+2  A: 

Its got to be Whitespace

John Nolan
A: 

Applescript (though actually it's more unwritable than unreadable).

TeX is particularly awful, it's a macro language whose macros influence their own lexer at runtime...

And in the realm of esoteric languages, I think Piet is not a bad one.

Damien Pollet
A: 

It was said that FORTH was a write-only language. Of course, there's also BF, and APL, so that might not have been unique in that.

Alister Bulman
+4  A: 
Scott Evernden
Oh yes you can. hex; accesses the unicode character set.
Joshua
A: 

I know many people will disagree, but I find functional languages like Haskell to be very unreadable. It can look clean at first, like the one line quicksort, but any real code gets messy.

I think the most readable language is Python. I have never written a line of it, but I can easily understand large projects written in it.

Zifre
A: 

I had to do some Prolog programming in college. Not exactly hard to understand the concept of how the "facts" work together, but to try and actually write some sort of useful program with it I think would be pretty hard.

I think it depends on the level of complexity of the program.

Like a 5 line BASIC hello world program is very simple, but a 500 BASIC program with subroutines and gotos all over the place would be a nightmare. But the same holds true for a C++ program with tons of polymorphism, inheritance, templates and operator overloading.

Mxyzptlk
A: 

I can't believe MUMPS hasn't been mentioned yet!

fretje
A: 

Although I'm C++ programmer, after I once read pro AmigaE article, I realized, that braces are inferior to ENDFOR and alike statements. Compare:

while (foo) {
   bar;
}

with:

WHILE foo
   bar
ENDWHILE

Now some more complex example:

while (foo) {
   for(i=0; i<10; i++) {
      if(i%2) {
        print 1;
      } else {
        print 2;
      }
   }
}

vs.

WHILE (foo) {
   FOR(i=0; i<10; i++) {
      IF(i%2) {
        print 1;
      ELSE
        print 2;
      ENDIF
   ENDFOR
ENDWHILE

Imagine that between FOR, ENDFOR and other keyword pairs there is not one, but 100 lines. Is using ENDFOR-like keywords helpful? IMO it is.

I think that many C++ programmers, including my self, have something like "brace blindness", i.e. they don't read braces, but only the indentation. When there is some error reported, only then brain switches to "ok, lets parse braces now" mode.

Not only C++ suffers from this, but most of mainstream languages, like Java, Perl, PHP and so on.

A: 

i'd say assembly

Jeff
A: 

I'm gonna go out on a limb here and say that Objective C is not very pretty, especially when you're first trying to pick it up. Eventually it becomes clear but out of all the languages I use on a regular to semi-regular basis, I tend to dread having to wade through Obj-C code the most.

MattC
A: 

PostScript has a fairly bad reputation for readability.

Coding With Style
A: 

TECO macros

Datamation, July 1983, pp. 263-265: "It has been observed that a TECO command sequence more closely resembles transmission line noise than readable text. One of the more entertaining games to play with TECO is to type your name in as a command line and try to guess what it does. Just about any possible typing error while talking with TECO will probably destroy your program, or even worse - introduce subtle and mysterious bugs in a once working subroutine."

mpez0
A: 

Malbolge and Whitespace.

virious
A: 

APL is mostly esoteric, so it doesn't count. LISP is outdated.

So it's C++, I'd say.

Not only does it have a completely incomprehensive standard library, it also requires the developer to take care of memory management. What a waste of time.

Turing Complete
A: 

I think that both Intercal and Befunge come close to the top

PurplePilot