Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell module naming conventions

How should I name my Haskell modules for a program, not a library, and organize them in a hierarchy?

I'm making a ray tracer called Luminosity. First I had these modules:

Vector Colour Intersect Trace Render Parse Export 

Each module was fine on it's own, but I felt like this lacked organization.

First, I put every module under Luminosity, so for example Vector was now Luminosity.Vector (I assume this is standard for a haskell program?).

Then I thought: Vector and Colour are independent and could be reused, so they should be separated. But they're way too small to turn into libraries.

Where should they go? There is already (on hackage) a Data.Vector and Data.Colour, so should I put them there? Or will that cause confusion (even if I import them grouped with my other local imports)? If not there, should it be Luminosity.Data.Vector or Data.Luminosity.Vector? I'm pretty sure I've seen both used, although maybe I just happened to look at a project using a nonconventional structure.

I also have a simple TGA image exporter (Export) which can be independent from Luminosity. It appears the correct location would be Codec.Image.TGA, but again, should Luminosity be in there somewhere and if so, where?

It would be nice if Structure of a Haskell project or some other wiki explained this.

like image 289
mk12 Avatar asked Jul 21 '12 18:07

mk12


People also ask

How do you name a module?

Package and Module Names Modules should have short, all-lowercase names.

How do you define a module in Haskell?

Haskell's module design is relatively conservative: the name-space of modules is completely flat, and modules are in no way "first-class." Module names are alphanumeric and must begin with an uppercase letter. There is no formal connection between a Haskell module and the file system that would (typically) support it.

What are different naming conventions?

The standard naming conventions used in modern software development are as follows: Pascal case. camel case. snake case.


1 Answers

Unless your program is really big, don't organize the modules in a hierarchy. Why not? Because although computers are good at hierarchy, people aren't. People are good at meaningful names. If you choose good names you can easily handle 150 modules in a flat name space.

I felt like [a flat name space] lacked organization.

Hierarchical organization is not an end in itself. To justify splitting modules up into a hierarchy, you need a reason. Good reasons tend to have to do with information hiding or reuse. When you bring in information hiding, you are halfway to a library design, and when you are talking about reuse, you are effectively building a library. To morph a big program into "smaller program plus library" is a good strategy for software evolution, but it looks like you're just starting, and your program isn't yet big enough to evolve that way.

These issues are largely independent of the programming language you are using. I recommend reading some of David Parnas's work on product lines and program families, and also Matthias Blume's underappreciated paper Hierarchical Modularity. These works will give you some more concrete ideas about when hierarchy starts to serve a purpose.

like image 65
Norman Ramsey Avatar answered Oct 16 '22 16:10

Norman Ramsey