473,406 Members | 2,356 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,406 software developers and data experts.

Two things that bug me about C#

mb
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.
Nov 16 '05 #1
8 1285
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

"mb" <mm@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 16 '05 #2
Hello mb,

Both points are advantages...
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 16 '05 #3
Hi,

<snip>
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
Nov 16 '05 #4
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.
Nov 16 '05 #5
Perhaps it is time to look for the advantages of OO programming... the
things you liked have been replaced with some very powerful things.

http://biztalkbum.blogspot.com/2004/...-oriented.html

--- Nick

"mb" <mm@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 16 '05 #6
On Sat, 25 Sep 2004 10:33:06 -0600, mb wrote:
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.
Nov 16 '05 #7
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

"mb" <mm@hotmail.com> wrote in message
news:Ou**************@TK2MSFTNGP09.phx.gbl...
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.

Nov 16 '05 #8
> 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.
Nov 16 '05 #9

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

Similar topics

12
by: Ryan Paul | last post by:
I've spent a lot of time using python, and personally, I feel like it is vastly superior when compared to languages like java, and c++, but there are still a few things that detract from its...
11
by: bearophile | last post by:
Hello, here are a four more questions (or suggestions) for the language (probably people have already discussed some of/all such things: I've seen the contracts for Python:...
13
by: Heather Stovold | last post by:
Wow - deciding to program in python sure requires a lot of decisions! So far: I've decided on python for the programming language. I've decided on wxpython for the GUI.... I've decided on...
2
by: john | last post by:
Hello developers, I am examining trends in developer satisfaction with Microsoft. Without starting a flame war, I would really appreciate it if you respond with the top 3 things that, as a...
111
by: JKop | last post by:
Okay here we go, I feel it's about time people conversed about the bullshit aspects of C++ (including the bullshit stuff brought forward from C). I'll begin with a few of my own grievances: 1)...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
14
by: CMM | last post by:
Do the developers of Visual 2005 actuall use it??? There's lots of great things in VS2005 (mostly related to the outstanding work done on the CLR)... but in general the LITTLE THINGS totally drag...
75
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has...
12
by: Michael Bell | last post by:
I am trying to put my learning effort into the most useful things. What do pointers do that other things can't? Michael Bell --
3
by: Danigan | last post by:
I've noticed a disturbing trend in this (or more accurately "every") tech forum to not answer people's tech questions when people are asking about something non-conformant. This is especially true in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.