• (nodebb)

    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.

  • (nodebb)

    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.

  • Snarkenstein (unregistered)

    Is it just me, or would it be simpler to just create an async wrapper for the synchronous version?

  • (nodebb) in reply to Snarkenstein

    Probably.

  • (nodebb)

    using exceptions for flow control instead of doing things like checking for file existence

    Checking for file existence can run into TOCTOU race conditions. This is generally the recommended practice.

  • (nodebb) in reply to Steve_The_Cynic

    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.

  • Agrajag (unregistered)

    Mostly, it's ugly because we're using exceptions for flow control instead of doing things like checking for file existence

    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...

  • (nodebb)

    Ehm, a C# language that compiles itself to something that is similar to C performance is called C# lol

  • (nodebb)

    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.

  • Officer Johnny Holzkopf (unregistered)

    But fear not! Captain Recursionicus is here to save the day!

  • A Human (unregistered) in reply to MaxiTB

    Vala actually transpiles to c, though.

  • (nodebb) in reply to MaxiTB

    You missed this:

    designed specifically for writing code against Gnome and its associated libraries.

    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.

  • (nodebb) in reply to jeremypnet

    Vala compiles to C which obviously can be compiled to native code rather than a virtual machine like the one C# targets.

    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.

  • (nodebb) in reply to A Human

    Vala actually transpiles to c, though.

    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.

  • (nodebb) in reply to Jaime

    It looks like Vala's yield is similar to C#'s await.

    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.

Leave a comment on “Asynchronous Directories”

Log In or post as a guest

Replying to comment #704177:

« Return to Article