3 added 23 characters in body
source | link

There are several choices here, in increasing order of preference (most preferable last):

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

...

Generally, though, these schemes are useful when the calls have to be serialized & transmitted between processes. If you're just making calls from one section of code into another, you can just identify what you want done with the function names. Writing some sort of "router" function that makes a call to lower-level function replicates what the language does for you, so you might think harder about whether you need that.

...

That is, I try to keep it so that 90% of my code looks like it came straight out of "Learn Java in 30 days" (or Python, or whatever). That is, the code should just use the language in a really basic way almost all the time. There should be a pretty good reason why you can't just do it the basic way before you move to a broader generalization.

There are several choices here, in increasing order of preference:

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

...

Generally, though, these schemes are useful when the calls have to be serialized & transmitted between processes. If you're just making calls from one section of code into another, you can just identify what you want done with the function names. Writing some sort of "router" function that makes a call to lower-level function replicates what the language does for you, so you might think harder about whether you need that.

There are several choices here, in increasing order of preference (most preferable last):

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

...

Generally, though, these schemes are useful when the calls have to be serialized & transmitted between processes. If you're just making calls from one section of code into another, you can just identify what you want done with the function names. Writing some sort of "router" function that makes a call to lower-level function replicates what the language does for you, so you might think harder about whether you need that.

...

That is, I try to keep it so that 90% of my code looks like it came straight out of "Learn Java in 30 days" (or Python, or whatever). That is, the code should just use the language in a really basic way almost all the time. There should be a pretty good reason why you can't just do it the basic way before you move to a broader generalization.

2 added 438 characters in body
source | link

There are several choices here, in increasing order of preference:

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

...

Generally, though, these schemes are useful when the calls have to be serialized & transmitted between processes. If you're just making calls from one section of code into another, you can just identify what you want done with the function names. Writing some sort of "router" function that makes a call to lower-level function replicates what the language does for you, so you might think harder about whether you need that.

There are several choices here, in increasing order of preference:

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

There are several choices here, in increasing order of preference:

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them

...

Generally, though, these schemes are useful when the calls have to be serialized & transmitted between processes. If you're just making calls from one section of code into another, you can just identify what you want done with the function names. Writing some sort of "router" function that makes a call to lower-level function replicates what the language does for you, so you might think harder about whether you need that.

1
source | link

There are several choices here, in increasing order of preference:

  • Bits (flags) in an integer. Can be confusing, but allows packing a lot of them into a single int. So

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 4 DO_ZING = 5

    perform(DO_THIS | DO_THAT)

    if (command && DO_THIS{ doThis(); } ...etc

  • Integer commands

    DO_THIS = 1 DO_THAT = 2 DO_ANOTHER = 3

    perform(DO_THIS, DO_THAT)

    for (command in commands): if (command == DO_THIS) { doThis(); }

  • I favor strings over ints, just because they're more readable

    DO_THIS = "this" DO_THAT = "that" ...

  • "Typesafe" constants (in case you don't have enums around)

    DO_THIS = new Object(); DO_THAT = new Object();

    perform(DO_THIS, DO_THAT);

    for (command in commands) if (command == DO_THIS) { doThis(); }

  • Enum is a formalization of "Typesafe constants" so use that if you have them