|
If you need sub-function-level blocks...
---- You're right.
These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets .
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Then you should refactor your code.
It's meant to save typing. Refactoring (design) has nothing to do with that unless by refactoring you intend to rename every class a single letter or something.
|
|
|
|
|
One of the fundamental principles of Object Oriented design is data hiding. If you are directly accessing members outside of a class then you are violating a philosophy and your code can be rewritten to be more maintainable. The reason with is so popular is the same reason MS is on the everything must be public tirade and both of which are poor design concepts IMHO.
The long and the short of it, is that if you want VB specific functionality use VB; don't alter C# until there is only one language. Furthermore, if saving typing concern is the primary concern of a Software Developer he or she is in the wrong field. While I have an excellent typing speed I spend 90% of my day thinking, not typing and the result is far better than if I had spent the entire day typing alone. No amount of feature that reduces the amount I have to type will save me work, save a complete layer generator.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: One of the fundamental principles of Object Oriented design is data hiding. If you are directly accessing members outside of a class then you are violating a philosophy and your code can be rewritten to be more maintainable.
Which has nothing to do with the point. You can and should access members inside the class or friend classes etc, unless you never access members at all except within the same class. In which case, there's no point even writing them as the class is virtually unusable. Furthermore, public members aren't all that bad they just shouldn't be abused. And lastly, you can use this on just more on a public member.
Sorry, but this is apples to oranges. It's a language construct meant as a shortcut to save typing. There's no reason the idea of refactoring should even come into play as a reason to not use it. Granted, you can write some horrid code by abusing it, but the again there's a lot of ways to do that in any environment.
|
|
|
|
|
If you are accessing members in a class you do not need with as you are already withing the namespace.
If you are accessing members outside of a class you have to ask yourself the question ... Can these operations be contained within this class rather than requiring my code to have intimate knowledge of the class, 9 times out of ten the answer is yes. In which case using the with keyword is more typing as it would only be one line of code to instruct the class to do it's operation.
Bottom line: In any case where someone is using a with there is a manner in which to write the code without the with that is better engineered.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: If you are accessing members in a class you do not need with as you are already withing the namespace.
Not if the class is a friend. Of course, I assume C# has that concept.
Ennis Ray Lynch, Jr. wrote: If you are accessing members outside of a class you have to ask yourself the question ... Can these operations be contained within this class rather than requiring my code to have intimate knowledge of the class, 9 times out of ten the answer is yes. In which case using the with keyword is more typing as it would only be one line of code to instruct the class to do it's operation.
Even with using 90% (which I doubt unless you only use crap code) that means one out of ten times you don't need to refactor it, and it might save you some typing.
Ennis Ray Lynch, Jr. wrote: Bottom line: In any case where someone is using a with there is a manner in which to write the code without the with that is better engineered.
Except in your 10% example.
I'm all for refactoring, but you cannot claim public or friend members will never be used otherwise it's a bad design. The fact is, they are there, and if some people can't design well it doesn't mean we shouldn't save typing when we need to access one.
It's also a quick and handy way to avoid a name space clash if you need something down and dirty real quick.
|
|
|
|
|
My claim is that in all cases you can write a better design without with than with with. To refute my claim I challenge you to come up with a scenario that shows otherwise.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Because you can't refactor someone else's code (say .NET BCL classes), and you may still need to populate multiple properties at once.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: My claim is that in all cases you can write a better design without with than with with. To refute my claim I challenge you to come up with a scenario that shows otherwise.
I'll use a pseudocode since I don't do C#...
MyWindow.Title = "blah";
MyWindow.Width = 640;
MyWindow.Height = 480;
MyWindow.BackgroundColor = Green;
MyEmployee.DoAction(Fire);
MyEmployee.DoAction(TellEmployeHesNotFired);
MyEmployee.GetAction(EmployeePissedOff);
MyEmployee.DoAction(TellEmployeeToTakeAJoke);
Would you care to explain to me how you intend to refactor that to make the window and employee classes not need those public methods/properties it uses to interact with them? Or do you still contend that using any public method is a bad design? I don't, because I'm not sure how you could otherwise use a class outside of creating an object.
|
|
|
|
|
While I cannot say whether the approach below is the best possible approach it is clearly better alternative than your example and I spent less time coming up with them.
MyWindow myWindow = new MyWindow("blah", 640, 480, Green);
or
myWindow.Initialize("blah", 640, 480, Green);
Then
myEmployee.BeginWorkFlow(sillyWorkFlow);
...
public class Employee{
protected void DoAction(IAction action);
public void BeginWorkFlow(IWorkflow workflow)
foreach(IAction action in workflow){
DoAction(action);
}
}
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: While I cannot say whether the approach below is the best possible approach it is clearly better alternative than your example and I spent less time coming up with them.
I spent about 5 seconds thinking of them and a bit longer to type them. Please don't assume. I don't check this site every 5 mins of my life.
So your grand scheme of never using a public method is to just reconstruct an object every time you need to change an attribute? Sorry man, but that means this conversation just went the path of being too silly for me to bother with if that's your idea of refactoring.
I mean surely you can foresee the need to change a window's width without recreating it every time right?
|
|
|
|
|
You missed by point by a mile. However, I feel it is clearly explained to anyone that wants to take the time to understand it so I will not belabor the point any more. My statements and examples are based, not only on my personal experience, but common design patterns as well as Fowler's book on refactoring.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: You missed by point by a mile.
No I didn't.
My point is you cannot refactor a lawn mower into a molecule and still expect it to cut grass. You refuse to accept it. Your whole stance that With can be replaced solely by refactoring is bogus. And I don't need to read a design book to tell me you need public methods at times; otherwise, it would be impossible to even use the class in the first place.
If you'd like to forgo obscure references and rather show me how to completely eliminate this 10% public nuances (where With helps), I'd entertain that. But, I don't think you can man.
You want to talk about your workflow idea? Tell me, is there no way to specify what goes into the workflow outside of the class, or is the class the only thing able to specify workflow items? It doesn't matter where you shift the load, someone somewhere has to specify it and making it only avialable in the class means you don't have something to reusable.
Edit* I'll check this again tomorrow. It won't take 24 hours for my reply, and I'm not trying to make you wait on purpose. But, I have a task I need to finish for work. Such is life. lol
|
|
|
|
|
Fowler's book is not an obscure reference but the defacto book on refactoring and is an excellent resource.
Shifting the load is designed primarily to offload the work onto items that have more reason to understand their workings. What we have here is a difference in design philosophy. Whereas yours seems to be give a developer everything, always. Mine is to only provide appropriate functionality in appropriate locations. I am sure there are pros to your side that I am unaware but I am only familiar with the RAD portion of such a philosophy which I write off as a mistake because I really am a Waterfall/Agile type of guy if there is such a thing.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: Shifting the load is designed primarily to offload the work onto items that have more reason to understand their workings. What we have here is a difference in design philosophy
Trust me, we bare *almost* the same one. I just don't think you see my point. I don't think the guts of a class should be exposed, but there are plenty of times when you will need to access public members, which is my point. I offer it's impossible tn never have a public member and so you have a chance to take use of this. And, I don't really see the With keyword as evil, scary and inbred sure, but evil no and can be used as a good thing at times.
|
|
|
|
|
MyEmployee.DoAction(Fire);
MyEmployee.DoAction(TellEmployeHesNotFired);
MyEmployee.GetAction(EmployeePissedOff);
MyEmployee.DoAction(TellEmployeeToTakeAJoke);
You did not properly handle the GetAction between the two DoAction calls.
Just because you are unable to think of a reasonable use for a feature, it does not mean that there are no reasonable uses. The use of "with" becomes more apparent with more complicated objects (though you can still do without it).
If you are accessing methods and properties of a deeply embedded object (such as a bar object embedded at a level of foo.many.layers.of.complexity.bar), you could write the code using a variety of methods such as
With foo.many.layers.of.complexity.bar
.PropertyA = "String"
.MethodB(params)
End With or
Dim tempBar as Bar = foo.many.layers.of.complexity.bar
tempBar.PropertyA = "String"
tempBar.MethodB(params) or even
foo.many.layers.of.complexity.bar.PropertyA = "String"
foo.many.layers.of.complexity.bar.MethodB(params)
I don't claim to be a know it all, for I know that I am not...
I usually have an answer though.
|
|
|
|
|
GetAction was unassigned and thus not required. My response is not meant as a buildable scenario but a demonstration that with can be avoided through better design. I struggle to see how someone can justify
foo.many.layers.of.complexity.bar.PropertyA = "String"
as good design.
What you are saying, to me at least, is that when the design sucks with is extremely useful. If the design sucks, I refactor it others use with ; only one solution reduces technical debt and results in a better engineered solution. As far as I am concerned I will never support a language feature that supports the philosophy that bad code is ok, so long as it is easy to use.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
How would you refactor this?
object.we.did.not.design.but.must.use.PropertyA = "String" Sadly, not every component that goes into our apps are ones that we have created ourselves.
Not every solution can be perfect, but we can at least strive to make it as elegant as possible.
Granted that this is still a simplification, but here is a real world object hierarchy that is this complex (the JulMar.ATAPI namespace for .NET TAPI development):
TapiManager.Lines(0).Addresses(0).Calls(0).Features(0).CanPark
No one ever said that the "With" keyword was added to make it easy. In fact, the "With" keyword can cause problems if misused (But so can c/c++). Yes, you can write code that does the exact same thing without using the "With" keyword. You can also perform multiplication using only the addition operator. Should we get rid of the multiplication operator?
I have not bothered to learn C#. The only reason is that I have yet to find anything I could not do using VB.NET that I could do in C#. Why buy a red handled screwdriver when I already own a blue one?
Back in the days before .NET, using a With block was very handy when working with databases as you could have code that was easy to read like this:
With rsEmployee
.AddNew
![Name] = "John Doe"
![Title] = "Peon"
![Extension] = "123"
.Update
End With This comprised 99.9% of all With blocks I've used.
I don't claim to be a know it all, for I know that I am not...
I usually have an answer though.
modified on Wednesday, October 8, 2008 4:38 PM
|
|
|
|
|
It has been a long time since I have used VB but is
with TapiManager.Lines(0).Addresses(0).Calls(0).Features(0)
.CanPark
end with
Even valid? And what happens when the lines collection is empty, a known condition that should have been checked. What we have here is trying to justify adding with to C# and providing no other scenario for its use than.the.one.argument.of.some.developer.creating.a.ridiculous.namespace whereas the arguments against adding the keyword, readability, reuse, value of code design just scream don't add the feature.
The bottom line, and I said this earlier, if you want to use VB.NET use VB.NET. There is a reason they are two different languages.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: if saving typing concern is the primary concern of a Software Developer
I always wondered just what that primary concern had to be
But on a serious note, I suspect that Pascal language fame was so short and C spread so fast mainly because BEGIN/END was replaced with {}
|
|
|
|
|
If you want to save on typing use resharper.
VB style keywords belong in VB. Why bastatrdize C# , it make no sense. If you are a C# developer that wants to use the with keyword to save some typing then then switch to VB. Just remember that the time that you save by using the with keyword will be lost by having to type those ridiculous if... then... end if statements.
modified on Wednesday, October 8, 2008 5:16 AM
|
|
|
|
|
sucram wrote: Just remember that the time that you save by using the with keyword will be lost by having to type those ridiculous if... then... end if statements.
So by adding WITH to C# you get the time-saving and avoid the IF THEN END statements...
(By the way, I voted NO too. I just don't think your reasoning is fully thought through.)
|
|
|
|
|
Your right I went into a blinding range when I saw the survey and my primeval instincts took over. Hence my grammar and logical sentence construction ability was reduced to grunts.
modified on Wednesday, October 8, 2008 11:05 AM
|
|
|
|
|
I voted you a 5, just because I was in the mood. Yeah, that's right, feel thy wrath! Muwahahahaha!
|
|
|
|
|
Sorry, I couldn't resist.
/ravi
|
|
|
|
|