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

Re: Long names are doom ?



Ivan Tomek wrote:

> I could not resist this. In Smalltalk, you can find for example the
> longest class name by the following code fragment. The code can be
> shortened, but this version shows very clearly what happens. I think that
> even a non-Smalltalk person can se what is going on - partially because of
> names that programmers in other languages might consider too long.
> 
> | longestName maxLength |
> longestName := ''.
> maxLength := 0.
> Object withAllSubclasses do:
>  [:class | | newName newLength |
>   class isMeta
>    ifFalse: [
>   newName := class name.
>   newLength :=  newName size.
>   newLength > maxLength
>     ifTrue: [longestName := newName. maxLength := newLength]]].
> longestName
> 
> By the way, the answer is ... (left as an exercise).

In Common Lisp you can e.g. write

(let ((maxlen 0))
  (do-all-symbols (symbol)
     (setf len (max maxlen (length (symbol-name s)))))
  maxlen)

To find the length of the longest accessable symbol of all packages.

Regards,
Jochen



References: