Hacker Newsnew | past | comments | ask | show | jobs | submit | rawling's commentslogin

A record wrapping a string, indicating what the string represents, so you can't mix it up with a different thing also represented by a string.

Yes, you can have two different record types which both wrap a string value.

As a (bad) trivial example, you could wrap reading a file in this kind of monstrosity:

    var fileResult = Helpers.ReadFile(@"c:\temp\test.txt");

    Console.WriteLine("Extracted:");
    Console.WriteLine(Helpers.ExtractString(fileResult));

    public record FileRead(string value);
    public record FileError(string value);
    public union FileResult(FileError, FileRead);

    public static class Helpers
    {
        public static FileResult ReadFile(string fileName)
        {
            try
            {
                var fileResult = System.IO.File.ReadAllText(fileName);
                return new FileRead(fileResult);
            }
            catch (Exception ex)
            {
                return new FileError(ex.Message);
            }
        }

        public static string ExtractString(FileResult result)
        {
            return result switch
            {
                FileError err => $"An Error occured: {err.value}",
                FileRead content => content.value,
                _ => throw new NotImplementedException()
            };
        }
    }

Now, such an example would be an odd way to do things ( particuarly because we're not actually avoiding the try/catch inside ), but you get the point. Both FileRead(string value) and FileError(string value) wrap strings in the same way, but are different record types, and the union FileResult ties them back together in a way where you can tell which you have.

It's more useful implemented a level deeper, so that the exception is never raised and caught, because exceptions aren't particularly cheap in .NET.


> 5 years of updates

Is this an improvement on how long whatever it's talking about usually gets updates for, or is putting a limit on it at all a bad sign? I've only seen this with regards to mobile phones before.


There are no guarantees your laptop will ever get a single update (let alone 5 years) unless they state as much. Most do not state any guarantee or less than 5 years.


Second sentence of the body:

> Tesla disabled the hacked FSD after detecting illegal activation hardware in over 100,000 cars in countries all over the world, where the feature has not received approval.

Sounds like the former.


Less than 5 seconds into the video shows it spraying a shade of green.






Is this meant to go to... a _particular_ search?



So, 11.3k results already.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: