News for hackers. Stuff that matters.
Re:Be wary of functions which take several parameters of the... by raverbashing on Friday September 27, 2019 @05:16AM (#21089923)
Yes but creating the scaffolding is the hard part and getting to the "once the thing is wrapped" takes more time than the other solutions.

You could "force" parameter naming, and it would be easier.

Types are good but having 10 types of string doesn't make sense.

Re:Be wary of functions which take several parameters of the... by louthy on Friday September 27, 2019 @07:11AM (#21090590)
> Types are good but having 10 types of string doesn't make sense.

It really does make sense. Types like string, int, float, etc. are poorly defined for most things they represent. There's no context and are just one step away from being dynamic, like values in a dynamic language.

By enforcing a contextual contract (perhaps with additional constructors that constrain the value) you leverage the type-system to do the hard work of checking for stupid mistakes. On large code-bases this reduction in cognitive complexity makes a whole class of bugs go away.

So, 100s of types of string could make sense, it really does depend how many types of thing you have which are distinct and can be represented as a string.

But once they're defined, they're not strings any more, they have an internal state which is a string, yes, but their type is not a string.

Re:Be wary of functions which take several parameters of the... by bluGill on Friday September 27, 2019 @08:07AM (#21090947)
The hard part - at least in languages I've worked with - is how hard it is to create a new string that acts like a string should act but isn't a string. In many (C's typedef) you can create two new types, but nothing stops you from using mixing them up as they freely convert to each other without even a warning. In some object oriented languages you can often create a new string - but only by writing by hand every single member function.

Of course none of the above are unsolvable problems. I've never seen anything that actually makes it easy, but I won't claim to have seen everything.

Re:Be wary of functions which take several parameters of the... by lonelappde on Friday September 27, 2019 @01:54PM (#21094473)
You are conflating dynamic types with weak types. Int is a relatively weak type and HttpPort is a strong type regardless whether static or dynamic
Re:Be wary of functions which take several parameters of the... by eterps on Friday September 27, 2019 @06:35AM (#21090360)
> Types are good but having 10 types of string doesn't make sense.

Not if the strings are clearly distinct (like a name being different from an e-mail address).

Re:Be wary of functions which take several parameters of the... by michaelcampbell on Friday September 27, 2019 @07:54AM (#21090852)
> 10 types of string

It's not. It's 10 types.

Re:Be wary of functions which take several parameters of the... by bewo001 on Monday September 30, 2019 @11:12AM (#21116175)
I want to agree, but the problem is that you now need 10 versions for many operations that are in a string library. Hidden assumptions -- like 'replacing a character in a string can never fail' -- may fail (eg in an email address type which only allows only a limited char set). Some constraints can't be expressed without dependent types (say you want to define a URI type that limits the length to 2000 chars total but is composed of variable length components, like the domain name, query strings etc).
Re:Be wary of functions which take several parameters of the... by michaelcampbell on Wednesday October 02, 2019 @05:17PM (#21140826)
> but the problem is that you now need 10 versions for many operations that are in a string library

Do you? Or do you need just the operations for the things that are relevant to the type at hand? Limiting a broad API to the needed interface for the type you're modeling is a GOOD thing.