Two things that bug me about C#

  • Thread starter Thread starter C# Learner
  • Start date Start date
C

C# Learner

1) you can't declare anything outside of a class, enum, etc. Thus you can't
declare globals right after the namespace declaration.

I'm glad that this isn't possible in C#. :-)

Unlike the cross-breed (some might even say hack) that is C++, C# is a
well-designed, "real" OOP language.
 
1) you can't declare anything outside of a class, enum, etc. Thus you can't
declare globals right after the namespace declaration. I just don't
understand why Microsoft decided to do away with easy to
use/declare/understand global variables. Even C++ can do this. I used to
put globals all in one spot for easy maintaining, this is intuitive. Now
they are spread all over the code, in different classes as "static"
variables, which to access I have to write out the full class and veriable
name.

2) Almost along the same lines, I can't just create a function, I have to
create a class first, and thus waste time and space. Then if I don't make
the function static, I have to instantiate the class just to use the
function.

This is just my lowly opinion as a beginning C# programmer.
 
Hi mb,

Instead of having global variables disorganized by being "all around", you
could organize your global var's in a more formal class. In C++ etc. , you
will have one BIG chunk of global variables.....here couldn't you have more
organization? It's the same case with methods as well.

In C#, everything is within a class, and everything derives from
System.Object...this arch is nicely added on with that arch as well.


HTH,
- Rakesh Rajan
 
Hi,

1) you can't declare anything outside of a class, enum, etc. Thus you can't
declare globals right after the namespace declaration. I just don't
understand why Microsoft decided to do away with easy to
use/declare/understand global variables. Even C++ can do this. I used to
put globals all in one spot for easy maintaining, this is intuitive. Now
they are spread all over the code, in different classes as "static"
variables, which to access I have to write out the full class and veriable
name.
2) Almost along the same lines, I can't just create a function, I have to
create a class first, and thus waste time and space. Then if I don't make
the function static, I have to instantiate the class just to use the
function.

It is just OO language like JAVA.
What does a "global" mean in object oriented way of thinking?

The Namespaces gives you a better access to class.
How you expect to keep unique "global" variable if single
project can reference 10 or more libraries?

Its very good style to declare unique namespace (for all libraries
in company), and extend it with namespace of module.
This is just my lowly opinion as a beginning C# programmer.

I think that your future experience in C# will change your
way of thinking.

Cheers!

Marcin
 
When I was programming in C (a long time ago), I used to:

organize the code in modules
give every module a special prefix
name my module header file <prefix>pub.h
name every global variable <prefix>_varname
name every function <prefix>_function

just so that the code does not look like a big mess, and so that people can
easily find where a given global or function was defined (there was a bit of
documentation in the <prefix>pub.h), etc.

When I switched to Java (and C# later), I had to make some small
adjustments:

modules became classes
the underscore after the prefix became a dot.

The morale of this is that if you try to organize a big piece of C code
decently, you end up with conventions that get you very close to the Java
and C# notation.

So, you should not be "bugged" by the <classname>. notation, you should feel
good about it, as it will help you organize the mess.

Bruno.
 
If you want this sort of thing it can be had in VB.NET via its "modules"
construct. However, those capabilities are in there for backward
compatibility with VB6 *and* to accomodate casual programmers.

What you are objecting to isn't so much a C# feature as an inherent OOD
characteristic that C# enforces (as do most other OO languages). It's true
that while you're learning how to properly architect the way that classes
are composited and the contracts they have with each other, the lack of this
"easy out" slows you down. But over the long haul, it results in more
stable, safe, flexible designs. VB.NET developers tend to throw all sorts
of stuff into modules because it's easier than figuring out what's
responsible for what and what needs to be passed where.

Being forced to think this stuff through also has long term cross-project
benefits.

Be patient, young Jedi ... in time you will see the wisdom of the masters
;-)

--Bob
 
1) you can't declare anything outside of a class, enum, etc. Thus you
can't
declare globals right after the namespace declaration. I just don't
understand why Microsoft decided to do away with easy to
use/declare/understand global variables. Even C++ can do this. I used to
put globals all in one spot for easy maintaining, this is intuitive. Now
they are spread all over the code, in different classes as "static"
variables, which to access I have to write out the full class and veriable
name.

I understand and relate quite well with you as I used to write a lot of
global messy vars. The more I studied OOP the more I learned that it is a
much cleaner way to program even though I don't always like it. I prefer
what's called "structured" programming with globals etc.. I am used to C++
and Delphi and they allow sloppiness. I have taken up C# because of its
automatic garbage collection and I plan on letting it do plenty of it for
me. I am tired of wild pointers!
2) Almost along the same lines, I can't just create a function, I have to
create a class first, and thus waste time and space. Then if I don't make
the function static, I have to instantiate the class just to use the
function.

The only way that the framework can keep track of everything properly is
through classes. Once you get used to them you will wonder how you ever
were productive any other way.
This is just my lowly opinion as a beginning C# programmer.

If we all had the same opinion then the world would be of one frame of mind

Larry.
 
Back
Top