Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The algorithms I browsed make sense, but his coding style is peculiar, and somewhat un-pythonic.

For instance: https://github.com/norvig/pytudes/blob/master/py/SET.py

Why the CAPS name? Why are we defining `test` if we’re just running it on the next line - or rather, why are running the test in that same file as it’s definition, and then running an example 100k times?

Any professional python developer will know this, but when an adventuring friend calls me to help him debug something, with code modeled on what he’s seen in examples like these, I’ll likely just throw my hands up.

On the flip side, this isn’t bad for showing how something works, and the cognitive overload for a beginner to “get to the meat” if he’d used `argparse` or `click` might be a bit high.



`set` is a built-in. He probably didn't want to smash it.

Defining a function and immediately calling it prevents pollution of module scope. Without it, `photo` would be exported.

The tests are in the same file because it makes the example self-contained, I assume.

The experiments are run 100,000 times because they have a random component and this exercises the system.


Please re-read my comment. I understand what he did, but my points stand.

The name `SET` conveys little. Running the exercise in the same file is OK as it’s not in a module, but again - the work demonstrates algorithms well enough, but I can’t see this coding style as “smart” or “clean”. It’s not.


Top of the file:

""" Game of Set (Peter Norvig 2010-2015) """

It's the name of the problem being solved.


Yeah, `game.py` would've been great!


>Any professional python developer will know this, but when an adventuring friend calls me to help him debug something, with code modeled on what he’s seen in examples like these, I’ll likely just throw my hands up.

A professional python developer would also know the difference between code written for exposition purposes, code written to validate an idea, and code written for production use. They are not identical, and should not be. The concerns and aims of each code are different and they optimize for different things, and that is reflected in the coding style.

>but when an adventuring friend calls me to help him debug something, with code modeled on what he’s seen in examples like these, I’ll likely just throw my hands up.

I doub't changing the capitalization of a variable renders you unable to help. Seems like something that you could trivially filter out, and use it as an opportunity to educate.


That kind of software construction discipline is unnecessary for projects of this size.




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

Search: