Good examples of version() algebra in real code

Walter Bright newshound2 at digitalmars.com
Mon May 22 17:59:35 UTC 2023


On 5/22/2023 4:12 AM, Hipreme wrote:
> Imagine we had the `module input`. Since all OS have a different way to get 
> input, we can basically separate them as you just said, by files. How Haxe 
> solves that is by letting users define a special file name such as:
> `input.windows.hx` and `input.javascript.hx`. Whenever you import that file for 
> usage, it will automatically import the correct file based on your target. I did 
> use that feature and in my experience: This is quite cool and can lead to a 
> single file to read without having any extra concern. The problem is that it did 
> generated a bit of code duplication. Which could be solved by putting the common 
> code in another file.

Yup, that works well.

A nice dividend is, you want to port to a new platform? The only code needed to 
be looked at is the personality module. Much better than it being peppered 
through the source code, and even worse, be unfindable because of the use of 
defaults.



More information about the Digitalmars-d mailing list