Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Smalltalk:

    anArray insert: anObject at: 5

    Objectionable C:

    [array insertObject: object at: 5]

    Quite cute really. Makes it a lot easier to use simple type suggesting variable names 'cos they're not having to do double duty to describe what they're for as well as what they are.
    • I don't understand your final point about variable names. Could you expand on it?

      Someone once suggested to me it was nice that Obj-C was nice because it showed you very clearly what parts were method calls, and what parts were just regular C code. I'm not sold on that yet, as I don't really have a problem with that in other languages. But my mind is open on it, and the OS X tools are nice enough that it won't sway me either way.
      • Consider a Smalltalk method declaration
        OrderedCollection at: anInteger put: anObject
        The method selector tells you what each argument is for, the parameter name tells you what it is. Actually, good Smalltalk style is to only use type suggesting variable names for method argument names. The method body that I lifted the above from, for instance, continues:
          | index |
          index := anInteger asInteger.
        | index | is Smalltalk for my $index. Note that there's an assumption in the implementation that the first argument won't necessarily be an integer; the name of the variable simply implies that it will be treated as an integer.

        There's a better discussion of Type Suggesting and Role Suggesting variables in Kent Beck's Smalltalk Best Practice Patterns, a book I never seem to stop recommending; even if you don't do Smalltalk, it's full of good stuff for anyone who does OO programming in a dynamic language. It's warped my brain to the extent I keep finding myself writing variableNamesLikeThis, which would be okay for private stuff, but runs counter to perlstyle for stuff I might want to release.