Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
on the other hand "cute" in a nice way is overloading the / for filesystem::path in C++, i found that pretty amusing when i first saw it

for the most cursed operator overloading candidate i submit muti dimensional analog literals
After using pathlib.Path in python, I see zero reason why / shouldn't have that behavior for strings by default
 
Why not use f-strings and the like?
Why would I want to roll my own platform independent path utility and file system management class, when pathlib is in the standard library and well supported by third party libraries?
Pathlib isn't just for path formatting, it's hooked into shutil2, os, sys, and is supported by the fsspec people
I could roll my own, but there's no reason to
 
Why would I want to roll my own platform independent path utility and file system management class, when pathlib is in the standard library and well supported by third party libraries?
Pathlib isn't just for path formatting, it's hooked into shutil2, os, sys, and is supported by the fsspec people
I could roll my own, but there's no reason to
I thought you meant for string formatting in general
 
I thought you meant for string formatting in general
Well, even for that, Path is nice because it's platform independent. They use OOP to abstract the path hierarchy, so code for one platform will function for another for manipulation. Hell, I can do p = Path.home() / '.my_app.d', and I'll get a valid path on any machine.
1752634671305.webp
The Pure ones are ABCs, then in the __new__ method of Path, python delegates to the proper child class.
I know exactly how to do this, I just like having it be a first class feature I don't need to overthink outside of really bizarre situations with shit like fuse
 
  • Informative
Reactions: Belisarius Cawl
Well, even for that, Path is nice because it's platform independent. They use OOP to abstract the path hierarchy, so code for one platform will function for another for manipulation. Hell, I can do p = Path.home() / '.my_app.d', and I'll get a valid path on any machine.
View attachment 7648748
The Pure ones are ABCs, then in the __new__ method of Path, python delegates to the proper child class.
I know exactly how to do this, I just like having it be a first class feature I don't need to overthink outside of really bizarre situations with shit like fuse
I'm familiar with it from an online GIS course I was using (too bad they never updated broken material)
 
  • Feels
Reactions: Anti Snigger
I'm familiar with it from an online GIS course I was using (too bad they never updated broken material)
Paths when you're writing cross platform code are a pain in the ass, having something just werk on different OSes is incredibly nice. The Python Path class is incredible. Spidering a subtree is two lines of easily readable code that replaces about 20 lines using os. I actively refactored codebases at work to use pathlib. If I ever make an operating system, all paths are going to be null separated strings.
 
Paths when you're writing cross platform code are a pain in the ass, having something just werk on different OSes is incredibly nice. The Python Path class is incredible. Spidering a subtree is two lines of easily readable code that replaces about 20 lines using os.
What are these two lines? I assume spidering is some kind of exhaustive search of a directory?
 
Cool, what are the two lines
Oh my bad, I thought you meant of what I wrote
It's something like this:
Python:
p: Path = ...
    
for cwd, subd, files in p.walk():
    ...
If you want to skip a subtree, you just mutate subd accordingly.
 
  • Informative
Reactions: Belisarius Cawl
Oh my bad, I thought you meant of what I wrote
It's something like this:
Python:
p: Path = ...
    
for cwd, subd, files in p.walk():
    ...
If you want to skip a subtree, you just mutate subd accordingly.
I assume alphabetical order is preserved?

(Also Google's AI suggested a completely unnecessary use of deque from collections)
 
I assume alphabetical order is preserved?
I believe so, at least lexicographic.
(Also Google's AI suggested a completely unnecessary use of deque from collections)
Yeah, that would probably relate to Path.walk's cranky drunk grandpa, os.walk. They ultimately make the same syscalls, but Path is easier to read and less error prone. A file system path is an identifier for a node in a tree, I want to manipulate my path objects as if they were a tree, not doing string parsing.
 
Back