*** New C# Language V2.0 Specification Now Available ***

  • Thread starter Eric Gunnerson [MS]
  • Start date
J

Jon Skeet [C# MVP]

Frans Bouma said:
A class should be a logical element in the structure of the system.
Not a way to cut up code because a random person cooked up the idea that a
file of XYZ lines is too large. After all, cutting up a class in multiple
classes pollutes the class hierarchy with extra types that are hardly
different, creating extra problems when the types require each-others
data/logic (they were first stored in the same class, remember ;) ).

I agree that a class should be a logical element - but I've rarely seen
a single element of that many lines which isn't better broken down into
smaller subelements. That's not to say it should be done artificially,
of course.
Although 7000 lines is a lot, you sometimes end up with large
classes, for example a main form class which controls all child windows
and main gui application logic (not the core application logic). It can
become very messy when you are chopping that up in smaller classes, which
will be used in just 1 spot: the main gui form, but because they're other
classes, you have add overhead code to communicate with them to reach
their data.

If it controls *all* the child windows, I would have thought that would
be too much - each child window should have its own class, I'd imagine.
Maybe I'm misunderstanding you though.

For what it's worth, I've been in a similar situation with all the GUI
logic for a mobile web application being in one class (this was written
a few years ago). Having started down that road, it's very difficult to
refactor it into smaller classes (we've tried twice). If we'd started
off with the goal of factoring out different parts, I'm sure it
wouldn't have been too difficult though. (One of the main problems was
that it was originally going to be a small app, and then it grew much,
much bigger.)
 
N

news.microsoft.com

If you look at the BCLs you will see a huge deep inheratence tree. Also a
reason why we dont have multpile inheratance.

(never could spell that word too :D)

Im sure if you look more abstract at youre class you will see places you can
break it up or generalise and derive, try a little normalisation:D
 
F

Frans Bouma

If it controls *all* the child windows, I would have thought that would
be too much - each child window should have its own class, I'd imagine.
Maybe I'm misunderstanding you though.

Child windows, for example in an MDI situation or docked inside the
main window, should control themselves, but say, the child window wants
something done in the application... where to put that logic, when yuo can
also start it from the menu for example... this will increase the main
form's code a lot and it's hard to chop it into multiple pieces because
you then end up with a lot of events, properties and other stuff that
wasn't even there in the beginning ;) exactly like you describe yourself:
For what it's worth, I've been in a similar situation with all the GUI
logic for a mobile web application being in one class (this was written
a few years ago). Having started down that road, it's very difficult to
refactor it into smaller classes (we've tried twice). If we'd started
off with the goal of factoring out different parts, I'm sure it
wouldn't have been too difficult though. (One of the main problems was
that it was originally going to be a small app, and then it grew much,
much bigger.)

That's what I ment :) But I agree that developers should write
classes that do a certain thing and not control the whole universe.
However it's sometimes hard to make the decision: add it to an existing
class or create a new class. Decisions like that in the early start of a
project can make the difference between a small set of large classes vs. a
large set of small classes.

FB
 
J

Jon Skeet [C# MVP]

Frans Bouma said:
That's what I ment :) But I agree that developers should write
classes that do a certain thing and not control the whole universe.
However it's sometimes hard to make the decision: add it to an existing
class or create a new class. Decisions like that in the early start of a
project can make the difference between a small set of large classes vs. a
large set of small classes.

Absolutely - but I'd usually prefer a large set of small classes, and I
*really* don't think that encouraging a small set of large classes is
something the language specification ought to be doing.

The main use of partial classes as far as I can see, however, is
keeping the machine-generated parts away from the human-generated
parts. That seems a perfectly reasonable thing to encourage.
 
M

Mike Schilling

Thanks, Eric. I don't suppose there's a list of changed sections anywhere,
or an MS Word diff tool I'm unaware of..
 
C

cody

And as I recall, C\C++ reserved all names starting with __ or something to
that effect, so it was your fault if you screwed up, they told you
beforehand what not to use.

C++ added the keyword "mutable" (and others). There are no leading
underscores. I shit on breaking changes. The code is quickly corrected and
thats better than having to write ___mutable the next 30 years I use this
language!
 
K

Kevin Cline

Eric Gunnerson said:
--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.


The big goal for partial classes *is* for generated code. Being able to keep
that separate from the user code simpifies the user model.

Code generation is a work-around for bad languages and/or libraries.
If the language has sufficient power and libraries are well-designed
then there is little need to generate code. For example, you could
use Lex and YACC to generate C++ code, or you could use the SPIRIT
parser classes instead.
 
K

Kerry Sanders

That sounds like a really bad reason to use partial types, IMO. Is it
really not possible to refactor that code into more classes which would
increase the readability of the code to start with? I've only *very*
rarely seen classes which really deserve to be that long.


I am not saying that there way of doing things is right or wrong. I can
definitely say I have written my share of crap code durin my 16 years a a
programmer, but I did hear someone say one time that if a class printout does
not fit on just one page, it is probably too long. :)
 
D

Daniel O'Connell

cody said:
C++ added the keyword "mutable" (and others). There are no leading
underscores. I shit on breaking changes. The code is quickly corrected and
thats better than having to write ___mutable the next 30 years I use this
language!
Well, when it comes down to it, thats your problem. You are really far to
rude to actually achieve anything. But, anyway, adding a keyword when it has
to be added is one thing, in this case its not, no matter how much you want
to complain about it.
--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
 
F

Frans Bouma

(e-mail address removed) (Kevin Cline) wrote in
Code generation is a work-around for bad languages and/or libraries.
If the language has sufficient power and libraries are well-designed
then there is little need to generate code. For example, you could
use Lex and YACC to generate C++ code, or you could use the SPIRIT
parser classes instead.

haha :) So you type all your database access code by hand? Great
sense of productivity ;)

Lex and Yacc are tools to generate a parser. They use an abstract
input language to produce specialized code you could have written by hand
but that would take a lot of time.

Code generation is a mechanism to produce sourcecode you otherwise
had to type in by hand. True, you probably can design away some of it by
using patterns and class hierarchies, but I estimate not more than 50% of
what you have to write. That's at least 50% left to type in by hand. Now,
I don't know but when I have to chose between a click of a button to
produce that code or typing it all in by hand, I will opt for the button
click. However, perhaps you love typing repetitive code for hours and
hours, I don't know ;)

FB
 
F

Frans Bouma

I am not saying that there way of doing things is right or wrong. I can
definitely say I have written my share of crap code durin my 16 years a
a programmer, but I did hear someone say one time that if a class
printout does not fit on just one page, it is probably too long. :)

Of course it's too long... for that piece of paper. ;)

Measurements of class aspects by using concepts like paper-size,
file amount or screen size are stupid. It's the functionality the class
represents, plus the data it encapsulates and represents. There is no
golden rule where to draw the line which says "at this point the class is
generic enough. Adding more will make it a big blob without a meaning".
Some will argue that that line comes very quickly, others have a different
opinion. (and the fun thing is, both sides think they're right, while
there is no rule which even defines the 'right' in this case) :)

FB, who once learned that a C function should fit on a 80x24 wyse
screen and if it was larger than that, the function was bad.
 
C

cody

Daniel O'Connell said:
something
Well, when it comes down to it, thats your problem. You are really far to
rude to actually achieve anything. But, anyway, adding a keyword when it has
to be added is one thing, in this case its not, no matter how much you want
to complain about it.


Iam not rude. I simply disagree with the way they want to implement "yield"
and I do not understand why in C++ keywords was added tenth of year after
the initial version and a worldwide codebase of c++ code of gigabytes.

And in C# is in its very early days with small codebase and only two years
past since introduction they refuse to make such a small change even if the
likelyhood that some code gets broken is minimal and fixing that code is
small matter of programming.

When c# is now already in a state where no new keywords can be added what
will it be in 10 or more years?

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no ****ing ads]
 
F

Frans Bouma

cody said:
Iam not rude. I simply disagree with the way they want to implement
"yield" and I do not understand why in C++ keywords was added tenth of
year after the initial version and a worldwide codebase of c++ code of
gigabytes.

And in C# is in its very early days with small codebase and only two
years past since introduction they refuse to make such a small change
even if the likelyhood that some code gets broken is minimal and fixing
that code is small matter of programming.

When c# is now already in a state where no new keywords can be added
what will it be in 10 or more years?

Cody, for what's worth, I fully agree with you. The masses of
developers still have to come to .NET, and by not adding keywords now but
a 'workaround' it will be regretted later and then it is much worse to add
keywords.

After all, only code that get's recompiled is affected, and can be
fixed easily by a global replace routine.

FB
 
D

Daniel O'Connell

cody said:
Iam not rude. I simply disagree with the way they want to implement "yield"
and I do not understand why in C++ keywords was added tenth of year after
the initial version and a worldwide codebase of c++ code of gigabytes.

And in C# is in its very early days with small codebase and only two years
past since introduction they refuse to make such a small change even if the
likelyhood that some code gets broken is minimal and fixing that code is
small matter of programming.

When c# is now already in a state where no new keywords can be added what
will it be in 10 or more years?
Anyone that speaks like you, and I quote, "I shit on breaking changes" is
rude.
--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu
[noncommercial and no ****ing ads]
 
D

Daniel O'Connell

Frans Bouma said:
Cody, for what's worth, I fully agree with you. The masses of
developers still have to come to .NET, and by not adding keywords now but
a 'workaround' it will be regretted later and then it is much worse to add
keywords.

After all, only code that get's recompiled is affected, and can be
fixed easily by a global replace routine.

While I agree that the strange syntax is weird, I do not think using return
in this case is proper, furthermore that is a hacky work around if I've ever
seen one, far worse than context keywords. Changing the meaning of return in
one circumstance is a very very bad thing and I think it would confuse
people more than using context sensitive wording.
 
K

Kerry Sanders

Measurements of class aspects by using concepts like paper-size,
file amount or screen size are stupid. It's the functionality the class
represents, plus the data it encapsulates and represents. There is no

Opinions. I understand your class represents the functionality that you need.
I just made a funny observation that someone said to me a long time ago. No
need for you to take it personally.

Or course, the 7000 lines of code is your code and you are the one that has to
work on it. I am glad it isn't me.
 
A

Alvin Bruney

7000 likes comprising or /// and /* */ blocks :D how much is dead code :D
how much is actualy used, man i bet the JIT on that takes a while.
 
F

Frans Bouma

Opinions. I understand your class represents the functionality that you
need. I just made a funny observation that someone said to me a long
time ago. No need for you to take it personally.

Who said it was personal? I read your comment, and perhaps it was
funny to you, I heard that remark as a serious remark mentioned to novice
developers (not me) a lot, and not as a funny remark. That's also why I
mentioned the 'has to fit on screen', quote, which is funny today, but was
hard reality in those days.

Nevertheless, I read several comments in this thread about the
class that is 7000 lines long. My project explorer window class in LLBLGen
Pro is 3116 lines long. That's 3116 lines of eventhandlers, management
code for the form and its controls (treeview etc), a lot of context menu
manager routines and handlers and properties. NO Application logic
whatsoever, that's placed in an assembly in a lower tier. True, I could
have subclassed the treeview and place logic there. However that would add
ANOTHER layer to the event chain running from the treeview's context menus
to the main gui the project explorer is docked in. What fun :) (and it
doesn't decrease complexity, which is the real reason a lot of lines is
not preferable: when you use a lot of classes you can abstract away some
code, however when abstracting away code snippet ABC increases complexity
because housekeeping event handlers have to be added, it doesn't help a
lot ;) )

Just an example how code can grow. Crying fool how crap a class
must be when it is 7000 lines long is moronic. Doing so shows you haven't
programmed complex gui's in .NET. True, when you want, you can group every
set of controls in a new control and hide the code in there, which will
lower the # of lines in the beginning, but will bite you in the foot when
overall application behaviour has to be kept in sync.

I'm sorry, but joking around about a guy's 7000 lines class is out
of order until you've seen the code yourself.
Or course, the 7000 lines of code is your code and you are the one that
has to work on it. I am glad it isn't me.

It wasn't me with the class of 7000 lines. However starting to
throw mud on the guy who had that class is zealotery: "Look, I know how to
design OO hierarchies, you're hierarchy stinks". As I said: measurements
of correct class size based on whatever measurement is pretty bogus: it's
one way or the other: a big class with not a lot of overhead code or a
large set of small classes with a lot of overhead code. What the most
optimal situation is between the two is not determinable by looking at the
class size, because what law proves that that measurement is the golden
rule? Nothing.

7000 is a lot of lines, however it can also have a lot of methods,
a lot of comments. I have classes which have a couple of thousand lines.
Most of these classes are not about a data element and the code targeting
that data element, but a group of functionality in one spot, like a
database driver or a main-form gui manager. Why would I have to chop it up
into more than one class? And better: what should be used as a dividing
rule what goes where? Chopping up classes can be good, but when there is
NO THEORY behind it, it's the most stupid thing a person can do: it will
increase the overhead in your application and if you're not careful it
will do that on a dramatic scale.

When you have a complex GUI which tries to keep everything in sync
(try to start thinking about the logic you need when you have an element
in your gui which name is shown in tabs, treeviews, controls, window
headers etc. that's eventhandler galore and a lot of code.) classes grow
out of proportion, classes can grow then beyond an amount of lines some
people find 'disgusting' or 'crappy design'. I can tell you: I've spend a
lot of time refactoring my GUI classes to make them smaller, however at
some point it isn't worth the effort, simply because chopping them up will
only create bigger classes.

Also, some program very verbose. I add a lot of commentlines, add a
lot of small methods and they all have XML comment tags, I also use a lot
of whitespace. This will add a lot of lines extra.

Don't forget that classes are logical, semantical boundaries of
code. It's simply stupid to divide a logical, semantical unit into two or
more classes simply someone says hte amount of lines is beyond a scale no-
one knows if its true or not. Again a reason why critizing a guy's 7000
lines class (which you do, don't forget that) is, sorry, a lame thing to
do, who says you are better than he is and your code is better than his?
Perhaps you would have ended up with also a 7000 line class as he did.
(imagine a form with a tabcontrol with a lot of tabs and a lot of code to
keep that working the way it should, that's a lot of overhead code you
can't abstract away).

Just a FYI.

FB
 
F

Frans Bouma

7000 likes comprising or /// and /* */ blocks :D how much is dead code
:D how much is actualy used, man i bet the JIT on that takes a while.

A method of 7000 lines will indeed take a while (or better: will not
/ never be jitted). A class with 500 small methods can be jitted perfectly,
as the jit jits methods on the fly, not just a whole class when it is
loaded.

FB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top