Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 13 2022 19:04
    dennisdoomen commented #266
  • Dec 13 2022 14:41
    marcvannieuwenhuijzen commented #266
  • Dec 12 2022 14:31
    dennisdoomen commented #266
  • Dec 12 2022 14:18
    marcvannieuwenhuijzen opened #266
  • Dec 08 2022 03:56
    dependabot[bot] labeled #265
  • Dec 08 2022 03:56

    dependabot[bot] on bundler

    Bump nokogiri from 1.13.9 to 1.… (compare)

  • Dec 08 2022 03:56
    dependabot[bot] opened #265
  • Oct 21 2022 07:02

    dennisdoomen on bundler

    (compare)

  • Oct 21 2022 07:02

    dennisdoomen on master

    Bump nokogiri from 1.13.6 to 1.… (compare)

  • Oct 21 2022 07:02
    dennisdoomen closed #264
  • Oct 21 2022 03:06
    dependabot[bot] labeled #264
  • Oct 21 2022 03:06

    dependabot[bot] on bundler

    Bump nokogiri from 1.13.6 to 1.… (compare)

  • Oct 21 2022 03:06
    dependabot[bot] opened #264
  • Aug 03 2022 14:13
    dennisdoomen commented #196
  • Jul 30 2022 17:59
    dennisdoomen commented #263
  • Jul 30 2022 17:59

    dennisdoomen on master

    Fixed example (#263) (compare)

  • Jul 30 2022 17:59
    dennisdoomen closed #263
  • Jul 30 2022 11:39
    bkoelman opened #263
  • Jul 23 2022 08:10
    dennisdoomen closed #261
  • Jul 23 2022 08:09
    dennisdoomen commented #261
Brendan Forster
@shiftkey
:wave:
Dennis Doomen
@dennisdoomen
Welcome to this discussion about the current state and the future of www.csharpcodingguidelines.com and it's source at https://github.com/dennisdoomen/csharpguidelines
For a nice introduction on the rationale and background of my initiative, consider reading https://github.com/dennisdoomen/csharpguidelines/blob/master/Guidelines/0001_Introduction.md
Dennis Doomen
@dennisdoomen
Welcome @shiftkey
Maher Jendoubi
@MaherJendoubi
Hello
Maher Jendoubi
@MaherJendoubi
I would like to discuss AV1520 about the using of var keyword since C# 3.0
Dennis Doomen
@dennisdoomen
Go ahead
Maher Jendoubi
@MaherJendoubi
I use var when the type name is too long
Dennis Doomen
@dennisdoomen
It's a heated topic at my current project as well.
Maher Jendoubi
@MaherJendoubi
ok
It is better to invest in the name of the variable when using var
Dennis Doomen
@dennisdoomen
The primary reason for this guideline is to make sure that developers don't return too much from a method. The analogy is often to not return the entire truck if you only need a package.
Maher Jendoubi
@MaherJendoubi
I mean not only for the very obvious type
Dennis Doomen
@dennisdoomen
I understand. Now imagine somebody is reviewing your code through Github. Will he or she be able to determine the type involved?
Maher Jendoubi
@MaherJendoubi
in the most of cases I would say yes
var retListPlanning = new ObservableCollection<PlanningArea>();
Dennis Doomen
@dennisdoomen
I can't judge those cases from my side, but if that's indeed the truth, you're fine.
That's fine.
Maher Jendoubi
@MaherJendoubi
could you guess the type of retListPlanning?
Dennis Doomen
@dennisdoomen
Obviously ;-)
Maher Jendoubi
@MaherJendoubi
ObservableCollection<PlanningArea> retListPlanning = new ObservableCollection<PlanningArea>();
which is the better :smile: ?
my point of view is to avoid coding like this: ObservableCollection<PlanningArea> x = new ObservableCollection<PlanningArea>();
Dennis Doomen
@dennisdoomen
That's the purpose of AV1520 as well.
Maher Jendoubi
@MaherJendoubi
but I suggest to use var
and invest more in the naming type
aha
Maher Jendoubi
@MaherJendoubi
when you said obviously have you some examples for non obvious please?
Dennis Doomen
@dennisdoomen
From the guideline: var myfoo = MyFactoryMethod.Create("arg");
Ivan Korneliuk
@vansha
Hi, I almost always use var without a deep thinking on it. Although was against it early days on. Rationale - isn't it somehow correlated with Hungarian notation? Why it should be that important to understand exact type for the variable.
Dennis Doomen
@dennisdoomen
@vansha I use it during code reviews to detect some developer exposing way too much from a method and causing unnecessary coupling between classes. When that developer uses var, it will be more difficult to spot.
Maher Jendoubi
@MaherJendoubi
@vansha if you like abstraction then var do the same thing with types
I would also say not use var x; (Back to Basics)
Maher Jendoubi
@MaherJendoubi
also I can't use var x = null;
Dennis Doomen
@dennisdoomen
I still believe var should only be used if the type is obvious from the context.
Maher Jendoubi
@MaherJendoubi
@dennisdoomen it makes sense for me I totally agree with you but I prefer to use var keyword as much I can :)
Ivan Korneliuk
@vansha
@dennisdoomen Not sure I understand the point of exposing too much from a method. I mean how not using var protects that. Could you please give a simple example?
Dennis Doomen
@dennisdoomen
The point is that you wan to prevent too much coupling between classes. For instance, you have some kind of domain entity with a method to do ask some information about one of its internal objects. I've seen developers returning an entire internal object even though only a single primitive value was sufficient. Quite often they don't realize that this causes way too much coupling.