- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
If the IOError.Exists exception corresponds under the covers to the POSIX "EEXISTS" error value, you only know that something with that name exists. The "something" might be a directory, but it just as easily be a bound UNIX socket, a terminal character device node, a symbolic link, or even a file. Good luck dealing with that.
The Windows documentation isn't clear, but could easily be trying to say something similar.
Admin
Also, I wouldn't bother with all the "crawl back up to find where it first doesn't exist" junk. Just start at the shortest length and work toward the full path.
Admin
Is it just me, or would it be simpler to just create an async wrapper for the synchronous version?
Admin
Probably.
Admin
Checking for file existence can run into TOCTOU race conditions. This is generally the recommended practice.
Admin
Often you know that unless someone has deployed deliberately antagonistic code, the existence of the name merely means that part of the hierarchy has already been created. You won't have non-directories where directories are supposed to be. This code is merely intended to make it idempotent, not deal with security violations.
Admin
Exceptions can actually be better for file operations. The file state can change in between the existence check and the file creation or usage; this is a class of bugs called TOCTOU (time of check/time of use).
Granted, in this code it doesn't matter because we build a list of things to create and then create them, so it's still open to TOCTOU bugs. And I bet they happened, which is why that final loop has a check to see if something else created the file...
Admin
Ehm, a C# language that compiles itself to something that is similar to C performance is called C# lol
Admin
Wait... they are making a C#-like language where they use a "yield" keyword, which C# has, to do something very unlike what C# does with "yield". It looks like Vala's yield is similar to C#'s await.
I checked the docs.... yield is both. One syntax is similar to C# yield, both without the return keyword after it and the caller apparently has to cooperate to "re-call" the method and resume it. Another use of yield looks identical to await. Some of the documentation even hints that it's even weirder: "The yield keyword pauses execution of the async method so other code (such as the timeout) can run; execution later resumes at the point after the yield.". This means that Vala essentially has cooperative multitasking and yield is similar to a Windows 3.x program calling GetMessage, but without returning anything useful.
Admin
But fear not! Captain Recursionicus is here to save the day!
Admin
Vala actually transpiles to c, though.
Admin
You missed this:
My understanding - which comes from reading the Wikipedia page just now - is that Vala is specifically designed to make using the GObject library (that underpins Gnome) easier to use. Using it directly from C is somewhat verbose and this makes it better. Vala compiles to C which obviously can be compiled to native code rather than a virtual machine like the one C# targets.
Admin
Ah, you are getting confused by a proprietary close-source product called Java which is mostly run with an interpreter with limited statement caching called "virtual machine" by default.
.net and especially .net core are fundamentally different from this language/framework mixup which was actually just the repurposed by-product of a failed Sun operating system. It doesn't have a "virtual machine" because it's a compiler. The difference to C/C++ is that it's a just-in-time compiler, so by default each types gets compiled ONCE before usage and only compiled code is executed. Why by default? Well, there is a mode where you can compile the whole assembly after loading (famously used by IIS), then there is AoT (ahead-of-time) which allows pre-compiling code to machine language making the code platform-specific and finally there is dynamic profile-guide optimization, which re-compiles compiled code again after specific criteria.
Admin
Interesting, that reminds me about the old days, when .net was nothing more than an extension for COM with an unified class library to replace MFC/ATL. When they brought Hejlsberg on board, he turned the ship around by going for a garbage collected Delphi with C syntax. That's why the class libraries are so closely aligned and you have PASCAL casing for names for nearly everything.
Admin
Yeah, it kinda makes sense though, cause async/await is just a state machine and you are iterating states on assigned worker threads on a thread pool. It's confusing though, because there is no return value for the methods... so on one hand complexity is washed away but on the other hand with the naming you still have the complexity right in your face. Kinda feels sloppy to me.
If you want to know what async/await actually is, here is a nice simple to understand video explaining it from concept to a rough implementation:
https://www.youtube.com/watch?v=R-z2Hv-7nxk
Ah, I kinda miss the days when MS actually made decent videos for dev beginners than videos about slop generation.