Replies: 3 comments 1 reply
-
|
Well, V does already have a way to deal with unused function parameters, the same way Go does it... use Perfectly valid code, compiles clean. The only real question is whether or not V should complain about unused variables. Currently, it does. It didn't in the past, but now for this slightly different code: You'll see something like this: Now... why would you even want an unused parameter... perhaps as a placeholder? You're still thinking about what parameters the function will need, but maybe you've just created a stub for now? I don't know what the "best" way to do this is. I've seen probably every variation amongst different languages... some languages just ignore it altogether. Some give you a warning about unused parameters. Others will give an error. I've pretty much come to the opinion that the "best" way is whatever the language you're using does - that's what's best for that language. In other words, there is no "best way". Just do what the language needs you to do in order to write your code. |
Beta Was this translation helpful? Give feedback.
-
|
Perhaps it would be good to show vlang style "option parameter" like alternatives, in context to the unused parameter issue:
|
Beta Was this translation helpful? Give feedback.
-
|
Something I haven't seen many people mention is one of the most frequent times I find myself leaving parameters unused is for anonymous functions that need to match a certain signature, such as event handlers in GUI apps. This does work with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There has been lots of debates about this, in many languages. It is often argued that an unused parameter is like unused variables, however, I'm of the opinion that's not the case. A variable is usually more about a deliberate action by the programmer to complete specific tasks. Function arguments, however, can often reflect the intention to do a wide variety of tasks, have more flexibility, and can also be part of libraries (modules) used by a great number of users.
Unused parameters can become an insidious issue for numerous reasons: 1) Library creators or those creating modules for future use, arguably can not predict nor anticipate all possible outcomes in advance. This would be even more of an issue for newbies and casuals, who we would or should not expect to rewrite libraries. 2) The intention can be for the function to produce different results, based on parameters used. 3) The flow state of the programmer can be affected, where they are forced to adopt a programming style they don't like or are not used to. 4) Interoperability and translation problems between languages, where unused parameters are handled differently.
Different languages, have different strategies to mitigate or circumvent the annoyance of unused parameters. They can allow for optional parameters, unnamed parameters, are not strongly typed, use method overloading (same method name with different parameters), etc... Interestingly, vlang has none of those ways to mitigate or circumvent in that way, possibly creating an issue.
There are some "vlang ways" to handle it, that probably should be shown in the documentation, but there is still the matter of backwards compatibility and updating. The issue of previous functions needing to be rewritten to adhere to newly implemented "policies" or "preferences". And rewriting functions, to say use structs or interfaces as the parameter, can be time intensive or require significantly different thinking in the design of the module.
Beta Was this translation helpful? Give feedback.
All reactions