Timeline for What is wrong with magic strings?
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 8, 2018 at 14:05 | comment | added | CodeMonkey | @Steve I agree, if your function is called average(a, b) = a + b / 2 you really don't need to have a name for the two. The name of the function already sufficiently describes what it means. | |
| Feb 7, 2018 at 15:48 | comment | added | corsiKa | The top answer is better than this answer if need convincing that magic strings are a "bad thing." This answer is better if you know and accept that they're a "bad thing" and need to find the best way to meet the needs that they serve in a maintainable way. | |
| Feb 6, 2018 at 17:27 | comment | added | Steve | @marcus, indeed! There is of course a case for using simple literal values in-place - for example, if a method divides a value by two, it may be clearer and simpler to simply write value / 2, rather than value / VALUE_DIVISOR with the latter defined as 2 elsewhere. If you intended to generalise a method handling CSVs, you'd probably want the separator passed in as a parameter, and not defined as a constant at all. But it's all a question of judgment in the context - @WGroleau's example of the SPEED_OF_LIGHT is something you'd want to explicitly name, but not every literal needs this. | |
| S Feb 6, 2018 at 14:09 | history | edited | Steve | CC BY-SA 3.0 | added 216 characters in body |
| Feb 6, 2018 at 13:54 | comment | added | marcus | Some people miss the point completely and write COMMA = "," instead of SEPARATOR = ",". The former doesn't make anything clearer, while the latter states the intended usage and allows you to change the separator later in a single place. | |
| Feb 6, 2018 at 13:28 | review | Suggested edits | |||
| S Feb 6, 2018 at 14:09 | |||||
| Feb 5, 2018 at 16:14 | comment | added | WGroleau | As an example, if someone sees “X := 898755167*Z” in your code, they probably won’t know what it means, and even less likely to know that it’s wrong. But if they see “Speed_of_Light : constant Integer := 299792456” someone will look it up and suggest the correct value (and maybe even a better data type). | |
| Feb 5, 2018 at 16:08 | comment | added | Alfred Armstrong | I like this answer. After all "struct" (and every other reserved word) is a magic string to the C compiler. There are good and bad ways of coding for them. | |
| S Feb 5, 2018 at 14:44 | history | suggested | Andy Vaal | CC BY-SA 3.0 | Changed long sentence into a list to make it easier to read. |
| Feb 5, 2018 at 14:37 | review | Suggested edits | |||
| S Feb 5, 2018 at 14:44 | |||||
| Feb 5, 2018 at 13:40 | history | answered | Steve | CC BY-SA 3.0 |