Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 21 07:02

    dennisdoomen on bundler

    (compare)

  • Oct 21 07:02

    dennisdoomen on master

    Bump nokogiri from 1.13.6 to 1.… (compare)

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

    dependabot[bot] on bundler

    Bump nokogiri from 1.13.6 to 1.… (compare)

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

    dennisdoomen on master

    Fixed example (#263) (compare)

  • Jul 30 17:59
    dennisdoomen closed #263
  • Jul 30 11:39
    bkoelman opened #263
  • Jul 23 08:10
    dennisdoomen closed #261
  • Jul 23 08:09
    dennisdoomen commented #261
  • Jul 22 09:20
    dependabot[bot] labeled #262
  • Jul 22 09:20
    dependabot[bot] opened #262
  • Jul 22 09:20

    dependabot[bot] on bundler

    Bump tzinfo from 1.2.9 to 1.2.1… (compare)

  • Jul 14 08:08
    gerryge edited #261
  • Jul 14 08:08
    gerryge edited #261
  • Jul 14 08:05
    gerryge opened #261
  • May 21 08:16

    dennisdoomen on bundler

    (compare)

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.
Ivan Korneliuk
@vansha
Ah, I see. While I understand the concern, still believe that in many cases it would be obvious what sort of data is returned - whether it some primitive type or internal object.
Dennis Doomen
@dennisdoomen
If you're looking at the code from inside Visual Studio...yes.... But what if you're reviewing a Pull Request on GitHub or BitBucket?
Ivan Korneliuk
@vansha
I understand that we're referring code reviews. And understand your point. Just saying that it seems like a rare case, when I can't understand type from a variable name and usage (for common examples that I can imagine):
var employees = repository.FindEmployees(criteria); // Don't really care about 'customers' type. Whether it IEnumerable<Person>, IList or List. Just know that it has a collection semantic.
var topSalary = employees.Select(var emp => emp.CalculateYearSalary()).Max(); // While I don't know exact type of 'topSalary' would be, it's not that important to me. I'm pretty sure it's primitive type like Integer  or Double.
Dennis Doomen
@dennisdoomen
Depends on the context. In your first example, I might wanna know whether somebody is returning an internal domain entity rather than some kind of DTO construct. If it is the former, you end up with unnecessary class coupling and leaky abstractions. In the second example, the difference between an integer and a double isn't really relevant, but might be considered an serious issue in accounting.
Yves Goergen
@ygoe
Ehm, wait a minute, wouldn't you detect such inappropriate return type from the method definition? When it should return an int value it surely can't return a complex internal type. You only need to check the method definition once whereas you'd have to analyse and verify its usage many times. And should the return type be something as unspecific as object you'd have another reason to complain, right?
Dennis Doomen
@dennisdoomen
The point is that I'd like to understand the type without browsing to the method definition. If you're reviewing code through e.g. Github Pull Requests, you won't see all that.
Yves Goergen
@ygoe
But when you only review the use of a method, you can't change the method itself. If you want to be able to influence the method, you need to review its definition. Once that's approved, it's safe.
You can't pull out an internal type of a method that just doesn't return it, so you can't hide it in 'var' as well.
Oleg Kleyman
@OlegKleyman

Hey Guys, with respect to AV1515. Would the literal used here be considered a magic number when the constructor is define as:

/// <param name="characterCount">The amount of characters that a segment should have.</param>
public Segment(int characterCount) and the usage is as such public class

ModelSegment : Segment { public Model() : base(4) {} }

Would the 4 above be considered magic or is being aware of the definition of the parameter be enough?

Dennis Doomen
@dennisdoomen
@OlegKleyman I would still treat that as a magic number. If you're reading this line in an online diff such as on github, you have no clue what it means. And in most cases, the base-class definition would be in a seperate file.
Oleg Kleyman
@OlegKleyman
@dennisdoomen Then how would you know if the naming is an accurate representation of the value if you're unaware what it's used for?