News for hackers. Stuff that matters.
Re:Show HN: Shareable reasons to upgrade to Python 3 by Smaug123 on Thursday August 10, 2017 @04:54PM (#14984149)
The very first one I was presented with was the following perversity:

    from pathlib import Path
    directory = Path("/etc")
    filepath = directory / "test_file.txt"
Overloading the addition operation for list concatenation: fine. Something something monads composition symbol. But the division operation?

[Apparently I don't know Windows very well, since I'm told the following sentences are wrong:] Anyway, I thought Python was meant to try and be cross-platform. On Windows, the forward slash is not a path separator.

Re:Show HN: Shareable reasons to upgrade to Python 3 by stevejohnson on Thursday August 10, 2017 @05:48PM (#14984635)
Having done a lot of work using both the old os.path library and new pathlib, the ergonomics of pathlib are much, much better. The behavior of the overloaded operator is well-defined, unsurprising, and otherwise intuitive.
Re:Show HN: Shareable reasons to upgrade to Python 3 by kstrauser on Thursday August 10, 2017 @05:09PM (#14984312)
While I get what you mean, we're very used to using "/" to concatenate components into full pathnames: we do it every time we're using the shell. "/" is the canonical pathname concatenation operator, and tricking a specific Python class into also using it feels a lot more natural than the joinpath stuff.
Re:Show HN: Shareable reasons to upgrade to Python 3 by khedoros1 on Thursday August 10, 2017 @05:16PM (#14984367)
We've got a C++ codebase with its own path class, which works this way. They also used unary operator* (dereference operator) in the string class to return a pointer to the underlying c-string. These are the "clever" kinds of things that the original devs used to get kind of sheepish about when I first brought them up.
Re:Show HN: Shareable reasons to upgrade to Python 3 by ktRolster on Thursday August 10, 2017 @05:36PM (#14984554)
At one time, operator overloading was encouraged. See for example, << in the cout command. Everyone was trying to think of new ways to use them.
Re:Show HN: Shareable reasons to upgrade to Python 3 by khedoros1 on Friday August 11, 2017 @12:25AM (#14986572)
Well, and it worked well enough, in the limited context of our software system. There were a few quirks like that, that everyone knew about. It was kind of funny how opinions changed in the years between when it was written and when I started working there, though.
Re:Show HN: Shareable reasons to upgrade to Python 3 by Osmose on Thursday August 10, 2017 @04:57PM (#14984182)
The `joinpath` method on Path objects works just as well. Also AFAIK pathlib.Path handles both forward and backslashes and does the right thing with them (assuming you don't have some very specific needs around, say, not accepting invalid slashes at all).
Re:Show HN: Shareable reasons to upgrade to Python 3 by Smaug123 on Thursday August 10, 2017 @05:01PM (#14984234)
Sure, `joinpath` may be the best thing since sliced bread. But I maintain that it's semantically perverse to use the division operator symbol to represent it.
Re:Show HN: Shareable reasons to upgrade to Python 3 by oarfish on Thursday August 10, 2017 @05:59PM (#14984741)
Boost::filesystem also does this with its path class. Needless to say I was amazed to see that the + operator wasn't chosen for path concatenation.
Re:Show HN: Shareable reasons to upgrade to Python 3 by tomrod on Thursday August 10, 2017 @04:59PM (#14984203)
I'm pretty sure forward slash works fine for file paths in Windows. It's just not the standard if you cut and paste a filepath from Windows Explorer. As a primarily Linux user that was a pleasant surprise because $BigCorpIWorkAt only has a Windows offering.

Unless it was Cygwin being sneaky, that is...

Re:Show HN: Shareable reasons to upgrade to Python 3 by tokenizerrr on Thursday August 10, 2017 @04:57PM (#14984185)
Using forward slashes on windows will work fine.
Re:Show HN: Shareable reasons to upgrade to Python 3 by jwilk on Thursday August 10, 2017 @05:05PM (#14984274)
ISTR slash works in most, but not all contexts.