Slashdot Mirror


Favorite Programming Language Features?

johnnyb asks: "I'm curious what everyone's favorite programming language features are. I'm looking for both the general and the specific. I'm especially looking for features that few people know about or use, but are really useful for those who do know about them. What are your favorite programming language features?" "A couple of examples to kick off the conversation:
  • Continuations

    Continuations are very interesting, because they can be used to implement a number of flow-control features such as exceptions, coroutines, cooperative multithreading, and are better at modelling web interactions. This is a more general feature, but most people use these in conjunction with either scheme or ML.

  • Tuple-returning

    It is a huuuuge time-saver when languages like Perl allow functions to return tuples. Instructions like '($a, $b, $c) = $sth->fetchrow_array()' is a wonderful thing.

  • The flip-flop operator [Perl's '..' operator]

    Another perlism that I just think is cool. Read more about it here.

Okay, on to yours!"

58 of 312 comments (clear)

  1. Simple, OOP by agent+dero · · Score: 2, Insightful

    Object-oriented programming.

    For me it's just easier. ;)

    (Especially with XCode displaying it as a little blue box, it makes the concept easier to grasp for beginners)

    --
    Error 407 - No creative sig found
  2. That's obvious by krel · · Score: 2, Insightful

    Beautiful syntactical simplicity.
    *cough*C*cough*

    --
    karma: ouch!
  3. Easy. T-Shirt (C): by torpor · · Score: 2, Funny
    (void *)(void *);
    --
    ; -- the corruption of government starts with its secrets. a truly free people keep no secrets. --
  4. ON ERROR RESUME NEXT by Anonymous Coward · · Score: 2, Funny

    j/k

  5. anonymous inner classes by notyou2 · · Score: 3, Insightful

    I think's java's concept of anonymous inner classes is simply superb... it enables runtime aggregation of small objects while preventing you from having to create hundreds of named external helper classes to implement the behavior.

    It's certainly not an unknown feature, but I couldn't live without it.

    1. Re:anonymous inner classes by bigsteve@dstc · · Score: 2, Insightful
      Other programming languages do this so much better with different constructs. For example, "blocks" in Smalltalk, Ruby, or "currying" in ML, etc.

      Java's inner classes (anonymous or named) are not even first class! (Try coding an inner class that refers to a non-final attribute in its enclosing scope.)

      They are better than nothing though ...

    2. Re:anonymous inner classes by Bazzargh · · Score: 3, Informative
      Java's inner classes (anonymous or named) are not even first class! (Try coding an inner class that refers to a non-final attribute in its enclosing scope.)

      This isn't quite right. First off, they are first class, and you can refer to a non-final attribute from a named or anonymous inner class. What you can't do is refer to a non-final local variable from an anonymous inner class.

      The intended effect is similar to closures - variables referenced from the enclosing scope have the value when the closure was instantiated (see, e.g. Scheme) - except that unlike scheme, you can't modify the now-private copy. If you want a modifiable copy, you just make one, like so:

      final finalFoo = foo; Object bar = new Object() { private myFoo = finalFoo; // myFoo now acts as 'foo' would if this was // *really* a closure. }

      I'd agree that the construct sucks. I'd rather be in a language with closures myself.

  6. Re:Speed and RAM by sfjoe · · Score: 3, Insightful

    I feel the one of the strongest features of Java (or any language) is a standardized documentation feature (i.e. javadoc) and "readability". Being able to easily understand what another developer's intentions and "gotchas" are is invaluable. Perl, for example, can be obtuse without even trying very hard.

    .. and now, 50 rebuttals from the Perl crowd.

    --
    It's simple: I demand prosecution for torture.
  7. Many by Apreche · · Score: 4, Interesting
    First off I like nothing more than automatic memory management. Being able to forget about pointers and malloc and all that garbage makes programming infinitely easier and faster. I only write in C or assembly when I really really need the speed or when I'm at such a low level that nothing else is possible.

    Next I love ruby's block system, especially for stuff like this.
    myarray.each { |e| puts e }
    It comes in super handy for a ton of stuff. Especially when I'm doing XML.

    Also, there is another thing that I first discovered in python
    x, y = y, x
    Save me a temporary variable, w00t.

    Lastly, its not really a language feature, but in any object oriented language I love being able to serialize the objects. It's so simple to use pickle or any other serialization library and just write objects out to file or network. I never have to design a binary file format ever again. It's even better when you use Ruby and you can marshall objects into XML or YAML with a single method. Then you've got a human readable and editable file format that you can magically transform into objects again later. Super useful.
    --
    The GeekNights podcast is going strong. Listen!
    1. Re:Many by PSUdaemon · · Score: 3, Informative

      x ^= y
      y ^= x
      x ^= y

      bitwise, no overflow worries...

    2. Re:Many by Albert+Y.C.+Lai · · Score: 5, Insightful

      So then the perfect language is one where all the real programmers have done all the work for you, and you're just a little script monkey.

      To that I answer by quoting Dijkstra: "if we wish to count lines of code, we should not regard them as 'lines produced' but as 'lines spent': the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger." (EWD1036, page 11)

      And so for example even your 10-line, 40-token launcher is too long; its information content can be expressed succintly as "new Webserver(80)" or even "Webserver 80" in any properly designed language.

      When electronic calculators came out, accountants did not say "the calculators do all the arithmetic for you, and you are not a real accountant" (or did they?) Similarly for spreadsheet. The reality is, each time they are relieved of a chore, they find a more worthwhile thing to spend their time on, such as analysing various what-if scenerios, which had been intractible until the advent of spreadsheets --- a fine programming language in its own right. I now quote Asimov on the general idea: "The Machines are only a tool after all, which can help humanity progress faster by taking some of the burdens of calculations and interpretations off its back. The task of the human brain remains what it has always been; that of discovering new data to be analyzed, and of devising new concepts to be tested. ... I notice that capable men are still at a premium in our society; we still need the man who is intelligent enough to think of the proper question to ask." (The Evitable Conflict, can be found in I, Robot or other collections)

  8. Dreamed-of feature by Dr.+Weird · · Score: 5, Interesting

    This is less of a favorite feature, and more of a feature I wish we had. What about having the representation of the language independent of the code itself? I think this will eventually happen and could really revolutionize things. I believe the inklings of separating 'physical' representation from the code were there in some languages like Algol 60 and CS work in the 1960's, but it never caught on (perhaps hindered by other features of those works?).

    In a little more detail, suppose I write a C program. It will have lots of functions and conditionals with their "blocks" surrounded by braces.

    But what if I prefer my "blocks" to be started and ended by brackets instead of braces. Better yet, what if I am tired of typing these and would like indentation to control this. Or whatever -- start end commands, if you like. The point is that these are minor sytactic idiosyncracies, and we all have preferences. Why not store the code in an underlying format (XML would be okay, were it not for the bulk of it)? As long as there is a one-to-one correspondence between all possible representations, you could view it however you want.

    And so on for all syntactic features. Prefer "if-fi" construction to "if () {}"? Or "if ... then ..."? Better yet, really like Perl's "$_"? If you want it to be displayed like this, turn it on. Otherwise, say you don't like this feature, and it will automatically replace the "$_"'s (either implicit or explicit) with the variable to which it refers. Again, no problem.

    At this point, I feel like I am repeating myself, but let me continue for a little bit. It would let each user have his/her personal favorite representation. We already let them control the colors of their syntax highlighting, lets take it a step further.

    Hell, if you want to use a graphical viewer for those C programs, akin to LabView, go for it! Or (in my opinion) a much better graphical programming environment with a graph structure. The point is: you write it how you want and save it. It appears to another coder how he/she wants it to appear, but the content is exactly the same.

    In short: why isn't this done? It seems like a spectacular step in unifying programming languages a bit, and letting each user tailor his preferences while maintaining compatibility. As long as there was simple one-to-one correspondence, the translation from physical representation to underlying code and back would be quick and fairly easy to handle. Are there any modern projects which attempt this? Or *any* which attempt it with some success?

    On a somewhat related note, is it possible to put a "hook" to a comment in the code, and with the proper viewer have that comment displayed along with the code (say when you click the "hook", move your mouse over it, or drag the "hook" to a "comment box")? If this last paragraph doesn't make sense, please ignore it.

    1. Re:Dreamed-of feature by Dr.+Weird · · Score: 2, Interesting
      Imagine trying to read the code for a given app that had all sorts of bizarre preferences chosen. You would have to spend a lot of time just understanding what the hell you were looking at.

      No. In some sense, this is precisely the problem I try to avoid. The bizarre preferences were chosen because that programmer/company/standards bureau liked them and/or found them useful (hopefully). By storing the content of the program, and not their silly display preferences, it would load and present to me however I had it set up to display it, not according to their preferences.

      In other words, they have some silly COBOL-like syntax mixed up with graphical elements. But the presentation is not in the code . When I load the file, it would display according to my preferences, perhaps looking very C-like.

      I am not suggesting that the options/commands be different for each user, but rather that the presentation be different. In other words, this is the way to make there be least to learn on behalf of programmers. They don't need to know the other programmers' formatting rules, syntax, blocking options, etc. By having a 1-1 correspondence between representations, a representation suitable for you would be generated automatically.

    2. Re:Dreamed-of feature by Somegeek · · Score: 2, Insightful
      This is a terrible idea for maintenance. Imagine trying to read the code for a given app that had all sorts of bizarre preferences chosen. You would have to spend a lot of time just understanding what the hell you were looking at.

      I don't believe that you understand the concept becuase it seems that your argument doesn't apply.

      The whole point would be that you wouldn't see the idiosyncrasies of the way that he likes his code laid out, he would in essence give you compiled code and your development environment would display it for you however you liked to see it.

      For example, take the way people develop HTML code; some code it in notepad, writing the raw code, others use graphical interfaces with WYSIWYG software that just lets them edit the finished product, and others may use something in between, but its all the same code; displayed for you the way you like it; in text or graphically, or in windows with your toolbars and your highlighting preferences and tab spacing. What if you could only view it in the program that it was originally writen in?

      --
      And as you tread the halls of sanity, You feel so glad to be, Unable to go beyond. I have a message, From another time..
    3. Re:Dreamed-of feature by wayne606 · · Score: 4, Insightful

      Why in the world would any programmer care about whether they write "if { }" or "if ... fi", etc? I don't see the big advantage in indulging one's personal preferences about syntax. It's not like every person's brain has a completely different way of reading a program that makes it significantly easier to understand a unique brand of syntactic sugar...

      Sure, you can develop in your own special IDE that gives you your unique syntax. But don't you ever look at code together with other programmers who might have different preferences? Don't you ever view code published in magazines and on web sites that can't pretty-print to your specification? Training yourself to strongly prefer some kind of private language is not a very good idea.

    4. Re:Dreamed-of feature by wayne606 · · Score: 2, Insightful

      As long as the different representations are not too far off then it's probably not a big deal. But I work a lot together with other developers looking at the same code at the same time and if our dialects were mutually incomprehensible that would not be a good thing.

      Multiple representations can be very powerful - editing html code in parallel with the rendered version makes a lot of sense. But even in this case there is not a one to one mapping - it's not just syntax but semantics that vary (i.e. the rendered version has no semantics whereas the html or xml code may). I wonder if you could find two real programming languages that you could usefully and bidirectionally translate between and not lose a lot in the process.

    5. Re:Dreamed-of feature by gurps_npc · · Score: 2, Interesting
      I agree. But more so.

      We use graphical interfaces for a lot of things, we should use them for programming.

      SCREW the text editor based programming.

      What is this bracket crap to seperate codes?

      You want to seperate code? draw a circle around it. Variables that are in the circle can be accesed by code in the circle. Want to reference a variable outside the circle? Draw a line from it into the circle. And guess what - you can tell from the color of the variable name that it is not from that same object.

      I am trying to design such a language, but realize it is a big project. In fact it is two projects: 1) Designing the language (mostly done) and 2) Writing an open source graphical editor/compiler program that will allow you to write/code the program, save it, edit it, debug, and compile.

      reply to this post if you want more information

      --
      excitingthingstodo.blogspot.com
  9. Re:Speed and RAM by MooseGuy529 · · Score: 2, Insightful
    .. and now, 50 rebuttals from the Perl crowd.

    Yeah, Perl can be obtuse. Personally, I find that less-experienced programmers write clearer Perl code. Basically, there are many idioms and shortcuts that, used sparingly, can create extremely readable and intuitive code. However, just as using the same pronoun to mean several different things in the same sentence, using too many of these features makes code hard to read.

    Take $_, for example. I am relatively inexperienced at Perl (I have used it a lot, but I don't know a ton about it), and I usually don't use $_ unless I'm absolutely sure it will be what I think it is. Often, I prefer to use a specific variable name in constructs like foreach where the variable will be used several times in the loop, just because it makes things a little clearer.

    Personally, what I like about Perl is that, in the same way that PHP has functions for everything on earth, Perl has every data structure on earth built in. It's nice not to have to worry about how to organize data. Perl also just seems very intuitive to me. In my opinion, and inevitably opinions on this will differ, Perl makes concepts like pointers/references, hash tables/associative arrays, and arrays/lists simple enough that you can use them without extra effort, but versatile enough that you aren't stuck reinventing the wheel when you want a slightly different structure. That's basically one of the things that makes me prefer Perl to C--in C, I have to do so much stuff by hand: conversions, array insertions and such, but in Perl, everything does what it should without extra effort. Of course, Perl isn't for everyone or everything, since these built-in features come at a performance cost, but, for what I use it for (little scripts and such), it doesn't matter.

    Maybe the ease of working with data is what makes the rest of Perl programs so sloppy or cryptic sometimes... I guess when you have to create and manipulate data structures by hand, you can (and must) put more thought into what the data structures should look like.

    --

    Tired of free iPod sigs? Subscribe to my blacklist

  10. Stupid Lexical Scoping Tricks by Breakerofthings · · Score: 2, Interesting

    Closures and Currying are two of my personal favorites.

    Overloaded Functions are sweet.

    I am also quite fond of operator overloading.

  11. Favourites by E_elven · · Score: 3, Insightful

    Ruby blocks, lambda functions, lazy evaluation.

    And C++ :)

    --
    Marxist evolution is just N generations away!
  12. C pointers and arrays by Quill_28 · · Score: 3, Interesting

    Just to confuse people do this:

    main() {

    int x;
    int y[2];

    x=1;
    y[1]=10;

    printf("%d\n", y[x]);
    printf("%d\n", x[y]);
    }

    What will happen?

    1. Re:C pointers and arrays by ComputerSlicer23 · · Score: 3, Informative
      As I recall, in C x[y] and y[x] are defined to be identical. I believe you can do 1[y] and have it work. That's because a[b] is must be identical to *((a) + (b)). I'm over using paranthesis intentional. Because addition of a pointer and a constant is communitive, either one works. Because (1 + y) is a legal, and returns a pointer it works.

      Personally, I think it's a completely crappy thing. You should get an error telling you: "Attempting to use a constant like a pointer".

      So it should print out "10\n10\n";

      If that's an ANSI C complier: you should get a warning about no return in main, an illegal declaration of main, and an unknown function printf. You might get away with main, because I believe all functions implicitly return an int.

      Kirby

    2. Re:C pointers and arrays by Quill_28 · · Score: 3, Interesting

      You are correct. Thee compiler just sees memory.
      The x could also be a double.

      double x; won't change a thing

      One another interesting thing:

      the x[y] line compiled into assembly(using gcc non-optimized) will use less lines of code than y[x]

      Optimized they use the same.

      Learning this stuff actually gave me a much better understanding of pointers and arrays and their relationship in c.

  13. Self-execution by BollocksToThis · · Score: 4, Informative

    My favourite thing is languages that can execute strings of their own code.

    For example, clipper can do this via blocks:

    cVar := &("{ || nVar += 43")

    Python has the same thing via "exec":

    >>> b
    NameError: name 'b' is not defined
    >>> exec "b=2"
    >>> b
    2

    This means you can build up strings of code at runtime and execute them, or store field-specific database logic in another database table, and fetch it when needed.

    C# is not quite so convenient - you have to build up a complete class and compile it, but it can all be done in memory at runtime so it's just a little more work. Clipper and python can both affect the current scope directly (which can be both bad or good, I suppose).

    I believe ruby has blocks similar to clipper (probably better), but I don't use it, so I'm not sure. I also don't use perl, so I have no idea if it supports this...

    --
    This sig is part of your complete breakfast.
    1. Re:Self-execution by BollocksToThis · · Score: 2, Informative

      I'm not sure what you mean by 'valid', but I'm going to go with 'useful'.

      Say you have a database with multiple tables that all require user data entry. You can write code for each and every data entry screen (apparently the "visual basic" school of thought), or you can write a generic data-entry screen and include pieces of code for specific field validation in the database itself - so in effect, based on structural tables, the program builds the correct code for each screen. This also saves having to distribute a new version of your app every time you update or add a new table.

      Another good reason might be embedding pieces of code in an XML document or some such, but that seems a little less useful than the database idea.

      --
      This sig is part of your complete breakfast.
    2. Re:Self-execution by turgid · · Score: 2, Interesting

      In the days of 8-bit micros, as games became more advanced, allegedly self-modifying code was used to get enough stuff in the sparse RAM available and for performance reasons when a dynamically-modified unrolled loop was required IIRC.

  14. Several: by twem2 · · Score: 3, Interesting

    Functions as first class citizens, that is functions can be returned from functions and provided as arguments as functions. The basis of the functional paradigm and it makes life much much simpler.
    Pattern matching (some ML:)

    fun has_a [] = false
    | has_a 'a'::_ = true
    | has_a _::xs = has_a xs;

    Simple elegent functions requireing much less if_then_else's.

    Automatic garbage collection and bounds checking: enables me to write the code to do the job, not the memory management.

    Polymorphic typing: I can write general functions:

    fun contains x [] = false
    | contains x x::_ = true
    | contains x _::xs = contains xs;

    That will work with any type for which equality is defined.

    These are the reasons I hate C for general programming. The most important thing is efficient algorithms, without them no amount of low level optimization will help. With good algorithms, functional languages are now normally at least as fast... (and much much easier to debug and even verifiable).

    From non-functional languages, the object model is wonderful when used properly.
    Smalltalk & co's complete environment is a nice feature.

    I also have a soft spot for BBC BASIC with its speed, interactivity and simplicity. These are combined to allow windowed applications including at least one web browser and anyone can start programming simple programs (which is missing from most modern computers)

    Then there's the specialist languages. They have all sorts of nifty features (Mathematica is a good example) but I wouldn't expect them in an everyday language.

  15. Two words: string handling by Fished · · Score: 4, Interesting

    This is not the issue it was ten years ago, but one feature I absolutely want tightly integrated into my language is robust string handling. I still like perl's best (although perhaps only because I know it best). It simply seems to be more tightly integrated into the language as a whole.

    --
    "He who would learn astronomy, and other recondite arts, let him go elsewhere. " -- John Calvin, commenting on Genesis 1
    1. Re:Two words: string handling by Anonymous+Brave+Guy · · Score: 2, Insightful

      This is certainly true to a point. There are three basic kinds of data used throughout the programming world: text, numbers and logic (true/false). Pretty much any mainstream general-purpose language provides basic arithmetic and logical operators, and then an extensive library of more advanced mathematics functions. With strings, you often get basic operators, but beyond those there's a world of difference between providing a couple of upper-/lower-case conversions and having things like regular expressions supplied as standard.

      I think part of this problem is that what constitutes good support for strings isn't nearly as clear-cut as it is with numbers. Should we provide mutable and non-mutable types? How much should the regexes support? How do we deal with international issues?

      The latter is a biggie that I think will become more significant as time goes on and markets expand worldwide. Frankly, most languages suck when it comes to dealing with translating text and working with foreign languages. Consider how many provide a function mapping a character onto its upper-case equivalent; what it's supposed to do with a German double-s? Some languages get text support spectacularly wrong: C++'s much heralded IOStreams system codifies structure that should be data, and thus makes itself almost completely useless for any sort of internationalised development; all the locales in the world won't change the fact that different languages use different word order conventions.

      I think the underlying problem here is that text is fundamentally a complicated thing. Numbers, whether integers, fixed- or floating-point, have fairly well-defined rules (though as any numerical analyst will tell you, they don't necessarily match those of mathematics). Text, however, is on a different level. Even dealing with simple concepts like a case-insensitive comparison (assuming your input language even has cases in this sense) can be hugely complicated in practice, and complications like multiple word-forms multiply up to make it many times more difficult than typical mathematical code. It's more like expecting calculus to be built into a simple programming language, except that relatively few apps need that level of maths, while just about anything with a UI potentially needs that level of text support.

      Even if you're only dealing with manipulations of well-structured text in a single language, not all processing fits neatly into the idioms offered by regular expressions. Regexes are powerful tools, to be sure, but I think we're still waiting for the not-quite-silver bullet in text processing to arrive. I expect this to be something based on higher level concepts than a simple list of characters, possibly to be very demanding of processing power (though viable with tomorrow's technology), and probably to revolutionise the international development community like nothing we've ever seen before.

      So yes, I agree completely, good text processing is a very important feature for a programming language. If only any of them had it... ;-)

      --
      If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  16. This "ask Slashdot" is a concurrent "cross-post" by Paul+Bain · · Score: 4, Informative
    The poster, johnnyb, also asked this question on Advogato just a short time ago. It will be interesting to see the differences in the comments made there and the ones made here at Slashdot.

    Hey, johnnyb, where else have you posted this question? When you get answers, will you analyze them and post your conclusions? It could be interesting.

    --

    A lawyer & digital forensics examiner. Also an expert on open source software (OSS).
  17. Python's indentation syntax by mkcmkc · · Score: 3, Insightful
    Like probably most people, I hated Python's blocking-by-indentation syntax for the first few weeks. The column restrictions kind of reminded me of FORTRAN.

    But after the adjustment, I've truly grown to love its spartan clarity and simplicity. I can hardly stand to look at the redundant brace-littered syntax of Java, C or Perl now.

    Mike

    --
    "Not an actor, but he plays one on TV."
    1. Re:Python's indentation syntax by L1TH10N · · Score: 2, Insightful

      I was a bit sceptical of the Python method of blocking. Then I tried Python and really lost my tempo because I was so used to having closed braces. But after getting used to the Python way, I found it was so QUICK!

      --
      Yet another ironic recursive statement.
  18. Generic programming by LoveMe2Times · · Score: 4, Insightful
    The ability to do generic programming ala Boost is a great feature. Higher level languages are all about better abstractions, and generic programming is the best abstraction mechanism we've seen in general use since OOP. While OOP lets you encapsulate behavior and abstract over interfaces, generic programming lets you abstract over *form*. The significance is in the coupling. Generic programming allows much looser coupling between the writer of the generic library and the user of the library. A nice example is a generic "find" function:
    template <typename I, typename V>
    I find(I begin, I end, V val)
    {
    for (I it = begin; it != end; ++it)
    if (*it == val)
    return it;

    return end;
    }
    And here, you have captured the essence of a linear search. To understand what's going on, first know that I and V are arbitrary types that are inferred (at compile time) from the values you pass when you actually call the find function. For the generic find function to work, there are only a couple of restrictions on these types:

    1) I must be incrementable.
    2) I must be dereferenceable.
    3) You must get from begin to end in a finite number of steps.
    4) The type you get when dereferencing I (I's value type) must be comparable to V.

    Because of this, you can use the same find function to search through arrays, lists, vectors, maps, sets, strings, streams, and more, even though none of them inherit from each other or implement a common interface in the OOP sense.

    Additionally, there's no complicated syntax for the user of the library:
    int myarray[10] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55};
    int* p = find(myarray, myarray + 10, 8);
    if (p == myarray + 10)
    cout << "8 was not found." << endl;
    else
    cout << "The value of p is " << *p &lt&lt "." << endl;
    The great thing about abstraction is that it avoids duplication. Avoiding duplication lets you test/debug/prove correct once for greater reliability. Once you wrap your head around this simple example, you'll be surprised how deep the rabbit hole goes.
    1. Re:Generic programming by tchuladdiass · · Score: 2, Interesting

      One thing I've always wondered (since I mostly do C and not much into C++), how is this different than something like pointers to void in C? For example, the way qsort() works -- it can operate on any data type also.

  19. VB could use a little of that by pingveno · · Score: 2, Insightful

    Complete agreement! It's much easier and readable. It would be great if MS used that for Visual Basic, instead of the ugly End If construct. Much more comfortable for people who have to work with VB every once and a while. Some people get too attached to the English language.

    --
    "it's not about aptitude, it's the way you're viewed" - Galinda
  20. Simplicity, macros, conditions, multiple dispatch by Wolfkin · · Score: 2, Interesting

    I use Common Lisp.

    Lisp has almost no syntax, so it's extremely regular (barring exceptions like LOOP). Because it's so regular, it's easy to build macros that do powerful things.

    Macros can completely transform the source, at compile time, but with the full power of the language. Having that ability, together with simplicity, means that it's easy to build a complete mini-language for one's manager or web designer to use on the site, and easy for them to learn it, since you can explain the syntax in 5 minutes or less, and they don't have to learn 50 built-ins to use it.

    Common Lisp's conditions system not only allows exception-handling, like Python, but can also have an entire protocol for controlling execution flow built on it. More about that in the conditions chapter of Peter Seibel's forthcoming book.

    Lastly, having a generic-function-based object system means that a method can "belong" simultaneously to more than one class, at the same time. So, instead of having a method inside a class, you call a method with any number of objects of various classes, and it figures out from the type of the object what method to run, of all the similarly named methods. You can even specialize a method on a particular object or objects, instead of a particular class or classes! Multiple dispatch rocks.

    --
    Property law should use #'EQ, not #'EQUAL.
  21. Re:Speed and RAM by daviddennis · · Score: 2, Insightful

    What makes Perl sloppy or cryptic was that it was designed to make it easy to create quick hacks. Remember Larry Wall's Great Programmer Virtues: Lazyness, Impatience and Hubris. Perl was designed to make laziness easy; once Perl was written, you could be very lazy in your programming and things would still work.

    I'm an experienced programmer who's done relatively little Perl, although its use is increasing significantly in my work. Like you, I deliberately avoid use of $_ because I find it a very confusing concept, and I think it encourages the creation of confusing code. And even though you and I avoid it, the beginning Perl books are full of it and that makes it almost inevitable that most will use it.

    For some reason, I always, always hated that $ you have to put in front of variable names. I know it makes all sorts of interesting things possible, but for some reason I've always found it hard to read.

    Still, it's tough not to love associative arrays built into the language. It really makes a lot of normally tough things a snap, and I'm sure their coding of it is a lot faster than anything I would have done.

    D

  22. my favorite by scrytch · · Score: 2, Insightful

    Clean syntax. Not one that forces me to lean on my shift key and decorate my code with punctuation characters. The "noise" gets in my way so much that I can't even stand to program in perl anymore. I just can't take syntax like sub foo { dostuff @{$blah->{woof}}; etc... } anymore. Semicolons drive me bats.

    Python's ok. Tcl is closer to the ideal syntax, but oy what a feature poor language. Lisp's really nice. Forth would be about perfect, but it makes you work at such a low level most of the time (fact is, most people just don't build it up that much) that your code looks noisier than perl, more like APL even.

    Of course I like modern features, like automatic memory management, structured exceptions, first class functions, pattern matching, currying, asynchronous execution, concurrency, and so on. But I just can't express concepts well in a language that makes me clad every expression in so much syntactic scaffolding.

    --
    I've finally had it: until slashdot gets article moderation, I am not coming back.
  23. Perl's taint mode by babbage · · Score: 4, Interesting
    In the current issue of ACM Queue, Marcus Ranum makes an interesting case for Perl's taint mode in his article Security: The root of the problem -- Why is it we can't seem to produce secure, high-quality code?:
    Right now, the state of the art in software security is to pass your code through some kind of static source-code analyzer such as ITS4 or Fortify that looks for dangerous practices and known bugs. That's a great start, and, according to my friend Gary McGraw--chief technology officer of Cigital and author of several books on software security--who works with the stuff, it catches a significant number of potential security problems. But, as you can see, the compiler already knows a lot of what it needs to in order to make a good stab at determining what is being done wrong.

    One really neat concept is embodied in the Perl programming language--tainting. The idea of tainting is that the interpreter tracks the source of data and turns off dangerous operations if they are called directly as a result of user input. For example, when you're running a Perl script in taint mode, it turns on a lot of error checking before passing user-provided data to certain system calls. When you try to open a file for write using a filename that is tainted data, it checks to make sure the directory tree ownerships for the target directory are correct and that the filename doesn't contain "../" path expansions. In other words, the runtime environment tracks not just the type and value of the data but also its origin. You can imagine how nice this capability can be for writing server-side code or captive applications.

    Unfortunately, few programmers use tainting because it imposes an extra burden on the programmer, and it's sometimes difficult to figure out a secure way to get the job done. But what if we built tainting-type capabilities right into our runtime environments for C/C++? A simple high-value approach might be to modify I/O routines (read/write) to determine if they are connected to a socket from a remote system, and to do some basic checks on data coming across it, such as checking to see if the stack is altered across calls to certain functions following I/O.

    Ranum is citing this as an example of a way that existing tools -- such as GCC -- could be enhanced in such a way that programmers using currently popular languages (C/C++) would have a better security safety net without having to be retrained in practices (like checking for buffer overflows) that while obvious are still under-utilized in most software. The whole article is interesting reading, but this remark about Perl's taint mode seems like one of the best concrete examples of a modern protective language feature.

  24. True 64-bit Environment w/ Strong Primitive Typing by mosel-saar-ruwer · · Score: 2, Interesting

    This is what I want:
    1) An honest-to-goodness, floor-to-ceiling, cradle-to-grave, first-to-last, night-n-day 64-bit environment, with

    2) Strongly-typed data primitives.

    For the first criteria, if, at any point, you are forced to make contact with a 32-bit environment, then the platform fails the test.

    For instance, if the platform requires you to use either Java or SQL, then it fails.

    SQL fails because it is essentially an ASCII-based language that has almost no sense of primitive data types whatsoever, and its only undefined binary type, the binary BLOB, maxes out at 2^32 = 4 Billion bytes [so much for high-quality MPEGs of, e.g., Gone With The Wind].

    Java fails because, as recently as the Java 1.5.x Beta, it cannot take long ints as array indices. For instance, the following will not even "compile" [i.e. "javac," whatever that is] under the Java 1.5.x Beta:

    public class SixtyFourBit
    {
    public static void main (String args[])
    {
    long theLong = 1;
    theLong theLong += 1;
    System.out.println("theLong = " + theLong);

    double [] theDoubleArray = new double[theLong];
    }
    }

    So your "middleware" for this hypothetical 64-bit platform is forbidden to touch either SQL or Java.

    As for the strong data typing, I want the environment to be natively aware of

    A) IEEE 96-bit Extended Doubles
    B) IEEE 128-bit Extended Doubles
    C) [Bonus for Extra Credit] LabVIEW 128-bit TIMESTAMPs
    According to Professor Kahan, Matlab has [or has had] some serious problems here:
    http://www.cs.berkeley.edu/~wkahan/MxMulEps.pdf
    PDF DOCUMENT
    So: Any takers?
  25. Lameness Filter - Java Correction by mosel-saar-ruwer · · Score: 2, Informative

    The java code should have read as follows [I didn't notice that the shift operator had been caught by the /. HTML filter]:
    public class SixtyFourBit
    {
    public static void main (String args[])
    {
    long theLong = 1;
    theLong <<= 32;
    theLong += 1;
    System.out.println("theLong = " + theLong);

    double [] theDoubleArray = new double[theLong];
    }
    }

  26. unification as in prolog by egott · · Score: 2, Interesting

    Languages without "real" unification feel unexpressive or too low level. Whenever I program in something other than prolog (which is most of the time) I miss it.

    Example: [foo(A,x)|B] = [foo([p,q],x),C,d,e].
    which implies that A = [p,q], B = [C,d,e], and C remains unconstrained.

    --
    There are 10 kinds of people: Those that understand ternary; those that don't; and those that don't care.
  27. emacs solves that problem by mkcmkc · · Score: 2, Informative
    I use emacs, so moving blocks around with proper indentation is quite trivial. Even if I had to edit with Notepad, though, it'd be a small price to pay for the readability.

    Mike

    --
    "Not an actor, but he plays one on TV."
  28. Re:Speed and RAM by chromatic · · Score: 2, Insightful
    I deliberately avoid use of $_ because I find it a very confusing concept

    How ironic that you used the English cognate a mere four words later!

  29. You can simulate it in perl by bill_mcgonigle · · Score: 2, Interesting

    You could do this in perl if you wanted to. For instance, you can code perl in Latin. It's done using the Filter::Util::Call module, which lets you preprocess your perl code. Read Damian Conway's discussion about it. He gives a simple example using Klingon keywords and talks about implementing a Switch function in perl.

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  30. Re:Lists by bill_mcgonigle · · Score: 2, Informative
    Perl does have this, to an extent, but only on static lists.

    What do you mean by 'static lists'? Do you mean they're immutable?

    You can do
    push(@{$outer[$inner]},$value)
    to add to a list in a list. The syntax is tough, but I think it does what you mean. @{} is like a cast-to-list.
    man perlref
    should be helpful.
    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  31. reflection by agwis · · Score: 2, Interesting

    I'm surprised I haven't seen this listed yet. In java I use reflection often and at the cost of a little processing overhead, it allows me to add remove fields from a database with very little code change.

    I generally like to use struts in web applications and find I often have to tranfer values from an action form to a java bean and vice versa. Using the org.apache.commons.beanutils package it is incredibly easy to do this, and beanutils uses reflection to do this with.

    My second choice would be good regexp support. IMO, Perl is the best at this and I also like the Java regexp package in 1.4 as well.

  32. #1 Garbage collection by Simon · · Score: 2, Interesting

    #1 Garbage collection. a.k.a. automatic memory management. Not very sexy, but by far the single biggest productivity boosting feature of any language. I hate housework. It is just a waste of time.

    #2 No pointers, no buffer overruns, no memory corruption. Related to the first point. Memory corruption is just so hard track down. You can keep your pointers, I've already got an OS, I don't need to write my own. :)

    After spending years programing asm and C on a platform with no memory protection (Amiga), and then later C++, I think I've paid my dues here.

    #3 Stack traces. Not a language feature per se, but it takes a lot of the drudge work out of debugging.

    #4 Python's 'for' loop for iterating over the contents of a list or array:

    for thing in myarray:
    mutate(thing)

    It is easy to remember, easy to type, much easier to read, and you use it _all_ the time. Compared to the same code in C, C++ or Java, it is a godsend.

    #5 Dictionaries, a.k.a. associative arrays. It just makes a lot of problems much much simplier and faster to solve. Sure, most other languages have dictionaries available as a class, but when they are seamlessly built into the language you use them as easily as any other primitive datatype.

    --
    Simon

  33. Re:Speed and RAM by krakrjak · · Score: 2, Informative

    Perl has a standardized documentation feature: PODs. You can embed all manner of documentation alongside your code and then see the output (much like a man page) by running 'perldoc [perl module]'. If you use classgen you get a POD skeleton in your perl modules.

    I do agree that standardized documentation built into a language is quite powerful.

  34. Pascal and With operator. by rasjani · · Score: 2, Interesting

    I dont remember what the syntax actually was but when you defined a structure, you could point into its members with with.

    like if the structure had members x and y and structure was named coords you could do something like this

    var own_x;
    with coords
    begin
    x=own_x
    y=123.13
    end

    --
    yush
  35. Don't bash C++ by Chemisor · · Score: 4, Informative

    > #1 Garbage collection. a.k.a. automatic memory
    > management. Not very sexy, but by far the single
    > biggest productivity boosting feature of any
    > language. I hate housework. It is just a waste of time.

    Garbage collection does not free you from memory management. It simply converts one kind of problem into another: namely it eliminates accesses of unallocated memory, but it creates memory leaks instead. The thing is, it is not always easy to figure out when you no longer need a block of memory. That's with garbage collection it is supposed to be good practice to "free" your pointers anyway, by assigning NULL to them. Why they can't just use STL containers instead, I don't know.

    > #2 No pointers, no buffer overruns, no memory
    > corruption. Related to the first point. Memory
    > corruption is just so hard track down. You can
    > keep your pointers

    You won't have any memory corruption if you don't use arbitrary indexes to access your arrays. For example, when iterating over a container, you run your iterator from ctr.begin() to ctr.end(); no corruption possible. The other cause of memory corruption is using unverified data to directly access your arrays. That happens when you ask the user for a number and then use it to index; this is wrong in so many ways, I can't even begin to list them all. Verify your data, and you will not have any data corruption.

    > #3 Stack traces. Not a language feature per se,
    > but it takes a lot of the drudge work out of
    > debugging.

    #include
    backtrace_symbols()

    > #4 Python's 'for' loop for iterating over the
    > contents of a list or array:
    >
    > for thing in myarray:
    > mutate(thing)

    #define foreach(t,i,c) for(t i = c.begin(); i #5 Dictionaries, a.k.a. associative arrays. It
    > just makes a lot of problems much much simplier
    > and faster to solve.

    map m;

    > Sure, most other languages
    > have dictionaries available as a class, but when
    > they are seamlessly built into the language you
    > use them as easily as any other primitive '
    > datatype.

    You can use map as easily as any other primitive data type of the same category: as an array.
    m["january"] = 31;
    cout "january has " m["january"] " days" endl;

  36. Don't confuse people by Chemisor · · Score: 4, Funny

    Just because you can write it that way, does not mean you should. Should you blame makers of underware for letting you put it on over your clothes? Just because Superman can do it, does not mean you should.

  37. Re:This "ask Slashdot" is a concurrent "cross-post by johnnyb · · Score: 4, Interesting

    Actually what I'm wanting to do, eventually, is write a book about great programming constructs people have probably never heard of, or don't understand well.

    My last book took me 3 years to find the spare time to finish, so I don't suspect I'll have this done anytime soon.

    I was originally going to just analyze scheme's features, but then I realized that many languages have features that need to be recognized, too. my original outline was going to be:

    * Memory Management
    * Symbolic programming - an intro to Scheme
    * Functional Programming & Functional Programming Patterns
    * Closures and higher-order functions
    * Advanced Flow Control w/ Continuations
    * Compile-Time programming 1: Macros
    * Compile-Time programming 2: Partial Evaluation
    * Compile-Time programming 3: C++ templates
    * Lazy evaluation
    * Lazy data structures

    However, if I decide to open it up to other languages, I have no idea how I'm going to organize it or even how I will decide what to include.

    Anyway, it was originally posted just to Advogato, but then I remembered that the only threads on Advogato that get any real response are flame-wars, which is sad because Advogato could be a real cool place. Then I thought "you know, this would make a good 'Ask Slashdot' as well. However, I don't expect the quality of responses on Ask Slashdot to be as good, although I expect there to be a LOT more of them.

  38. My must haves... by Fahrenheit+450 · · Score: 2, Informative
    Things I've found to be invaluable to the way I program:
    • Strong typing: Much like pig and elephant DNA just don't splice, one should not be allowed to add characters to integers then divide by floats and expect a sensible result.
    • Type inference: I want a language that can figure out what I'm doing without having to specify every last detail. And I want it to be able to tell me when I'm trying to splice said pig and elephant DNA.
    • Higer order/first class/anonymous functions: makes life and coding so much nicer.
    • Pattern matching: pretty and powerful.
    • An interactive environment: why should I have to compile my whole freaking program to test one little function?
    • Paradigm neutrality: if a problem is best solved with object, let me use objects. If an algorithm is most naturally expressed functionally, gimme that. If imperative code is what I need, let me use it. If I want to mix'n'match hand me the blender
    • Native and byte-code compilation: choose between speed and portability depending on your needs
    Thank goodness there's OCaml there to provide all this for me in one happy little package...
    --
    -30-
  39. A few favorites by scruffy · · Score: 2, Interesting
    Garbage collection

    Unrestricted integer size (e.g., Lisp bignums)

    Have persistent objects between program invocations. It's so tedious and buggy to have to write to a file when a program ends and then read it again when you start it up again.

  40. Re:Unification and Backtracking by BenjyD · · Score: 2, Insightful

    Yes, but does anyone do anything serious in standard Prolog? I found even using Eclipse's (www.icparc.ic.ac.uk/eclipse) extended Prolog, with all the extra functional features just too damn fiddly, even for something well suited to solution by Prolog-like techniques (optimal scheduling).

  41. purposes are more important by bloody_geek · · Score: 2, Interesting

    I don't look at the features alone in a language. Usually, I look at what its primarly used for. I use C because it's a general-purpose language, that has a strong issued standard, with ANSI compiler compliance. I find that beginner programmers who like languages with lots of features(i.e C++), they get carried away and don't learn the language like they should. C++ is an extremely complex language, that is hard to use correctly.

  42. Textual vs. graphical representations by Anonymous+Brave+Guy · · Score: 4, Insightful
    We use graphical interfaces for a lot of things, we should use them for programming.

    SCREW the text editor based programming.

    I think this is one of those rites of passage all experienced programmers probably go through. At some stage, your experience of different languages gets to the point where you understand that the underlying concepts transcend the syntax of any specific language. A natural next step, particularly if you've seen the sort of parsing graphs used by compilers, is to assume that throwing out the "awkward" text syntax in favour of some whizzy graphical scheme will make things much easier. Some people have even done PhDs on this subject.

    Unfortunately, when you try it in practice, you find it's not nearly as clear-cut as you thought. Like all that nasty, unnecessary punctuation found in many programming languages, it turns out that using a concise, precise text format is often far easier both to read and write than any graphical alternative. What can be done in one line of regex in Perl takes a whole screen of graphical representation via flow charts and state machines.

    I wish you luck in your exploration of graphical alternatives, but I'm afraid the odds are pretty heavily that after a while, you'll come full circle, and understand that all that nasty "bracket crap" is there for a reason, and has survived for decades because that reason is sound.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.