| ▲ | _ache_ a day ago |
| No it will *replace* or create the files "touched" by an empty file. Major bug in the first command. Technically, yes, it updates the last modified date, by actually emptying the file. He should have use "w+" or "a" instead of "w". PS: I like this guy. |
|
| ▲ | dasyatidprime a day ago | parent | next [-] |
| This could just be from a classic issue that comes up with organic intelligences. Where do people most commonly see ‘touch’ used, after all? It's very common to see it in build processes, used only on empty files, whereas using it to update the timestamp of a file with contents is more obscure (I don't know if I've ever seen it in the wild, personally). If you asked random developers “what does ‘touch’ do?”, and they weren't primed to think unusually carefully about it, you might well get something around creating empty files as the dominant answer, via extrapolating from a biased pile of examples rather than going to an authoritative source. In natural language, this leads to semantic drift. In programming languages, semantic drift leads to bugs. |
| |
| ▲ | smugma 21 hours ago | parent [-] | | I had forgotten that touch creates files, not just updates the timestamp. I was watching the video and was confused until he demoed its usage. | | |
| ▲ | tefkah 20 hours ago | parent [-] | | interesting, i for one didn’t know about updating the timestamps haha, i’ve only ever used touch to create an empty file |
|
|
|
| ▲ | taspeotis a day ago | parent | prev | next [-] |
| Should have used AI |
| |
| ▲ | cmiles74 a day ago | parent | next [-] | | It seems 50/50 to me that an LLM would come up with a similar solution. | | | |
| ▲ | suddenlybananas a day ago | parent | prev [-] | | Well, if the point is to have something that works well and follows the standard, he shouldn't have done anything at all and just use what was already made. |
|
|
| ▲ | saidnooneever 16 hours ago | parent | prev | next [-] |
| its not neccesarily a bug it could be a feature. :D |
|
| ▲ | geocar a day ago | parent | prev [-] |
| w+ truncates |
| |
| ▲ | Joker_vD a day ago | parent [-] | | Such a baffling option, to be fair, I don't think I've ever used it. Like, what's even the point? | | |
| ▲ | vconnor a day ago | parent [-] | | Why would one would like to truncate an existing file? To overwrite it. It's a very common use case. What I have never found any use for personally is opening a file in read-write mode, while also truncating it, which is the full extent of w+ behaviour. I cannot think of many reasons to have an output stream to also function as an input. | | |
| ▲ | Joker_vD 15 hours ago | parent [-] | | > Why would one would like to truncate an existing file? To overwrite it. It's a very common use case. Yeah, but we have plain "w" for that already. > What I have never found any use for personally is opening a file in read-write mode, while also truncating it, which is the full extent of w+ behaviour. I cannot think of many reasons to have an output stream to also function as an input. Exactly my point. If I am about to fully overwrite the file content, why would I want to re-read them without even an intermediate fclose()? I know that content already, I've just wrote it out! The only fringe use cases I can think of are really the edge cases of some general scenarios that would normally use "r+" (e.g. databases) but could occasionally go "okay, let's drop everything and start ab initio" — but those can just call ftrunc() in those circumstances. Or just open the file twice with different modes, the filesystem being what it is (global shared mutable state), you'll see your changes through. |
|
|
|