Timeline for Clean Code: Functions with few parameters
Current License: CC BY-SA 3.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 14, 2017 at 15:45 | comment | added | AngularRat | The biggest issue I always have with global variables is the fact that you can no longer properly test a function if it uses global state. This is a concept that is actually very simple but that a lot of developers I've worked with struggle with. For more details, I refer you to an article by John Carmack that covers the subject well, especially referencing the fact that in programming, hard rules like "never use global state" aren't always practical, but they are a good goal. | |
| Jul 13, 2017 at 18:00 | comment | added | gnasher729 | @kat0r: Use Objective-C or Swift. Parameters are named in the call by default. | |
| Jul 13, 2017 at 18:00 | comment | added | gnasher729 | @JörgWMittag: Not only is a program using global variables harder to understand, it is also much easier to have hard to reproduce errors, especially when using multiple threads. | |
| Jul 13, 2017 at 13:46 | comment | added | Doc Brown | The answer is correct in what it says, nevertheless it seems it takes the OPs misunderstanding about the recommentations in "Clean Code" for granted. I am sure there is no recommendation to replace function parameters by globals in that book. | |
| Jul 13, 2017 at 12:45 | comment | added | kat0r | @JerryJeremiah No one, that is why we use IDEs. Your case is kinda extreme though and honestly do the amount of parameters matter? Can you rely on your memory that for random_3_paramter_function the correct order is A, B, C and not A, C, B? | |
| Jul 13, 2017 at 9:43 | history | edited | Samuel | CC BY-SA 3.0 | deleted 11 characters in body |
| Jul 13, 2017 at 8:51 | comment | added | Jerry Jeremiah | I maintain a code base where some of the functions take more than a dozen parameters. It's a huge time waster - every time I need to call the function I need to open that file in another window so that I know in what order the parameters need to be specified. If I used an IDE that gave me something like intellisense or if I used a language that had named parameters then it wouldn't be so bad but who can remember what order a dozen parameters are in for all those functions? | |
| Jul 13, 2017 at 7:26 | comment | added | Jörg W Mittag | More parameters make a subroutine harder to understand, global variables make the whole program, i.e. all subroutines harder to understand. | |
| Jul 13, 2017 at 6:46 | vote | accept | OiciTrap | ||
| Jul 13, 2017 at 4:29 | comment | added | OiciTrap | Mmmm ok, I guess you are right... | |
| Jul 13, 2017 at 4:19 | history | edited | Samuel | CC BY-SA 3.0 | deleted 6 characters in body |
| Jul 13, 2017 at 4:18 | comment | added | Samuel | That doesn't sound like a design issue. I still think passing parameters to the functions is the best design. In an AI system like you're describing I would find it useful to write unit tests to test the pieces of the system, and the easiest way to do that is with parameters. | |
| Jul 13, 2017 at 3:59 | comment | added | OiciTrap | Ok, It's good to hear other opinions, but about the design smell, I'm programming in C problems that are solved by methods of artificial intelligence and I tend to use many functions that almost always use the same matrices, arrays or variables (which I pass as parameters to the functions), I'm saying this because I don't feel that I can put these variables inside a common concept/thing like a struct or union so I wouldn't know how to make a better design, so that's why I think the use of global variables in this case could be worth, but most likely I'm wrong. | |
| Jul 13, 2017 at 3:47 | history | answered | Samuel | CC BY-SA 3.0 |