473,839 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I've Had Enough

I've had enough of C#. I've had enough of using parentheses for every
'if' statement. I've had enough of having to mix assignment of return
value of methods with flow control, making writing code that's both
readable and consistent, impossible.

C# is hindered by its predecessors and the Microsoft marketing
department. If Anders had his way, this language would be a one where
readable code isn't a near impossibility for non-trivial code; but no,
Microsoft marketing and C++/Java got in his way. The evidence is
blatently apparent in the language.

Microsoft, the company where money comes before technology, has struck
again. The repercussions affect us all.
Nov 16 '05
123 4014
Jon Skeet [C# MVP] wrote:
[...]
Actually, I find that less readable than the straight returns, myself.
With returns in the middle of the method, I know that that's the end of
the useful path of that method. [...]


Out of interest, then, which of the top two code snippets would you go
for, only taking into account the code around the 'return' statements?

Here're the top two again:

FontTagElement GetFontTagEleme nt()
{
//...

if (length == SingleElementPa rtCount) {
if (arr[FirstIndex] == FontNameSpecifi er) {
string name = arr[FirstIndex];
return new FontTagElement( name);
} else {
int size = TryStringToInt( arr[FirstIndex]);
return new FontTagElement( size);
}
} else if (length == DualElementPart Count) {
string name = arr[FirstIndex];
int size = TryStringToInt( arr[SecondIndex]);

return new FontTagElement( name, size);
} else {
return null;
}
}

FontTagElement GetFontTagEleme nt()
{
//...

if (length == SingleElementPa rtCount) {
if (arr[FirstIndex] == FontNameSpecifi er) {
string name = arr[FirstIndex];
return new FontTagElement( name);
}
int size = TryStringToInt( arr[FirstIndex]);
return new FontTagElement( size);
}
if (length == DualElementPart Count) {
string name = arr[FirstIndex];
int size = TryStringToInt( arr[SecondIndex]);

return new FontTagElement( name, size);
}
return null;
}
Nov 16 '05 #61
C# Learner wrote:
For clarification, the difference with Delphi's returning mechanism is
that there's no need to declare the result variable, and no need to use
'return result;'.


So how then do you exit "early" from a function, if you have checked
input arguments and decided you already know the result without further
processing? Is your only choice to wrap the entire rest of the function
body inside an else block? If so, the code gets very unreadable very
quickly, especially if there multiple possible early exit points from
the function.
Nov 16 '05 #62
Kevin P. Fleming wrote:
C# Learner wrote:
For clarification, the difference with Delphi's returning mechanism is
that there's no need to declare the result variable, and no need to
use 'return result;'.


So how then do you exit "early" from a function, if you have checked
input arguments and decided you already know the result without further
processing? Is your only choice to wrap the entire rest of the function
body inside an else block? If so, the code gets very unreadable very
quickly, especially if there multiple possible early exit points from
the function.


One can exit early if one so chooses, using 'Exit'.

i.e.:

function Foo: Boolean;
begin
Result := True;
if FooBar then
Exit;
//...
end;

Personally, I don't like exiting before the end ever. If the routine is
so complicated that you need to return before the end to avoid a code
mess, I think it needs refactoring. Perhaps my opinion on this is
somewhat biased, though, due to this being a style I've practised for a
long time.
Nov 16 '05 #63

"Julie" <ju***@nospam.c om> wrote in message
news:40******** *******@nospam. com...
C# Learner wrote:

Julie wrote:
> I'll take the language any day. It is their sucky, buggy, deficient
> IDE that
> gets my goat, day after day.
>
> So far, their IDE can handle "hello world" class projects, but not much
> more...
The IDE seems pretty solid to me; but I guess it could be a case of
different machines, different setups, etc.

How about a deal: you take the language and I take the IDE ;-P


Consider yourself lucky. Any commercial-scope project is way outside the
bounds of the IDE.

I'm currently working on one solution composed of maybe 30-40 projects of
C#,
managed C++, and native C++, with multiple forms, controls, etc.

It is a battle to get through a day w/o numerous restarts due to the piece
getting hung up on itself. As we speak, the compiler can't build a
project
because somewhere else the IDE has a file open (in this case, a debugging
pdb
file). Closing all files, and even the project/solution doesn't solve the
problem, the only solution is to restart and rebuild.

Try closing the IDE and deleting the .suo file. This sounds like a known bug
that has been cropping up for quite some time(I seem to recall filing a bug
report myself), there is hope it will be fixed in whidbey, but I don't know
if there was any official word on that and considering how hard it is to
reproduce I couldn't test. Though I havn't run into it in about a year it
does happen and it will drive you nuts. It seems to crop up most commonly
with large C# or C++ projects and *may* be related to the size of an output
assembly. I imagine someone else here knows waht I'm talking about and
remembers more details that I do.
A *major* piece of crap, but what should I expect, MS is run by a bunch of
snot-nosed adolescents that think they know everything.

Not to sound harsh, but you pretty much sound like a know-it-all in all of
your posts. Considering the content of said posts I'd say you have a long
way to go before that attitude is anywhere near correct.
Nov 16 '05 #64
C# Learner <cs****@learner .here> wrote:
Jon Skeet [C# MVP] wrote:
[...]
Actually, I find that less readable than the straight returns, myself.
With returns in the middle of the method, I know that that's the end of
the useful path of that method. [...]


Out of interest, then, which of the top two code snippets would you go
for, only taking into account the code around the 'return' statements?


I think I'd use the first one, with the else clause. However, I'd
recode the first part to:

if (length==Single ElementPartCoun t)
{
string name = arr[FirstIndex];
if (name==FontName Specifier)
{
return new FontTagElement( name);
}
else
{
int size = TryStringToInt( name);
return new FontTagElement( size);
}
}

etc

In fact, I'd probably end up declaring name right at the top, as it's
such a common expression in your code.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #65
C# Learner wrote:
Personally, I don't like exiting before the end ever. If the routine is
so complicated that you need to return before the end to avoid a code
mess, I think it needs refactoring. Perhaps my opinion on this is
somewhat biased, though, due to this being a style I've practised for a
long time.


Everyone has their own opinions, but think of a simple situation: you're
writing some sort of text parser, and you need a function to take a
token parsed from the file and turn it into an integer value for use
elsewhere in the program. There are many different tokens, of varying
lengths, but they are all known at compile time.

int ParseToken(stri ng token)
{
if (token.Length == 0)
return 0;

switch (token)
{
case "A":
return 1;
case "B":
return 2;
default:
break;
}

if (token.Length < 2)
return 0;

switch (token)
{
case "M1":
return 23;
case "M2":
return 25;
default:
break;
}

etc.
}

Without early returns, this code becomes extremely difficult to read due
to many levels of indentation and extra blocks. Breaking it up into
multiple functions to avoid that would be silly, as it's so simple.
Avoiding the early returns as a matter of "style" causes the code to be
less efficient, as it will continue trying to compare the token against
strings it could never match (granted the compiler may be smart enough
to help out here, or it may not).
Nov 16 '05 #66
Max Power wrote:
C# Learner <cs****@learner .here> wrote in news:#g9rpoAHEH A.2576
@TK2MSFTNGP11.p hx.gbl:

I've had enough of C#. I've had enough of using parentheses for every
'if' statement. I've had enough of having to mix assignment of return
value of methods with flow control, making writing code that's both
readable and consistent, impossible.

C# is hindered by its predecessors and the Microsoft marketing
department. If Anders had his way, this language would be a one where
readable code isn't a near impossibility for non-trivial code; but no,
Microsoft marketing and C++/Java got in his way. The evidence is
blatently apparent in the language.

Microsoft, the company where money comes before technology, has struck
again. The repercussions affect us all.


Actually, C#/C++/Java were developed by nerds. The real problem is nerds,
not MS. ;-)


"Very nice" *NERDS* definitions :)

http://www.urbandictionary.com/define.php?term=nerd&f=1
http://www.hyperdictionary.com/search.aspx?define=nerd
http://www.computeruser.com/resource...ml?lookup=2995

Marcin
Nov 16 '05 #67
Kevin P. Fleming wrote:
[...]

Without early returns, this code becomes extremely difficult to read due
to many levels of indentation and extra blocks. Breaking it up into
multiple functions to avoid that would be silly, as it's so simple.


To be honest, I find the following slight modification which doesn't
return early, much easier to read:

int ParseToken(stri ng token)
{
int result = 0;

if (token.Length > 0)
{
if (token.Length == 1)
{
switch (token)
{
case "A":
result = 1;
case "B":
result = 2;
default:
break;
}
}
else
{
switch (token)
{
case "M1":
result = 23;
case "M2":
result = 25;
default:
break;
}
}
}

etc.

return result;
}

Again, this may just be due to what *I* am used to doing.

<snip>

Regards
Nov 16 '05 #68
Jon Skeet [C# MVP] wrote:
C# Learner <cs****@learner .here> wrote:
Out of interest, then, which of the top two code snippets would you go
for, only taking into account the code around the 'return' statements?
I think I'd use the first one, with the else clause.


Okay.
However, I'd recode the first part to:

if (length==Single ElementPartCoun t)
{
string name = arr[FirstIndex];
if (name==FontName Specifier)
{
return new FontTagElement( name);
}
else
{
int size = TryStringToInt( name);
return new FontTagElement( size);
}
}

etc

In fact, I'd probably end up declaring name right at the top, as it's
such a common expression in your code.


Oops, yes! Looking back on it, I can't've been fully awake when I wrote
that method :-)

Regards,
Tom
Nov 16 '05 #69
C# Learner <cs****@learner .here> wrote:

<snip>
So one can choose either readability or consistency, but not both.
I don't believe that's true.
Here's the above slightly changed to show a more Delphi-like returning
construct:

FontTagElement GetFontTagEleme nt()
{
//...

if (length == SingleElementPa rtCount) {
if (arr[FirstIndex] == FontNameSpecifi er) {
string name = arr[FirstIndex];
result = new FontTagElement( name);
} else {
int size = TryStringToInt( arr[FirstIndex]);
result = new FontTagElement( size);
}
} else if (length == DualElementPart Count) {
string name = arr[FirstIndex];
int size = TryStringToInt( arr[SecondIndex]);

result = new FontTagElement( name, size);
} else {
result = null;
}
}

Voilŕ -- no loss of readability and no inconsistency!


Actually, I find that less readable than the straight returns, myself.
With returns in the middle of the method, I know that that's the end of
the useful path of that method. However, you can easily make C# behave
like Delphi in that respect, to a large extent. Just declare:

FontTagElement result;
at the top of the method

and

return result;

at the end.

Personally the first thing I'd ditch from the above is the K&R
bracing...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #70

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

Similar topics

23
264
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code that's both readable and consistent, impossible. C# is hindered by its predecessors and the Microsoft marketing department. If Anders had his way, this language would be a one where readable code isn't a near impossibility for non-trivial...
101
4010
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code that's both readable and consistent, impossible. C# is hindered by its predecessors and the Microsoft marketing department. If Anders had his way, this language would be a one where readable code isn't a near impossibility for non-trivial...
26
1125
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code that's both readable and consistent, impossible. C# is hindered by its predecessors and the Microsoft marketing department. If Anders had his way, this language would be a one where readable code isn't a near impossibility for non-trivial...
98
2428
by: C# Learner | last post by:
I've had enough of C#. I've had enough of using parentheses for every 'if' statement. I've had enough of having to mix assignment of return value of methods with flow control, making writing code that's both readable and consistent, impossible. C# is hindered by its predecessors and the Microsoft marketing department. If Anders had his way, this language would be a one where readable code isn't a near impossibility for non-trivial...
0
9854
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9696
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10290
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9425
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7015
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5681
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4482
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3131
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.