Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
November 20, 2020 why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
I was reading some posts and this was presented as a snippet of code and was immediately flagged as bad practice. I get some people don't like it but occasionally I prefer this syntax. It feels more declarative and fluent in style. Is there a good technical reason why it is bad practice, e.g. does it make it easier to write bugs? Or is it just what people are used to? Thanks, norm |
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to norm | On Friday, 20 November 2020 at 07:39:10 UTC, norm wrote: > I was reading some posts and this was presented as a snippet of code and was immediately flagged as bad practice. > Eh, I wouldn't quite put it that way. If we're thinking of the same thread, one person said he thought it was a bad idea. That doesn't make it bad practice. It's just his opinion. I think UFCS is an awesome feature. And it's widely used in D code. > I get some people don't like it but occasionally I prefer this syntax. It feels more declarative and fluent in style. Is there a good technical reason why it is bad practice, e.g. does it make it easier to write bugs? Or is it just what people are used to? I think everyone has their own criteria for when to use UFCS. For example, I don't generally write "foo".writeln myself, because I don't think of writeln as being a property of strings. And that's the lens through which I view UFCS: this operation is akin to a property of this type. Other people might not see it that way, and one (not me) could make an argument that this specific usage is bad practice, but the feature itself rocks. |
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to norm | I was the person who wrote that example. It was just an example to show how it can be used. I would not write a function call like that when using a literal. As Mike said, its all up to personal preference. |
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker Attachments:
| On Fri, Nov 20, 2020 at 8:55 AM Mike Parker via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > ... > Eh, I wouldn't quite put it that way. If we're thinking of the > same thread, one person said he thought it was a bad idea. That > doesn't make it bad practice. It's just his opinion. I think UFCS > is an awesome feature. And it's widely used in D code. > I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE. So I am now avoiding UFCS as much as possible and it is a much better experience for me. |
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Friday, 20 November 2020 at 10:03:18 UTC, Daniel Kozak wrote:
>
> I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE. So I am now avoiding UFCS as much as possible and it is a much better experience for me.
Doesn't bother me. Auto-completion is a nice-to-have for me, not a must-have, and I don't miss it when I don't have it.
|
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
On Fri, Nov 20, 2020 at 11:03:18AM +0100, Daniel Kozak via Digitalmars-d-learn wrote: [...] > I remember days when I liked UFCS too . Unfortunately it is not so > awesome when you use it with IDE. So I am now avoiding UFCS as much > as possible and it is a much better experience for me. [...] IMO, if the IDE can't give a good experience with UFCS, then it's the IDE that needs to be fixed, rather than the programmer bending over backwards to please the IDE. T -- I don't trust computers, I've spent too long programming to think that they can get anything right. -- James Miller |
November 20, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On Friday, 20 November 2020 at 10:03:18 UTC, Daniel Kozak wrote:
> I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE.
And I would like to add: if you use in a bigger team. It's annoying when every dev have a own taste.. And together with optional () it's hell - no joke.
The need to think about codeatyle definitions in such detail is a nogo for big projects.
|
November 21, 2020 Re: why is "hello".writeln considered bad? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin | On Friday, 20 November 2020 at 18:46:40 UTC, Martin wrote:
> On Friday, 20 November 2020 at 10:03:18 UTC, Daniel Kozak wrote:
>> I remember days when I liked UFCS too . Unfortunately it is not so awesome when you use it with IDE.
>
> And I would like to add: if you use in a bigger team. It's annoying when every dev have a own taste.. And together with optional () it's hell - no joke.
> The need to think about codeatyle definitions in such detail is a nogo for big projects.
This is a good point. I find with D there are many different ways to write code and each can look different on the page. Where I work we mandated all D code will be implemented in Phobos style and use Phobos and mir source as guides. Some parts do heavily use UFCS/optional() and some parts do not. We have not had issues with readability, but maybe our D code isn't that complicated because it is mostly PC side data analysis tools.
Personally a really like UFCS, even `"hello".writeln;` and I think I'd rather have UFCS than autocompletion. But then I did start out in industry well before autocomplete was a thing so maybe I have never relied on it too much.
Thanks all for the replies!
norm
|
Copyright © 1999-2021 by the D Language Foundation