Git Product home page Git Product logo

Comments (7)

cjakobsen avatar cjakobsen commented on July 30, 2024 3

This documentation from Microsoft also speaks against using == for comparison so I think we should keep it.

from atc-coding-rules.

rickykaare avatar rickykaare commented on July 30, 2024 1

As far as I understand using == for comparing two strings will be the same as using string.Equals() with StringComparison.Ordinal (given that the two strings are of type string, and not cast to e.g. object).

In my mind, this way of comparing strings are by far the most commonly used, so applying the MA0006 rule in general would add a lot of clutter.

In most cases I think it would be very obvious if you need to compare using case-insensitivity or the CurrentCulture, and then use the string.Equals() instead.

from atc-coding-rules.

egil avatar egil commented on July 30, 2024

What StringComparison style is used with a == b? If it is not StringComparison.Ordinal, then a.Equals(b, StringComparison.Ordinal will perform better.

Besides that, I agree that it does NOT improve readability.

from atc-coding-rules.

MrAndersPedersen avatar MrAndersPedersen commented on July 30, 2024

Please red comment from cjacobsen.

from atc-coding-rules.

egil avatar egil commented on July 30, 2024

As far as I understand using == for comparing two strings will be the same as using string.Equals() with StringComparison.Ordinal

That's surprising to me @rickykaare, but you are right, at least if we read the latest string.cs code. Here we see that EqualsHelper is called when from both the operators ==/!= and from the Equals method when StringComparison.Ordinal is set.

That takes the performance concern out of the equation for me. The question that is left is whether we want to be explicit in our code about our intentions, e.g. signaling that, yes, we have thought about culture and this is what we want.

from atc-coding-rules.

egil avatar egil commented on July 30, 2024

ROOT=NONE, because in most cases we are only doing ordinal comparisons anyway, and == leads to cleaner code.

Exception to this rule when working on an application that is multi cultured.

from atc-coding-rules.

davidkallesen avatar davidkallesen commented on July 30, 2024

https://github.com/atc-net/atc-coding-rules/blob/main/documentation/CodeAnalyzersRules/Meziantou/MA0006.md

from atc-coding-rules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.