• 4 Posts
  • 187 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle

  • DrDeadCrash@programming.devtoMemes@lemmy.mlThe Benefits of World Hunger
    link
    fedilink
    arrow-up
    1
    arrow-down
    3
    ·
    edit-2
    6 days ago

    I think “describing it as if it were normal” only helps the people who support this arrangement because it gets normalized. That’s where the accusation of conservatism came from, that and the way they tried to shut me down with insults.

    Edit: given that there are likely to be a lot of people that agree with this argument unironically, doesn’t it seem irresponsible to play some game where you pretend like you support it? Without ever coming out against it at the end?

    Really, it’s just naked approval, with any disapproval left as an exercise to be performed by the reader.



  • DrDeadCrash@programming.devtoMemes@lemmy.mlThe Benefits of World Hunger
    link
    fedilink
    arrow-up
    1
    arrow-down
    1
    ·
    edit-2
    7 days ago

    Who would build any sort of factory if they did not know that many people would be available to take the jobs at low-pay rates

    Much of the hunger lirerarure talks about how it is important to assure that people are well fed so that they can be more productive. That is nonsense

    No one works harder than hungry people.

    […]well-nourished people are far less willing to do that work

    For those of us at rhe high end of the social ladder, ending hunger globally would be a disaster.

    I guess the irony is lost on me. Nothing here indicates that it’s wrong or should change. Also, you’re a huge asshole.

    Edit: in fact I know people (conservatives) who are totally fine with this arrangement. They are huge assholes too, huh isn’t that weird.















  • The example is simplified, but I dislike returning null in my own code. The function will always execute, left or right doesn’t matter it’s mapped across in the ResultObject class.

    The function must return an IResult<T>, the ResultObject analyzes the IResult<T> checking for IFail or IOk. If it’s IOk the value of type T is retrieved from the Value property of the IOk<T> object and returned, the Some property defaults to true. If the IResult<T> is an IFail, Some is set to false, it copies the message from the IFail object into the ResultObject, and returns the value the was supplied to its constructor.

    I’m just sharing something I find useful, and I hope I can make it useful for others as well. Thanks for the questions.



  • Here’s a real world side project example of how I handle this situation:

     public IResult<T> GetResourceValue<T>(string path)
        {
            string err = $"{typeof(T).FullName} is not available from this Resource ({nameof(FileSystemResource)})";
    
            switch (typeof(T))
            {
                case Type t when t == typeof(DriveInfo):
                    return (IResult<T>)new Ok<DriveInfo>(BackingValue);
                case Type t when t == typeof(DirectoryInfo):
                    err = $"Directory path invalid: {path}";
                    var dir = new DirectoryInfo(path);
    
                    if (dir.Exists)
                        return (IResult<T>)new Ok<DirectoryInfo>(dir);
                    break;
                case Type t when t == typeof(FileInfo):
                    err = $"File path invalid: {path}";
                    var file = new FileInfo(path);
    
                    if (file.Exists)
                        return (IResult<T>)new Ok<FileInfo>(file);
                    break;
            }
            return new Error<T>(err);
        }
    

    You said elsewhere that it feels like you’re doing something wrong if you have to check for every type just to use a Generic. I think you’re right in thinking along those lines. There should be a minimal number of types to check, and Ideally limited via a type constraint.

    Here’s example that includes a constraint:

        public IResult<T> GetValue<T>() where T : struct =>
            typeof(T) switch
            {
                Type t when t == typeof(int) && value <= int.MaxValue =>
                 (IResult<T>)new Ok<int>((int)value),
                Type t when t == typeof(uint) && value <= uint.MaxValue && value >= uint.MinValue =>
                 (IResult<T>)new Ok<uint>((uint)value),
                Type t when t == typeof(byte) && value <= byte.MaxValue && value >= byte.MinValue =>
                 (IResult<T>)new Ok<byte>((byte)value),
                Type t when t == typeof(sbyte) && value <= (int)sbyte.MaxValue =>
                 (IResult<T>)new Ok<sbyte>((sbyte)value),
                Type t when t == typeof(short) && value <= (int)short.MaxValue =>
                 (IResult<T>)new Ok<short>((short)value),
                Type t when t == typeof(ushort) && value <= ushort.MaxValue =>
                 (IResult<T>)new Ok<ushort>((ushort)value),
                Type t when t == typeof(long) && value <= long.MaxValue =>
                 (IResult<T>)new Ok<long>((long)value),
                Type t when t == typeof(ulong) => (IResult<T>)new Ok<int>((int)value),
                _ => new IntegerError<T>()
            };