Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Property Name Sementics - IsEmpty or Empty

Property Name Sementics - IsEmpty or Empty

Scheduled Pinned Locked Moved C#
question
26 Posts 13 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Can't make up my mind. Coding a class that represents a Polygon. If the polygon has no points should the property name be Empty or IsEmpty?

    B Offline
    B Offline
    BobJanova
    wrote on last edited by
    #21

    The short answer is that both are acceptable and both are used within the Framework, so use whichever you think is better. I typically drop the 'Is'. I also agree with other posters who've said that you should really be defining a Valid (or IsValid ;P ) property which checks that there are at least 3 points (maybe 3 non-colinear points?). The points array being empty isn't really a relevant concern, I don't think.

    1 Reply Last reply
    0
    • L Lost User

      Can't make up my mind. Coding a class that represents a Polygon. If the polygon has no points should the property name be Empty or IsEmpty?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #22

      "Empty"; as "IsEmpty" would be question and would indeed imply either a delegate or a method. "Empty" is a property of the Polygon. "IsEmpty" would be a method that can be called from that property to fetch a value, but a property never begins with "Is". The color of an apple is "Apple.Color", not "Apple.IsColor". Yes, you might be persuaded to prefix the "Is" because the property returns a bool. It shouldn't matter whether it returns a bool or an enum - if it's a property, then it'll have the name of a property - not the form a question.

      Bastard Programmer from Hell :suss:

      1 Reply Last reply
      0
      • L Luc Pattyn

        I guess it would be considered too confusing to have some Parse() methods that throw exceptions on failure, and others that just return false; I do recall a Microsoft recommendation NOT to have a parameter that controls whether failures would throw exceptions, for the same reason. :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #23

        Luc Pattyn wrote:

        it would be considered too confusing

        I disagree; the boolean return and the documentation make it clear.

        L 1 Reply Last reply
        0
        • P PIEBALDconsult

          Luc Pattyn wrote:

          it would be considered too confusing

          I disagree; the boolean return and the documentation make it clear.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #24

          bool.Parse() would always return a bool... :doh:

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          P 1 Reply Last reply
          0
          • L Lost User

            Can't make up my mind. Coding a class that represents a Polygon. If the polygon has no points should the property name be Empty or IsEmpty?

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #25

            Thinking about the way structs such as Size, Point and Rectangle deal with this, I haven't checked, but I don't believe they don't provide a property for this. There is a static read only instance available called Empty that you can use for equality comparison to see if the one you have is empty. Overriding Equals(object), GetHashCode() and providing operator overloads for == and != (and possibly implementing IEquatable<T>) would be the way to do this. I don't think I would use a property for this, I would use a method public bool IsEmpty() as you are asking for information about the object as a whole rather than a part of it which is IMO opinion the purpose of a property.

            Dave
            Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            1 Reply Last reply
            0
            • L Luc Pattyn

              bool.Parse() would always return a bool... :doh:

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #26

              True, but then there's the out parameter.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups