tilteng / api-style-guide

Best practices for API development at Tilt.
1 stars 0 forks source link

Why are DSL imports placed first? #3

Closed danschmidt5189 closed 8 years ago

danschmidt5189 commented 9 years ago

The style guide suggests placing auto-exporting files (like Dancer) first:

However, if another module that alters the current file with a custom DSL (Domain-specific language) is loaded first, such as Dancer or Moose, then that module should take precedence.

Why is that? Why not always load our prereqs first (e.g. Tilt::Core and MooseX::Modern), since they act like pragmas and are, themselves, auto-exporting?

Also the language is a bit vague - the real issue here is that some files forcibly export symbols into the caller's namespace, and for those import order matters. (Because those symbols can be overwritten.)

ironcamel commented 9 years ago

Listing Moose first makes it immediately clear that the current package is a Moose class, and also allows you to immediately list the parent class and the roles. Another reason modules like Dancer and Moose are traditionally listed first is because they enable strict and warnings. When you open up a perl module file you want to see something that enables strictures at the very top, instead of having to scroll down until you find Moose or Dancer or Test::Modern at the bottom of the import list.