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? _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
> 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. > > > 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? I will often use a mixture, based on the length of the block. For short blocks, I don't go to a new line; for longer ones, I use the style in your first example (the one I snipped). Even when using the style I cite above, I will always put something after a keyword, unlike your example (i.e. I would have started the new line after "ifTrue: ["). The conversion tool generates code in the latter format, so soon enough the source code will all be in this format. Paolo _______________________________________________ help-smalltalk mailing list [hidden email] http://lists.gnu.org/mailman/listinfo/help-smalltalk |
Free forum by Nabble | Edit this page |