Good programming practice question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alex

    Good programming practice question

    Hi,

    I was just wandering which one is correct, better, or better programming
    practice?

    //Case #1
    public class Main
    {
    ClassA a = new ClassA();
    a.Value = "some value";
    a = ModifyClassA(a) ;
    Console.WriteLi ne(a.Value);
    }
    private ClassA ModifyClassA(Cl assA a)
    {
    a.Value += "something" ;
    return a;
    }

    Or this:

    //Case #2
    public class Main
    {
    ClassA a = new ClassA();
    a.Value = "some value";
    ModifyClassA(a) ;
    Console.WriteLi ne(a.Value);
    }
    private void ModifyClassA(Cl assA a)
    {
    a.Value += "something" ;
    }

    //Where CassA is:

    public class ClassA
    {
    string m_value;
    public ClassA(){ m_value = "";}
    public string Value
    {
    get{return m_value;}
    set{m_value = value;}
    }
    }

    I'm writing this on the fly so sorry if it doesn't compile.
    I would appriciage your oppinion.

    Thanks,
    Alex


  • news.microsoft.com

    #2
    Re: Good programming practice question

    whats easier for you is what you should use.


    "alex" <aleks79@yahoo. com> wrote in message
    news:uCKvu2mnDH A.1488@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > I was just wandering which one is correct, better, or better programming
    > practice?
    >
    > //Case #1
    > public class Main
    > {
    > ClassA a = new ClassA();
    > a.Value = "some value";
    > a = ModifyClassA(a) ;
    > Console.WriteLi ne(a.Value);
    > }
    > private ClassA ModifyClassA(Cl assA a)
    > {
    > a.Value += "something" ;
    > return a;
    > }
    >
    > Or this:
    >
    > //Case #2
    > public class Main
    > {
    > ClassA a = new ClassA();
    > a.Value = "some value";
    > ModifyClassA(a) ;
    > Console.WriteLi ne(a.Value);
    > }
    > private void ModifyClassA(Cl assA a)
    > {
    > a.Value += "something" ;
    > }
    >
    > //Where CassA is:
    >
    > public class ClassA
    > {
    > string m_value;
    > public ClassA(){ m_value = "";}
    > public string Value
    > {
    > get{return m_value;}
    > set{m_value = value;}
    > }
    > }
    >
    > I'm writing this on the fly so sorry if it doesn't compile.
    > I would appriciage your oppinion.
    >
    > Thanks,
    > Alex
    >
    >[/color]


    Comment

    • Kevin Carter

      #3
      Good programming practice question

      This is subjective, but your Case #2 example seems to be
      more clear. If I was going to write it, I'd write
      something like #2.
      [color=blue]
      >-----Original Message-----
      >Hi,
      >
      >I was just wandering which one is correct, better, or[/color]
      better programming[color=blue]
      >practice?
      >
      >//Case #1
      >public class Main
      >{
      > ClassA a = new ClassA();
      > a.Value = "some value";
      > a = ModifyClassA(a) ;
      > Console.WriteLi ne(a.Value);
      >}
      >private ClassA ModifyClassA(Cl assA a)
      >{
      > a.Value += "something" ;
      > return a;
      >}
      >
      >Or this:
      >
      >//Case #2
      >public class Main
      >{
      > ClassA a = new ClassA();
      > a.Value = "some value";
      > ModifyClassA(a) ;
      > Console.WriteLi ne(a.Value);
      >}
      >private void ModifyClassA(Cl assA a)
      >{
      > a.Value += "something" ;
      >}
      >
      >//Where CassA is:
      >
      >public class ClassA
      >{
      > string m_value;
      > public ClassA(){ m_value = "";}
      > public string Value
      > {
      > get{return m_value;}
      > set{m_value = value;}
      > }
      >}
      >
      >I'm writing this on the fly so sorry if it doesn't[/color]
      compile.[color=blue]
      >I would appriciage your oppinion.
      >
      >Thanks,
      >Alex
      >
      >
      >.
      >[/color]

      Comment

      • news.microsoft.com

        #4
        Re: Good programming practice question

        What colour of panties should I wear.

        Whats everybody else wearing, I wana copy.

        *bleet**bleet** bleet**bleet*

        "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
        news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .[color=blue]
        > This is subjective, but your Case #2 example seems to be
        > more clear. If I was going to write it, I'd write
        > something like #2.
        >[color=green]
        > >-----Original Message-----
        > >Hi,
        > >
        > >I was just wandering which one is correct, better, or[/color]
        > better programming[color=green]
        > >practice?
        > >
        > >//Case #1
        > >public class Main
        > >{
        > > ClassA a = new ClassA();
        > > a.Value = "some value";
        > > a = ModifyClassA(a) ;
        > > Console.WriteLi ne(a.Value);
        > >}
        > >private ClassA ModifyClassA(Cl assA a)
        > >{
        > > a.Value += "something" ;
        > > return a;
        > >}
        > >
        > >Or this:
        > >
        > >//Case #2
        > >public class Main
        > >{
        > > ClassA a = new ClassA();
        > > a.Value = "some value";
        > > ModifyClassA(a) ;
        > > Console.WriteLi ne(a.Value);
        > >}
        > >private void ModifyClassA(Cl assA a)
        > >{
        > > a.Value += "something" ;
        > >}
        > >
        > >//Where CassA is:
        > >
        > >public class ClassA
        > >{
        > > string m_value;
        > > public ClassA(){ m_value = "";}
        > > public string Value
        > > {
        > > get{return m_value;}
        > > set{m_value = value;}
        > > }
        > >}
        > >
        > >I'm writing this on the fly so sorry if it doesn't[/color]
        > compile.[color=green]
        > >I would appriciage your oppinion.
        > >
        > >Thanks,
        > >Alex
        > >
        > >
        > >.
        > >[/color][/color]


        Comment

        • Arran Pearce

          #5
          Re: Good programming practice question

          Good code practise is quite a big issue when your working in a team, so its
          not as if the question deserves that sort of response.


          "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
          news:u2abJHnnDH A.2528@TK2MSFTN GP12.phx.gbl...[color=blue]
          > What colour of panties should I wear.
          >
          > Whats everybody else wearing, I wana copy.
          >
          > *bleet**bleet** bleet**bleet*
          >
          > "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
          > news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .[color=green]
          > > This is subjective, but your Case #2 example seems to be
          > > more clear. If I was going to write it, I'd write
          > > something like #2.
          > >[color=darkred]
          > > >-----Original Message-----
          > > >Hi,
          > > >
          > > >I was just wandering which one is correct, better, or[/color]
          > > better programming[color=darkred]
          > > >practice?
          > > >
          > > >//Case #1
          > > >public class Main
          > > >{
          > > > ClassA a = new ClassA();
          > > > a.Value = "some value";
          > > > a = ModifyClassA(a) ;
          > > > Console.WriteLi ne(a.Value);
          > > >}
          > > >private ClassA ModifyClassA(Cl assA a)
          > > >{
          > > > a.Value += "something" ;
          > > > return a;
          > > >}
          > > >
          > > >Or this:
          > > >
          > > >//Case #2
          > > >public class Main
          > > >{
          > > > ClassA a = new ClassA();
          > > > a.Value = "some value";
          > > > ModifyClassA(a) ;
          > > > Console.WriteLi ne(a.Value);
          > > >}
          > > >private void ModifyClassA(Cl assA a)
          > > >{
          > > > a.Value += "something" ;
          > > >}
          > > >
          > > >//Where CassA is:
          > > >
          > > >public class ClassA
          > > >{
          > > > string m_value;
          > > > public ClassA(){ m_value = "";}
          > > > public string Value
          > > > {
          > > > get{return m_value;}
          > > > set{m_value = value;}
          > > > }
          > > >}
          > > >
          > > >I'm writing this on the fly so sorry if it doesn't[/color]
          > > compile.[color=darkred]
          > > >I would appriciage your oppinion.
          > > >
          > > >Thanks,
          > > >Alex
          > > >
          > > >
          > > >.
          > > >[/color][/color]
          >
          >[/color]


          Comment

          • Erik Frey

            #6
            Re: Good programming practice question

            A third solution (to consolidate functionality) is this:

            //Case #1
            public class Main
            {
            ClassA a = new ClassA();
            a.Value = "some value";
            a.Modify();
            Console.WriteLi ne(a.Value);
            }

            //Where ClassA is:

            public class ClassA
            {
            string m_value;
            public ClassA(){ m_value = "";}
            public string Value
            {
            get{return m_value;}
            set{m_value = value;}
            }
            public void Modify()
            {
            m_value += "something" ;
            }
            }


            Comment

            • Richard A. Lowe

              #7
              Re: Good programming practice question

              Kevin is right #2 is clearer - it avoids a completely non-functional
              reference copy, as you have in Case #1. In fact Case #2 could be said to be
              a refactor of Case #1 with the non-functional code removed. #1 implies you
              are changing out the reference to a for some reason, when in fact you are
              always re-assigning it to the same thing again - pointless, IMO.

              Richard

              --
              Veuillez m'excuser, mon Français est très pauvre. Cependant, si vous voyez
              mauvais C #, c'est mon défaut!
              "alex" <aleks79@yahoo. com> wrote in message
              news:uCKvu2mnDH A.1488@TK2MSFTN GP12.phx.gbl...[color=blue]
              > Hi,
              >
              > I was just wandering which one is correct, better, or better programming
              > practice?
              >
              > //Case #1
              > public class Main
              > {
              > ClassA a = new ClassA();
              > a.Value = "some value";
              > a = ModifyClassA(a) ;
              > Console.WriteLi ne(a.Value);
              > }
              > private ClassA ModifyClassA(Cl assA a)
              > {
              > a.Value += "something" ;
              > return a;
              > }
              >
              > Or this:
              >
              > //Case #2
              > public class Main
              > {
              > ClassA a = new ClassA();
              > a.Value = "some value";
              > ModifyClassA(a) ;
              > Console.WriteLi ne(a.Value);
              > }
              > private void ModifyClassA(Cl assA a)
              > {
              > a.Value += "something" ;
              > }
              >
              > //Where CassA is:
              >
              > public class ClassA
              > {
              > string m_value;
              > public ClassA(){ m_value = "";}
              > public string Value
              > {
              > get{return m_value;}
              > set{m_value = value;}
              > }
              > }
              >
              > I'm writing this on the fly so sorry if it doesn't compile.
              > I would appriciage your oppinion.
              >
              > Thanks,
              > Alex
              >
              >[/color]


              Comment

              • news.microsoft.com

                #8
                Re: Good programming practice question

                Then discuss it with ur team.


                "Arran Pearce" <arran.pearce@b acoll.ac.uk> wrote in message
                news:%23B7KYQnn DHA.2424@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                > Good code practise is quite a big issue when your working in a team, so[/color]
                its[color=blue]
                > not as if the question deserves that sort of response.
                >
                >
                > "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in[/color]
                message[color=blue]
                > news:u2abJHnnDH A.2528@TK2MSFTN GP12.phx.gbl...[color=green]
                > > What colour of panties should I wear.
                > >
                > > Whats everybody else wearing, I wana copy.
                > >
                > > *bleet**bleet** bleet**bleet*
                > >
                > > "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
                > > news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .[color=darkred]
                > > > This is subjective, but your Case #2 example seems to be
                > > > more clear. If I was going to write it, I'd write
                > > > something like #2.
                > > >
                > > > >-----Original Message-----
                > > > >Hi,
                > > > >
                > > > >I was just wandering which one is correct, better, or
                > > > better programming
                > > > >practice?
                > > > >
                > > > >//Case #1
                > > > >public class Main
                > > > >{
                > > > > ClassA a = new ClassA();
                > > > > a.Value = "some value";
                > > > > a = ModifyClassA(a) ;
                > > > > Console.WriteLi ne(a.Value);
                > > > >}
                > > > >private ClassA ModifyClassA(Cl assA a)
                > > > >{
                > > > > a.Value += "something" ;
                > > > > return a;
                > > > >}
                > > > >
                > > > >Or this:
                > > > >
                > > > >//Case #2
                > > > >public class Main
                > > > >{
                > > > > ClassA a = new ClassA();
                > > > > a.Value = "some value";
                > > > > ModifyClassA(a) ;
                > > > > Console.WriteLi ne(a.Value);
                > > > >}
                > > > >private void ModifyClassA(Cl assA a)
                > > > >{
                > > > > a.Value += "something" ;
                > > > >}
                > > > >
                > > > >//Where CassA is:
                > > > >
                > > > >public class ClassA
                > > > >{
                > > > > string m_value;
                > > > > public ClassA(){ m_value = "";}
                > > > > public string Value
                > > > > {
                > > > > get{return m_value;}
                > > > > set{m_value = value;}
                > > > > }
                > > > >}
                > > > >
                > > > >I'm writing this on the fly so sorry if it doesn't
                > > > compile.
                > > > >I would appriciage your oppinion.
                > > > >
                > > > >Thanks,
                > > > >Alex
                > > > >
                > > > >
                > > > >.
                > > > >[/color]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                • news.microsoft.com

                  #9
                  Re: Good programming practice question

                  What is good for youre team may not work for our team. Its a subjective
                  matter.

                  If it where the case we wouldnt need software engineers, we would have that
                  ONE PERFECT APP, or one perect API call.

                  But we dont.

                  "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
                  news:u%23zbqprn DHA.2140@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                  > Then discuss it with ur team.
                  >
                  >
                  > "Arran Pearce" <arran.pearce@b acoll.ac.uk> wrote in message
                  > news:%23B7KYQnn DHA.2424@TK2MSF TNGP10.phx.gbl. ..[color=green]
                  > > Good code practise is quite a big issue when your working in a team, so[/color]
                  > its[color=green]
                  > > not as if the question deserves that sort of response.
                  > >
                  > >
                  > > "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in[/color]
                  > message[color=green]
                  > > news:u2abJHnnDH A.2528@TK2MSFTN GP12.phx.gbl...[color=darkred]
                  > > > What colour of panties should I wear.
                  > > >
                  > > > Whats everybody else wearing, I wana copy.
                  > > >
                  > > > *bleet**bleet** bleet**bleet*
                  > > >
                  > > > "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
                  > > > news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .
                  > > > > This is subjective, but your Case #2 example seems to be
                  > > > > more clear. If I was going to write it, I'd write
                  > > > > something like #2.
                  > > > >
                  > > > > >-----Original Message-----
                  > > > > >Hi,
                  > > > > >
                  > > > > >I was just wandering which one is correct, better, or
                  > > > > better programming
                  > > > > >practice?
                  > > > > >
                  > > > > >//Case #1
                  > > > > >public class Main
                  > > > > >{
                  > > > > > ClassA a = new ClassA();
                  > > > > > a.Value = "some value";
                  > > > > > a = ModifyClassA(a) ;
                  > > > > > Console.WriteLi ne(a.Value);
                  > > > > >}
                  > > > > >private ClassA ModifyClassA(Cl assA a)
                  > > > > >{
                  > > > > > a.Value += "something" ;
                  > > > > > return a;
                  > > > > >}
                  > > > > >
                  > > > > >Or this:
                  > > > > >
                  > > > > >//Case #2
                  > > > > >public class Main
                  > > > > >{
                  > > > > > ClassA a = new ClassA();
                  > > > > > a.Value = "some value";
                  > > > > > ModifyClassA(a) ;
                  > > > > > Console.WriteLi ne(a.Value);
                  > > > > >}
                  > > > > >private void ModifyClassA(Cl assA a)
                  > > > > >{
                  > > > > > a.Value += "something" ;
                  > > > > >}
                  > > > > >
                  > > > > >//Where CassA is:
                  > > > > >
                  > > > > >public class ClassA
                  > > > > >{
                  > > > > > string m_value;
                  > > > > > public ClassA(){ m_value = "";}
                  > > > > > public string Value
                  > > > > > {
                  > > > > > get{return m_value;}
                  > > > > > set{m_value = value;}
                  > > > > > }
                  > > > > >}
                  > > > > >
                  > > > > >I'm writing this on the fly so sorry if it doesn't
                  > > > > compile.
                  > > > > >I would appriciage your oppinion.
                  > > > > >
                  > > > > >Thanks,
                  > > > > >Alex
                  > > > > >
                  > > > > >
                  > > > > >.
                  > > > > >
                  > > >
                  > > >[/color]
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • news.microsoft.com

                    #10
                    Re: Good programming practice question

                    Use yer noggin.

                    *takes notes* "Cannot work under own iniative..."


                    "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in message
                    news:u%23zbqprn DHA.2140@TK2MSF TNGP09.phx.gbl. ..[color=blue]
                    > Then discuss it with ur team.
                    >
                    >
                    > "Arran Pearce" <arran.pearce@b acoll.ac.uk> wrote in message
                    > news:%23B7KYQnn DHA.2424@TK2MSF TNGP10.phx.gbl. ..[color=green]
                    > > Good code practise is quite a big issue when your working in a team, so[/color]
                    > its[color=green]
                    > > not as if the question deserves that sort of response.
                    > >
                    > >
                    > > "news.microsoft .com" <discussion@dis cussion.microso ft.com> wrote in[/color]
                    > message[color=green]
                    > > news:u2abJHnnDH A.2528@TK2MSFTN GP12.phx.gbl...[color=darkred]
                    > > > What colour of panties should I wear.
                    > > >
                    > > > Whats everybody else wearing, I wana copy.
                    > > >
                    > > > *bleet**bleet** bleet**bleet*
                    > > >
                    > > > "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
                    > > > news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .
                    > > > > This is subjective, but your Case #2 example seems to be
                    > > > > more clear. If I was going to write it, I'd write
                    > > > > something like #2.
                    > > > >
                    > > > > >-----Original Message-----
                    > > > > >Hi,
                    > > > > >
                    > > > > >I was just wandering which one is correct, better, or
                    > > > > better programming
                    > > > > >practice?
                    > > > > >
                    > > > > >//Case #1
                    > > > > >public class Main
                    > > > > >{
                    > > > > > ClassA a = new ClassA();
                    > > > > > a.Value = "some value";
                    > > > > > a = ModifyClassA(a) ;
                    > > > > > Console.WriteLi ne(a.Value);
                    > > > > >}
                    > > > > >private ClassA ModifyClassA(Cl assA a)
                    > > > > >{
                    > > > > > a.Value += "something" ;
                    > > > > > return a;
                    > > > > >}
                    > > > > >
                    > > > > >Or this:
                    > > > > >
                    > > > > >//Case #2
                    > > > > >public class Main
                    > > > > >{
                    > > > > > ClassA a = new ClassA();
                    > > > > > a.Value = "some value";
                    > > > > > ModifyClassA(a) ;
                    > > > > > Console.WriteLi ne(a.Value);
                    > > > > >}
                    > > > > >private void ModifyClassA(Cl assA a)
                    > > > > >{
                    > > > > > a.Value += "something" ;
                    > > > > >}
                    > > > > >
                    > > > > >//Where CassA is:
                    > > > > >
                    > > > > >public class ClassA
                    > > > > >{
                    > > > > > string m_value;
                    > > > > > public ClassA(){ m_value = "";}
                    > > > > > public string Value
                    > > > > > {
                    > > > > > get{return m_value;}
                    > > > > > set{m_value = value;}
                    > > > > > }
                    > > > > >}
                    > > > > >
                    > > > > >I'm writing this on the fly so sorry if it doesn't
                    > > > > compile.
                    > > > > >I would appriciage your oppinion.
                    > > > > >
                    > > > > >Thanks,
                    > > > > >Alex
                    > > > > >
                    > > > > >
                    > > > > >.
                    > > > > >
                    > > >
                    > > >[/color]
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • alex

                      #11
                      Re: Good programming practice question

                      Richard, thanks for your post. I also think that case #2 is better because
                      there is no reassignment of a reference. I just wan't sure how intuitive it
                      would be for people who would later read the code.

                      "Richard A. Lowe" <chadich@yumspa myumYahoo.com> wrote in message
                      news:OSCYF2qnDH A.424@TK2MSFTNG P10.phx.gbl...[color=blue]
                      > Kevin is right #2 is clearer - it avoids a completely non-functional
                      > reference copy, as you have in Case #1. In fact Case #2 could be said to[/color]
                      be[color=blue]
                      > a refactor of Case #1 with the non-functional code removed. #1 implies[/color]
                      you[color=blue]
                      > are changing out the reference to a for some reason, when in fact you are
                      > always re-assigning it to the same thing again - pointless, IMO.
                      >
                      > Richard
                      >
                      > --
                      > Veuillez m'excuser, mon Français est très pauvre. Cependant, si vous[/color]
                      voyez[color=blue]
                      > mauvais C #, c'est mon défaut!
                      > "alex" <aleks79@yahoo. com> wrote in message
                      > news:uCKvu2mnDH A.1488@TK2MSFTN GP12.phx.gbl...[color=green]
                      > > Hi,
                      > >
                      > > I was just wandering which one is correct, better, or better programming
                      > > practice?
                      > >
                      > > //Case #1
                      > > public class Main
                      > > {
                      > > ClassA a = new ClassA();
                      > > a.Value = "some value";
                      > > a = ModifyClassA(a) ;
                      > > Console.WriteLi ne(a.Value);
                      > > }
                      > > private ClassA ModifyClassA(Cl assA a)
                      > > {
                      > > a.Value += "something" ;
                      > > return a;
                      > > }
                      > >
                      > > Or this:
                      > >
                      > > //Case #2
                      > > public class Main
                      > > {
                      > > ClassA a = new ClassA();
                      > > a.Value = "some value";
                      > > ModifyClassA(a) ;
                      > > Console.WriteLi ne(a.Value);
                      > > }
                      > > private void ModifyClassA(Cl assA a)
                      > > {
                      > > a.Value += "something" ;
                      > > }
                      > >
                      > > //Where CassA is:
                      > >
                      > > public class ClassA
                      > > {
                      > > string m_value;
                      > > public ClassA(){ m_value = "";}
                      > > public string Value
                      > > {
                      > > get{return m_value;}
                      > > set{m_value = value;}
                      > > }
                      > > }
                      > >
                      > > I'm writing this on the fly so sorry if it doesn't compile.
                      > > I would appriciage your oppinion.
                      > >
                      > > Thanks,
                      > > Alex
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      • alex

                        #12
                        Re: Good programming practice question

                        I agree. But in my case I'm passing SqlParameter object to a function. I'm
                        too so sure if I want create my own derivative of SqlParameter class.

                        Thanks,
                        Alex


                        "Erik Frey" <eriksjunk@hotm ail.com> wrote in message
                        news:uh5ZDennDH A.1740@TK2MSFTN GP12.phx.gbl...[color=blue]
                        > A third solution (to consolidate functionality) is this:
                        >
                        > //Case #1
                        > public class Main
                        > {
                        > ClassA a = new ClassA();
                        > a.Value = "some value";
                        > a.Modify();
                        > Console.WriteLi ne(a.Value);
                        > }
                        >
                        > //Where ClassA is:
                        >
                        > public class ClassA
                        > {
                        > string m_value;
                        > public ClassA(){ m_value = "";}
                        > public string Value
                        > {
                        > get{return m_value;}
                        > set{m_value = value;}
                        > }
                        > public void Modify()
                        > {
                        > m_value += "something" ;
                        > }
                        > }
                        >
                        >[/color]


                        Comment

                        • alex

                          #13
                          Re: Good programming practice question

                          Thanks for your post Kevin. I agree.

                          "Kevin Carter" <anonymous@disc ussions.microso ft.com> wrote in message
                          news:04bb01c39e 70$f6298db0$a40 1280a@phx.gbl.. .[color=blue]
                          > This is subjective, but your Case #2 example seems to be
                          > more clear. If I was going to write it, I'd write
                          > something like #2.
                          >[color=green]
                          > >-----Original Message-----
                          > >Hi,
                          > >
                          > >I was just wandering which one is correct, better, or[/color]
                          > better programming[color=green]
                          > >practice?
                          > >
                          > >//Case #1
                          > >public class Main
                          > >{
                          > > ClassA a = new ClassA();
                          > > a.Value = "some value";
                          > > a = ModifyClassA(a) ;
                          > > Console.WriteLi ne(a.Value);
                          > >}
                          > >private ClassA ModifyClassA(Cl assA a)
                          > >{
                          > > a.Value += "something" ;
                          > > return a;
                          > >}
                          > >
                          > >Or this:
                          > >
                          > >//Case #2
                          > >public class Main
                          > >{
                          > > ClassA a = new ClassA();
                          > > a.Value = "some value";
                          > > ModifyClassA(a) ;
                          > > Console.WriteLi ne(a.Value);
                          > >}
                          > >private void ModifyClassA(Cl assA a)
                          > >{
                          > > a.Value += "something" ;
                          > >}
                          > >
                          > >//Where CassA is:
                          > >
                          > >public class ClassA
                          > >{
                          > > string m_value;
                          > > public ClassA(){ m_value = "";}
                          > > public string Value
                          > > {
                          > > get{return m_value;}
                          > > set{m_value = value;}
                          > > }
                          > >}
                          > >
                          > >I'm writing this on the fly so sorry if it doesn't[/color]
                          > compile.[color=green]
                          > >I would appriciage your oppinion.
                          > >
                          > >Thanks,
                          > >Alex
                          > >
                          > >
                          > >.
                          > >[/color][/color]


                          Comment

                          Working...