Slashdot Mirror


What I Hate About Your Programming Language

chromatic writes "Perl programmers like punctuation. Python programmers like indentation. Every programming language has its own syntax, stemming from its philosophy. What I Hate About Your Programming Language examines the issues that shape languages as they grow. It's not advocacy, I promise."

3 of 800 comments (clear)

  1. Self-documenting? by steveha · · Score: 5, Interesting

    Better would be languages which are self-documenting...

    There is no language that will force perfect code. There is always room for a poor programmer to produce hard-to-understand code. Functions that do two unrelated things, confusing control flow, bad variable names, broken code that was repeatedly patched instead of being cleaned up... the possibilities are endless.

    Nonetheless, some languages have been designed with self-documenting code in mind; sometimes it even works.

    If you look at languages like COBOL, they have long descriptive keyword names designed to make the code easy to read. But you get tired of looking at those long keywords.

    I haven't used ADA, but I understand that it is somewhat designed for self-documenting code, and that as a result you are hemmed in on all sides by language rules. (ADA fans please comment here.)

    The best language I have seen for this is Python. As a rule there is exactly one way to do things, so you don't trip over obscure hackish tricks that you have to puzzle out. The language doesn't force self-documenting or comments, but it does force indentation; everyone indents their Python pretty much the same (compare with the mess that is C indentation). The language is high-level enough, with lots of libraries, so you don't need to write 10 lines of code just to do one simple thing.

    Python was designed by a guy who is both a computer geek and a math geek. The math geek in him led to a very tidy language design, and I like it very much. I think schools ought to be using Python to teach introductory programming classes.

    steveha

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely
  2. Re:At the end of the day... by RevAaron · · Score: 5, Interesting

    Smalltalk is quite self-documenting. I'm sure most C/C++/java/Perl/Python programmers think you're joking when you talk about a "self-documenting language," but they're real.

    A simple langauge plus a decent code browser can equal a self-documenting language. Methods are organized into logical groups (e.g. "accessing" "initialization" etc), and clicking on a category will tell you the methods there. Especially when there is a tradition for short (7 lines or less is the rule) methods, as in Smalltalk- you can usually see what the entire method is doing just by looking at it, if you cannot guess at what is is for by looking at the name.

    People may think this is an exageration, especially if they're used to systems that require various man pages, books, and on-line class lib references just to write some code. Other than one book on Smalltalk style, I've not read any books on Smalltalk. I read some tutorials when I began, but after you learn the basic syntax [1], the very basic ideas [2], and especially, how to browse classes, you learn as you go, finding out classes to use as you need them.

    [1] All of Smalltalk's syntax can be summarized as-
    a := 1. ":= is assignment"
    obj + 2. "a binary message"
    obj methodName. "a unary messsage"
    obj methodName: argument. "a keyword message, unlim keywords"
    [ :a :b | a + b ] "block creation- a block closure, aka anonymous subroutine"

    [2] You don't even need to know anything about OOP or OOA/D- simpyl the rudiments of *object-based* programming... simply understand that an object is a chunk of data that can do certain things.

    --

    Working toward a usable PDA environment in the spirit of Newton OS: Dynapad
  3. Actually PHP is a hack of a language by Imperator · · Score: 5, Interesting
    I code PHP every day, so I've become quite proficient at it. However, I constant find myself horrified at some newly-discovered inconsistency in its library. The language itself is not so terrible, but its library is a beast.

    As a particular example, take PHP's error handling. The language has no real exceptions, which is forgivable--but it insists of making up for it by faking them.

    It has something akin to sigaction(), but much less powerful. It allows you to provide one function to handle all errors, except for some that PHP insists on handling itself. At least that function can switch on the error, right? Nope! There are only 5 different error codes which your code can catch, only 3 of which you can actually throw (again, with a function instead of a language construct).

    And if you thought this was bad, try the error handling in the library. Each set of functions seems to have its own function to check for errors, and you have to repeatedly check the manual to find out how a function indicates failure. I've seen the following different methods of indicating failure:

    function returns FALSE

    function returns TRUE

    function prints a message to the browser

    function returns 0

    function returns 1

    function returns nonzero

    function returns negative

    call another function to find out

    functions returns something that can be fed into another function to find out

    function raises an error condition you can catch (through fake exceptions described above)

    function raises an error condition you can't catch

    pass in a variable by reference and the result will be there

    check if the returned array is empty, and if it is use a different function to find out whether that indicates an error or just a (legitimate in context) empty array

    Don't even get me started on the naming conventions of functions, or the ordering of their arguments. (Check out the array functions if you want some good examples.)

    PHP is a language that was designed for small, simple CGI scripts, and it does this well. It does not scale. PHP was never meant to be used from the command line, but how else can you write a cron job to do some nightly maintenance? (Write in another language? Sure, and give up all the libraries you've written for the project.) Sure, you can use lynx -dump http://example.com/nightly.php >/dev/null, but then you have to make sure no one but you can use that script, and it's just generally an ugly thing to do.

    For all of its faults (and it has many), one of the thigs Perl does well is provide actual language features for things like merging arrays, sorting arrays with a user-provided comparison function, or declaring a variable with loop scope. PHP's libraries keep growing, which is nice, but the language itself is too small and too limited. I don't want to use library functions for everything, nor do I honestly care whether the language is even context-free. I just want a lanugage that doesn't suck.

    </rant>

    --

    Gates' Law: Every 18 months, the speed of software halves.