Hacker News new | past | comments | ask | show | jobs | submit login

While it's not a perfect example or solution, this illustrate a fairly common issue with modern code. He also mentions too many parameters. Other commonly frown upon constructs include unclear names (java "filter" or "compareTo" easily come to mind), boolean parameters (One should use named enums instead). Some add to the list out parameters (passing a to-be-modified list as a parameter), functions returning their modified input parameter, even though they certainly have their usefulness (like being able to handle memory management outside of the callee). I'd personally like to add String parameters to the list, but modern language make such restrictions often too cumbersome.

I the given example, I'd love to see a language with optional named parameters. For the function copy(String fromFileName, String toFileName), instead of calling copy (file!, file2), one would have the possibility of calling copy(from:file1, to:file2)




Your last point is something that I really like about the Swift language. All parameters have names that are mandatory when calling the function, so in Swift you would be required to call copyFile(from: file1, to: file2). [0]

0: https://docs.swift.org/swift-book/LanguageGuide/Functions.ht...


In C# you can optionaly name parameters when you call a method, sometime this is mendatory when you want to set the second(or more!) optional argument, but you don't want to set the first optional argument.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: