On Sat, 20 Dec 2014 08:18:22 +0000 Jonathan Marler via Digitalmars-d <[email protected]> wrote:
> Performing a grep on phobos reveals there are currently almost > 3,000 casts. I never like to use casts but they are a necessary > evil. I think anything D can do to help the programmer get their > job done is a win. The initial "pro" I saw for this idea was > improving refactoribility. I see this as a huge win. You claim > it will hide bugs? Could you give an example? autocasting to the types of function arguments is the immediate weak point. what you doing by this is destroying type checking. ok, we doing that from time to time, but you proposing handy sytax for it which will not break when function signature changes. there is topic about "kind of programmers" nearby, where we found that "majority of programmers don't read books". and they tend to use the first tool they see to "make the job done", don't trying to evaluate the long-term consequences. i can assure you that you'll see `cast(auto)` all over their code, 'cause it's simply, it doesn't require even looking at function signature and trying to grasp why it accepts the given types, and "ah, it's so refactorable!" (they love "refactoring", 'cause they don't like to design their software, plus "refactoring" is often the blessed way to do nothing really valuable and still got payed). besides, `cast` is a hack by itself. the good way to deal with hacks is to make them less powerful, not more powerful. you are proposing to make the hack more powerful. there is nothing bad in it... when the language is designed for use by hardcore hackers. but for languages with greater audience this is not a good way to go. hacks will inevitably be abused. it doesn't matter how many times we write in big letters: "PLEASE, DON'T DO THAT!" so hacks must be small and fine-grained, not small and powerful. besides, `cast(auto)` is not decipherable without analyzing the expression (and, possibly, function signature). it is not clear what result of `cast(auto)` will be. this is bad for hack. why `cast` is hack? 'cause it turns off most of the compiler type checking system. that's why we have `to!XXX` thing, which is not so disasterous. and compiler is smart enough to see that `a&0xff` is good for ubyte, for example. we can't make `cast` less powerful now, but what we surely shouldn't do is making it more poweful. > When I requested other people to chime in on this idea I was more > looking for data/examples. Maybe someone will think of an > example that shows this idea could encourage bad coding > practices? Maybe it will hide bugs? My point is, I don't want > to discourage you from providing your opinion, but I would > really like to understand where your opinion comes from. I hope > that wasn't harsh, I've read other posts you've made on the > forums and although I don't agree with everything you say I would > value your assessment. Thanks. it comes from my past expirience. sometimes i just *sense* the smell. powerful hacks are great troublemakers. making Cassandra prophecies is my superpower. ;-)
signature.asc
Description: PGP signature
