News for hackers. Stuff that matters.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by vbezhenar on Tuesday August 08, 2023 @10:01PM (#37057898)
I don't like anything implicit in programming languages. Being explicit does not make code unreadable. Being implicit does make code hard to truly understand and requires being a language expert. What's worse, implicit code often pretends to be simple, while in reality it's not.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by smitty1e on Tuesday August 08, 2023 @10:39PM (#37058114)
The general review of anything, "It would have been twice as good if it was half as long" applies.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by mvdtnz on Tuesday August 08, 2023 @11:27PM (#37058379)
Not in the general case, no. Not in programming. I would much rather review (and maintain) 20 lines of clear, readable code than 3 lines of obscure clever code. More lines isn't better, but in the limit fewer lines is very often worse.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by chris_wot on Tuesday August 08, 2023 @11:50PM (#37058508)
Three lines of clever, readable code is also better than 20 lines of obscure boilerplate code.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by OrderlyTiamat on Wednesday August 09, 2023 @03:33AM (#37059673)
In particular if that boilerplate code spans multiple projs and type inheritances for something that really could be done in about three lines. Boilerplate has its own obscurity problems.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by Supermancho on Tuesday August 08, 2023 @11:02PM (#37058240)
destructuring is helpful

[1, 2] = somefun();

Decimal amount = m where this means Decimal amount = m.amount, seems less so.

How do I know that's implicit without tracing the type back?

Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by Guvante on Wednesday August 09, 2023 @12:13AM (#37058614)
Implicit can make things hard to understand meaning it should be used with caution.

But allowing CustomInt i = 0; instead of CustomInt i = CustomInt::Zero; or worse CustomInt i = static_cast<CustomInt>(i); isn't a bad thing.

Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by vbezhenar on Wednesday August 09, 2023 @12:27AM (#37058694)
For me this looks fine:

var i = CustomInt.valueOf(0)

Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by joaonmatos on Wednesday August 09, 2023 @06:40AM (#37060799)
Can’t you do `auto i = CustomInt(0)`? Then all of the construction is explicit (and in a single place in the statement) without repeating.
Re:Are Implicit Operators a Path to Clean Code or a Buggy Ni... by onetoo on Wednesday August 09, 2023 @09:29AM (#37062379)
At the risk of being a pedant, I think your argument is too absolutist for it to really mean anything.

Every programming language, contains something that's implicit in their syntax. I assume you don't dislike every programming language?

A sufficiently stubborn greybeard could use much the same argument to complain about something like ASLR.