[Haskell-cafe] Organizing your code files

Hécate hecate at glitchbra.in
Sun Aug 8 06:50:24 UTC 2021


Hi Christopher!

On my end, I make use of automated style formatters, so that this kind 
of thing can be kept consistent during CI. I invite you not to think too 
much about the micro-details of code styles, but rather find a tool that 
you can configure so that your style can be enforced automatically. 
You'll be able to spend more cycles on programme development.

I can give you an example of a recent library I wrote: 
https://github.com/Kleidukos/effectful-contrib/blob/8ae8ad1d76e0c43610619fc04a545dc622bafb88/effectful-cache/src/Data/Cache/Effect.hs#L47-L57

Note that:

  * Type variables are made explicit, and as such I annotate even the
    simplest of them (with `:: Type`)
  * I align the separators (., => and ->)
  * I use stylish-haskell & hlint
  * If you want finer automated control, try something like Britanny.


Le 07/08/2021 à 21:18, Christopher Conforti a écrit :
> Hi List,
> I'm a relatively new Haskeller. I've gotten the syntax of the
> language more or less down, and I'm slowly expanding my vocabulary. I've
> found in other languages that my coding style and how my code is
> organized affect both the quality of my code and how easy it is to
> understand.
>
> 'Coding style' refers to how code is organized within a block. For
> example:
> ```
> foo bar baz bing = x + y * z
> ```
> versus:
> ```
> foo
>    bar
>    baz
>    bing
>    = x + y * z
> ```
>
> Code organization refers both to how code is organized within a
> source file (i.e., how code blocks are arranged, how they're grouped,
> so on) and how source files themselves are organized.
>
> I've got the first part down--I've developed a code style that I'm
> satisfied with, I've tried to fine-tune my style to make maximum
> effective use of available space (limiting myself to 72 columns, and a
> block size of no more than 30 lines) so as to force myself to extract
> and abtract away unnecessary details.
>
> The second part is the one I'm having trouble with. There are so many
> ways to organize one's code that I don't even know where to begin
> developing a method that I like other than to ask other Haskellers how
> they do it and why they like doing it that way.
>
> So there you have it: How do you organize your code, and why?
>
> Cheers!
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.

-- 
Hécate ✨
🐦: @TechnoEmpress
IRC: Hecate
WWW: https://glitchbra.in
RUN: BSD

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210808/81b6194f/attachment.html>


More information about the Haskell-Cafe mailing list