473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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
Nov 15 '05 #1
12 1329
whats easier for you is what you should use.
"alex" <al*****@yahoo.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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

Nov 15 '05 #2
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 programmingpractice?

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

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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
.

Nov 15 '05 #3
What colour of panties should I wear.

Whats everybody else wearing, I wana copy.

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

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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
.

Nov 15 '05 #4
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" <di********@discussion.microsoft.com> wrote in message
news:u2**************@TK2MSFTNGP12.phx.gbl...
What colour of panties should I wear.

Whats everybody else wearing, I wana copy.

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

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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
.


Nov 15 '05 #5
A third solution (to consolidate functionality) is this:

//Case #1
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
a.Modify();
Console.WriteLine(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";
}
}
Nov 15 '05 #6
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" <al*****@yahoo.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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

Nov 15 '05 #7
Then discuss it with ur team.
"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <di********@discussion.microsoft.com> wrote in message news:u2**************@TK2MSFTNGP12.phx.gbl...
What colour of panties should I wear.

Whats everybody else wearing, I wana copy.

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

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
>}
>private ClassA ModifyClassA(ClassA a)
>{
> a.Value += "something";
> return a;
>}
>
>Or this:
>
>//Case #2
>public class Main
>{
> ClassA a = new ClassA();
> a.Value = "some value";
> ModifyClassA(a);
> Console.WriteLine(a.Value);
>}
>private void ModifyClassA(ClassA 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
>
>
>.
>



Nov 15 '05 #8
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" <di********@discussion.microsoft.com> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Then discuss it with ur team.
"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <di********@discussion.microsoft.com> wrote in

message
news:u2**************@TK2MSFTNGP12.phx.gbl...
What colour of panties should I wear.

Whats everybody else wearing, I wana copy.

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

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
> >}
> >private ClassA ModifyClassA(ClassA a)
> >{
> > a.Value += "something";
> > return a;
> >}
> >
> >Or this:
> >
> >//Case #2
> >public class Main
> >{
> > ClassA a = new ClassA();
> > a.Value = "some value";
> > ModifyClassA(a);
> > Console.WriteLine(a.Value);
> >}
> >private void ModifyClassA(ClassA 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
> >
> >
> >.
> >



Nov 15 '05 #9
Use yer noggin.

*takes notes* "Cannot work under own iniative..."
"news.microsoft.com" <di********@discussion.microsoft.com> wrote in message
news:u%****************@TK2MSFTNGP09.phx.gbl...
Then discuss it with ur team.
"Arran Pearce" <ar**********@bacoll.ac.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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" <di********@discussion.microsoft.com> wrote in

message
news:u2**************@TK2MSFTNGP12.phx.gbl...
What colour of panties should I wear.

Whats everybody else wearing, I wana copy.

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

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
> >}
> >private ClassA ModifyClassA(ClassA a)
> >{
> > a.Value += "something";
> > return a;
> >}
> >
> >Or this:
> >
> >//Case #2
> >public class Main
> >{
> > ClassA a = new ClassA();
> > a.Value = "some value";
> > ModifyClassA(a);
> > Console.WriteLine(a.Value);
> >}
> >private void ModifyClassA(ClassA 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
> >
> >
> >.
> >



Nov 15 '05 #10
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" <ch*****@yumspamyumYahoo.com> wrote in message
news:OS*************@TK2MSFTNGP10.phx.gbl...
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" <al*****@yahoo.com> wrote in message
news:uC**************@TK2MSFTNGP12.phx.gbl...
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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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


Nov 15 '05 #11
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" <er*******@hotmail.com> wrote in message
news:uh**************@TK2MSFTNGP12.phx.gbl...
A third solution (to consolidate functionality) is this:

//Case #1
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
a.Modify();
Console.WriteLine(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";
}
}

Nov 15 '05 #12
Thanks for your post Kevin. I agree.

"Kevin Carter" <an*******@discussions.microsoft.com> wrote in message
news:04****************************@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.WriteLine(a.Value);
}
private ClassA ModifyClassA(ClassA a)
{
a.Value += "something";
return a;
}

Or this:

//Case #2
public class Main
{
ClassA a = new ClassA();
a.Value = "some value";
ModifyClassA(a);
Console.WriteLine(a.Value);
}
private void ModifyClassA(ClassA 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
.

Nov 15 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: matty | last post by:
Go away for a few days and you miss it all... A few opinions... Programming is a craft more than an art (software engineering, not black magic) and as such, is about writing code that works,...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
45
by: Brett | last post by:
If I do this without declaring a corresponding field, is it considered bad design? What are the advantages or disadvantages to either method? Notice there is not set. public string URL { get...
1
by: trebor | last post by:
I'm learning dotNet, although I first learned programming back in the days when structured programming was all the rage. In both my books and courses, I've seen something like this: Public Class...
150
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
19
by: JoeC | last post by:
I have seen many books that teack coding for C++. What are ways to improve my techniques for writing larger programs. I have written many demo programs learning some aspects of code wether it be...
26
by: vlsidesign | last post by:
I am a newbie and going through "The C programming language" by Kernighan & Richie on my own time (I'm not a programmer but I want to learn because it can save me time in my normal job, and it is...
8
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine,...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.