4 ms·
I agree with the various other commenters on the blog post - that treating the wrapper function like an unacceptable amount of redirection is insane premature o
by angusgr 15y ago
I agree with the various other commenters on the blog post - that treating the wrapper function like an unacceptable amount of redirection is insane premature optimisation at expense of clarity.
Not to mention the wrapper can be inlined in C99, or would be automatically inlined with -O3 in gcc, not that it matters one iota in this case.
The other glaring bug would seem to be Windows' implementation for POSIX tmpfile() requiring admin access. But I guess that's not too surprising.
- nandemo 15y agoIndeed. What's a wrapper function's overhead compared to opening a file, which subsequently will be written to? Frankly, I wish this sort of blog post wouldn't be upvoted here. It's one thing when someone asks a basic question on StackOverflow. Even experienced programmers can learn with the answers. But when someone writes an "authoritative" blog post that misses the basics, it's more noise than signal.
- snprbob86 15y ago"What to Submit On-Topic: Anything that good hackers would find interesting." [1] I agree about this being an insane premature optimization, but the C:\ being a bug regarding line continuation within comments? That's fucking fascinating. [1] http://ycombinator.com/newsguidelines.html http://ycombinator.com/newsguidelines.html
- TorKlingberg 15y agoTo be fair, the bug that the post is about has nothing to do with his optimization. That is just context.
- joshu 15y agoWell, jrockway's deconstruction was pretty nice to read even if the original was boring.
- nandemo 15y agoPoint taken. I learned something with the comments if not with the original article.
- statictype 15y agoBut I guess that's not too surprising. I don't know - that's actually very surprising to me considering each user has their own temporary folder. I can't imagine what reason could exist for this functionality except possibly to provide backwards compatibility with some popular apps that have been poorly written.
- angusgr 15y agothat's actually very surprising to me considering each user has their own temporary folder To extrapolate, I found it unsurprising not because it's either Windows or POSIX individually, but because it's both together. It's been many years since I was a Windows developer, but I remember back then that the opinion of the POSIX implementation (XP era, not NT era) was "there be dragons" and to avoid it.
- roel_v 15y agoBecause the proper Windows way is to specify where to create the temporary file; for example the developer can choose between the user-specific 'temp' folder, or the 'temporary internet files' folder, or the folder returned by GetTempPath(). Some old programs rely on the temp folder being shared between application, others don't. And then you run into access issues - sometimes on Vista you don't have write access to whatever GetTempPath() returns and you'll have to find something else, like the user dir returned by SHGetSpecialFolderLocation or any of its predecessors or new versions, and tack "\Temp" onto that yourself. So, to get back to your question, the posix compatibility layer in Windows is very old and back then all the above didn't exist and they had to make a choice on how to implement the function. Back then (this decision may have been made as early as the late 1980's), using C:\ wasn't all that stupid an idea; either way, the point was that the file would be deleted when the file handle was closed anyway, so it's not like C:\ would be polluted with all sorts of files. Of course those assumptions changed in the past 20 years, but you can't just change the behavior of your core OS functions because you don't know how it will break old applications. If you're interested in Windows development, the The Old New Thing blog goes into detail on issues like this.