help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Coding style


From: Robin Redeker
Subject: [Help-smalltalk] Coding style
Date: Mon, 27 Aug 2007 09:15:25 +0200
User-agent: Mutt/1.5.11+cvs20060403

Hi!

I've been wondering whether there is some
coding style guideline for writing gnu smalltalk
code. It's mainly because I constantly wonder how
to indent. Especially with the new syntax.

This is an example, how would you indent it and the []?

   [
      [
         socket isNil
            ifTrue: [
               [
                  | conn |
                  trycnt := trycnt + 1.
                  socket := self connect.
                  trycnt := 0.
                  conn := self makeConnection: socket.
                  conn connect.
                  conn loop
               ] on: Error do: [:ex |
                  socket := nil.
                  PLog
                     logInfo: 'connection lost to ', host, ':',
                              port printString, ' because:',
                              ex description,', ', ex messageText.
                  Smalltalk backtrace.
                  ex return
               ].

               socket := nil.
               self delay: trycnt
            ]
      ] repeat
   ] fork

Some people on IRC told me a more lisp-ish style would be more
appropriate, 'no dangling brackets':

   [[socket isNil
      ifTrue:
         [
            [| conn |
            trycnt := trycnt + 1.
            socket := self connect.
            trycnt := 0.
            conn := self makeConnection: socket.
            conn connect.
            conn loop]
               on: Error
               do: [:ex |
                   socket := nil.
                   PLog
                   logInfo: 'connection lost to ' , host , ':'
                   , port printString
                   , ' because:' , ex description
                   , ', ' , ex messageText.
                   Smalltalk backtrace.
                   ex return].
         socket := nil.
         self delay: trycnt] ] repeat ] fork

This is of course more compact, but I consider the first example more
readable. Of course in the end it's a matter of taste. But what style
do you recommend?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]