Hardcoding parameters into function names

July 30, 2008 at 10:47 pm Leave a comment

Code seems to sometimes be slightly easier to read if information is pushed out of the arguments and into the function name.

I.e: Set(‘Color’, red) —> SetColor(red)

This has the nasty effects of making one’s APIs rather large, but if used sparingly it:

  1. Makes APIs more discoverable – the naming of function now contains information which would otherwise be in the usage of functions
  2. Makes code slightly easier to parse – Mostly just because we have removed an argument from the argument list
  3. Make code using the API slightly easier to write

Bear in mind that this statement is heuristic and general… so is probably wrong most of the time. Also I kind of suspect that all of this may immediately become false when two arguments rather than on are pulled out of the argument list and into the functional name.

This statement is, however, particularly true when your different operations take slightly different data as one of the other arguments vary.

Advertisements

Entry filed under: Uncategorized. Tags: , , .

Emacs version control Recording screencasts on Ubuntu Hardy

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


July 2008
M T W T F S S
« May   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031  

%d bloggers like this: