[Dlang Episode 99] D Language - version (for conditional compilation)

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • ►Full DLang Series Playlist: • D Language (DLang) Pro...
    ►Find full courses on: courses.mshah.io/
    ►Join as member to get perks: / @mikeshah
    ►Lesson Description: In this lesson I show you how we do conditional compilation in the D programming language. If you're coming from a C background, then you're probably use to using the preprocessor with #if/#define/#endif and other related ideas. D does not have a preprocessor, because it can compute so much at compile-time, and often this ends up making the language much cleaner. So in this lesson I introduce 'version' which can be used to control conditional compilation, whether for specific features or platforms. I'll show a few examples, and one real world use case where I use this in my code. As always, share your interesting use cases with the community in the discussion below!
    ►Please like and subscribe to help the channel!
    ►RUclips Channel: / mikeshah
    ►Join our free community: courses.mshah....

Комментарии • 14

  • @GaryChike
    @GaryChike 2 месяца назад +2

    D'liteful ... on of my favorite programming languages!

    • @MikeShah
      @MikeShah  2 месяца назад +1

      D Rocks!

    • @GaryChike
      @GaryChike 2 месяца назад +1

      @@MikeShah 'D 🪨🪨🪨'

    • @MikeShah
      @MikeShah  2 месяца назад

      @@GaryChike 🤣

  • @bsdooby
    @bsdooby 2 месяца назад +1

    and another great one!

  • @disdroid
    @disdroid 2 месяца назад +1

    version(unittest) { ... } comes in handy. I had a problem wherei i needed the fqn of a type and the types defined inside unittest {} weren't in the module namespace. I moved them into version blocks and that solved the issue.

    • @disdroid
      @disdroid 2 месяца назад +1

      The main use of version for me is in combination with configurations in my dub file. I can then build a specific version by using "dub -c my version" and that sets the version identifiers the build.

    • @MikeShah
      @MikeShah  2 месяца назад +1

      @@disdroid Very cool! Thanks for providing a use case here for configuration!

  • @twenty-fifth420
    @twenty-fifth420 2 месяца назад +1

    I feel like I Need to watch some C stuff because while I can read it 90 percent of the time now. There is always that 10 percent where my brain doesn't register # is NOT a comment, but a preprocessor directive.
    And it does not help that many devs treat their preprocessed commands with # LIKE comments. Like, I just wanna build this library for one place, I don't know how to use the GCC magic incantations all the time computer programmer, help me OUT here lol.
    Anyway, back to the video. Just a tiny thing. I treat # internally as a 'directive' in C since I can barely parse otherwise how headers and functional macros...work. Otherwise, I will have a headache.

    • @MikeShah
      @MikeShah  2 месяца назад

      Good note! Indeed, depending on the compiler there may be more magic with preprocessor directives. As far as getting through this video, the main thing 'version' replaces is the need for:
      #if WIN_32
      // Do some conditional thing here for windows
      #else
      // Do something for anything non-windows
      #endif
      My compiler video might be useful for seeing the preprocessor in action: ruclips.net/video/ksJ9bdSX5Yo/видео.html

  • @kevinchopra9111
    @kevinchopra9111 2 месяца назад +1

    cool...