Please do not use "type" as a function parameter name...

Please do not use “type” as a function parameter name…like:

function Map:getObjectsWithType(type)

as this will hide the system function type() within the scope of that function, which could lead to obscure bugs or crashes.

I just got bitten when I tried to add an extra test like if(type(ob==“string”) inside one of those functions, and it took me a while to figure out what was wrong and started seriously to doubt my own sanity before I finally found it… not sure about my sanity, but I am sure about the recommended best practice :wink:

The following function currently use type as a function parameter:

function Map:getObjectsWithType(type)
function Map:firePropertyListener(property, type, object)
function ObjectLayer:getObject(name, type)
function ObjectLayer:getObjects(name, type)
function ObjectLayer:getObjectsOfType(type)

Maybe use “atype” instead of “type” (?)

-FrankS
[import]uid: 8093 topic_id: 7427 reply_id: 307427[/import]

Ah dang, good catch there again, sorry about causing you to doubt your sanity. I have the luxury of losing mine ages ago so my mind is free from any doubt.

How about “objectType” and “propetyType” ? [import]uid: 5833 topic_id: 7427 reply_id: 26249[/import]

anything but “type” will do :wink:

… but personally I do like the more expressive, somewhat longer variable names as then you do not have to guess too much, so your suggested names would do exactly that. [import]uid: 8093 topic_id: 7427 reply_id: 26281[/import]

All changed. I usually am more of a fan of the more expressive names too. I blame uni for having the shorter names. [import]uid: 5833 topic_id: 7427 reply_id: 26292[/import]