views:

41

answers:

3

I'm making a game in Python, and it makes sense to have one of my modules named 'map'. My preferred way of importing is to do this:

from mygame import map

As pylint is telling me, however, this is redefining a built-in. What's the common way of dealing with this? Here are the choices I can come up with:

1) Ignore the pylint warning since I don't use the built-in map anyway.

2) Change to:

import mygame

then reference as mygame.map throughout my code.

3) Rename my map module to something else (hexmap, gamemap, etc.)

I'm leaning towards (2) but I want to see what other people think.

+2  A: 

This is subjective; there's no right answer.

That said, for me 3 is the only sensible option. Really really don't do 1; overwriting builtins is almost never a good idea and in this case it's especially confusing. 2 is better, but I think there is still an expectation that any function called map performs some operation similar to that of the builtin.

Maybe mapping?

katrielalex
I think `mapping` would be seen by the outsider as something to do with a data structure like a dictionary rather than a game map
Rafe Kettler
That's the name of a module, not a function. It contains classes for hex tiled maps, single hex tiles, helper functions, etc.
Colin
@Colin: sorry, edited. Why not `maps`? @Rafe: that's true; I think the context is sufficient in this case.
katrielalex
+1  A: 

Options 2 or 3 would work, however I think it would be most understandable to rename map so that it can't be confused. That way, you can get the conciseness that referring to map instead of mygame.map gives you, but you won't have any problems with scope. Also, I think map is a somewhat undescriptive variable name, so it'd be better to give it a more specific name.

Rafe Kettler
+2  A: 

Quoth PEP 20:

Explicit is better than implicit.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.

mygame.map is more explicit than map. mygame.board or mygame.terrain is less ambiguous than mygame.map. Guessing if code is talking about __builtins__.map or mygame.map is frightful and will mostly be wrong.

msw