Is 78 characters still a good option? Was: [Haskell-cafe] breaking too long lines

Daniel Fischer daniel.is.fischer at web.de
Sat Apr 25 11:02:07 EDT 2009


Am Samstag 25 April 2009 16:44:45 schrieb Miguel Mitrofanov:
> On 25 Apr 2009, at 18:34, Xiao-Yong Jin wrote:
> > Miguel Mitrofanov <miguelimo38 at yandex.ru> writes:
> >> On 24 Apr 2009, at 16:37, Loup Vaillant wrote:
> >>> 2009/4/23 Miguel Mitrofanov <miguelimo38 at yandex.ru>:
> >>>> On 23 Apr 2009, at 12:17, Thomas Davie wrote:
> >>>>> Haskell is a very horizontal language, and to limit our horizontal
> >>>>> space
> >>>>> seems pretty weird.
> >>>>
> >>>> +1. I sometimes use lines up to 200 characters long, when I feel
> >>>> they would
> >>>> be more readable.
> >>>
> >>> 200 sounds awfully long. Do you have any example?
> >>
> >> Something like
> >>
> >> newtype MyCoolMonad = MyCoolMonad (FirstTransformer
> >> (SecondTransformer
> >> (ThirdTransformer Whatever))) deriving (Functor, Monad, FirstClass,
> >> SecondClass, ThirdClass, SomeOtherClass)
> >>
> >> Nobody would be really interested in "deriving" clause, because it
> >> basically says "derive everything possible". Therefore, it seems
> >> pointless to move it to another line.
> >
> > You don't write lisp, do you?  Or probably it is just me.
> > But I would prefer to write the line as
> >
> > newtype MyCoolMonad = MyCoolMonad (FirstTransformer
> >                                   (SecondTransformer
> >                                    (ThirdTransformer Whatever)))
>
> Well, first impression I've got from this was that FirstTransformer,
> SecondTransformer and the rest are on the same level:
>
> newtype MyCool Monad = MyCoolMonad (FirstTransformer)
> (SecondTransformer) (ThirdTransformer Whatever)
>
> which is very confusing.

You have a point there. If split over several lines, I'd recommend each line indented 
further than the previous to indicate nesting:

newtype MyCoolMonad
    = MyCoolMonad
          (FirstTransformer
              (SecondTransformer
                  (ThirdTransformer Whatever)))

But I wouldn't really prefer that over having it on one line.

>
> >    deriving (Functor, Monad,
> >              FirstClass, SecondClass, ThirdClass, SomeOtherClass)
>
> A lot of unnecessary information distracting the reader. It's better
> kept somewhere else, where it doesn't attract too much attention -
> like in the end of the line.

There I have to disagree. IMO, having the deriving clause on the same line (unless it's a 
very short one) obscures the code and makes it *much* harder to read.




More information about the Haskell-Cafe mailing list