Hacker News new | ask | show | jobs
by Risord 2559 days ago
Code smell #1/#2: If you have too long function/method break it apart. How does this relate code being in function VS method

Code smell #3/#4: If you don't want to put helpers to global scope then just don't. I don't see why closures are so bad. Top level function can act pretty much same as class scope so what's the difference? I don't know about python but if you really don't want to use closure another languages have other encapsulation methods too.

Code smell #5: If you use closure you can have shared state. Passing state can be noise but on the other hand if you only read/write "semi global" variables it's messy too. If you need to pass lot amount of state it's usually hint that you have some other problem in your code.

1. Like said you don't need objects

2. Function have single entry without ambiguity like @Someone shows.

3. You should test behavior, not specific implementation. You don't need mocking for pure functions.

4. Is X optional? What about Y? Does order matter when calling 'withs'? And that builder thing is directly stolen from all the Java jokes.

5. I don't know what is Pythonish way to do delayed callability but I claim that it should be independent thing rather than directly bounded to specific function/object.

If it looks like a function, swims like a function, and quacks like a function, then it probably is a function.

1 comments

5. I do not know if it's pythonish, but I use and abuse functools.partial