[Rant] C# is not that great

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
[rant]

I was going to try and do some simple coding in C# to see if I wanted to use it to program.

I attempt to read a txt file in and after googling for about 10 minutes, I find a combination that reads the file in (after having like 10 options to choose from). This isn't so bad I guess. It gives lots of options for buffered reading, etc, etc. Ok, now to see if this is faster with C#.

So I google around to see how to read the next integer from a file... and i google.... and i google..... WHAT THE HELL?! You can't just type someinteger = file.readInteger() or anything like that. Hell, C++ even lets you do file >> someinteger. Isn't this language supposed to be better?! So I'm sitting here and I have the choice to either read every damn line one at a time from the file and sift through that crap to get my integers out or I can read every damn character one at a time. What the hell is the point in this?

Here's how I want this crap to work .NET :

- I want the choice to read in whatever damn data type I want and I want you to take out whitespace and other standard delimiters just like C++, OK?!
- I want to be able to read in these data types WITHOUT specifying exactly how many bytes I want to read in because this is a huge pain in the ass when they're all different types

Jesus christ, you think this kind of crap would be standard on a language that's supposed to kick ass. I hope I'm just being a huge moron and couldn't find it after about 20 minutes of googling. If that is the case, I will gladly proclaim myself a moron and continue coding, but until then .NET can kiss my ass and take its crappy file I/O with it.

:|:|:|

[/END RANT]
-silver
 

replicator

Senior member
Oct 7, 2003
431
0
0
Well, that is one tiny part of .NET, and you can't say it sucks just because you may need to do things differently.

If the file has delimiters, then you can read an entire file and use split to get the values out. You can cast to integer if necessary.

.NET has a very similar I/O to Java. You can pretty much do anything you want if you are willing to put in some time to learn new ways of doing things. A language isn't good or bad because it has some 'x' feature like .readInteger. You can always built a function like that using C# if you need to.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Yeah, you don't need streams to do easy manipulation of text i/o. F.e. in python, I would do:

firstnum = int(some_file.readline().split(None, 1)[0])

It looks like a lot of unneeded complexity, but I can do anything I want with text in python easily. In C++, it can get a bit hairy.
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
I admit, I was pretty ticked last night :p

I'm going to see if I can find a decent C# guide. A large part of my frustration was being unable to find a decent I/O guide. I have MSDN installed but I am not sure how to use it/if it covers this :eek: I'll update tonight if I find a good and efficient way to do this!

p.s. I meant C# can kiss my ass, not .NET :) .NET seems very useful for all those doing web coding and what not. I meant I wanted C# to have simpler i/o, but I'm probably just lacking a guide to do it without doing a whole lot of runaround.

-silver
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: agnitrate
[rant]I attempt to read a txt file in and after googling for about 10 minutes, I find a combination that reads the file in (after having like 10 options to choose from). This isn't so bad I guess. It gives lots of options for buffered reading, etc, etc. Ok, now to see if this is faster with C#.

So I google around to see how to read the next integer from a file... and i google.... and i google..... WHAT THE HELL?! You can't just type someinteger = file.readInteger() or anything like that. Hell, C++ even lets you do file >> someinteger. Isn't this language supposed to be better?! So I'm sitting here and I have the choice to either read every damn line one at a time from the file and sift through that crap to get my integers out or I can read every damn character one at a time. What the hell is the point in this?

No, you can't. If you want to create your own class that overloads the >> operator to offer a similar facility that C++ offers, then you can certainly do so.

Here's how I want this crap to work .NET :

- I want the choice to read in whatever damn data type I want and I want you to take out whitespace and other standard delimiters just like C++, OK?!
- I want to be able to read in these data types WITHOUT specifying exactly how many bytes I want to read in because this is a huge pain in the ass when they're all different types

If you want to use C++, then you can do so using managed C++ which will give you access to all the classes in the .NET BCL. You can work with file I/O in unmanaged C++ and still make use of .NET. See the #managed and #unmanaged pragmas in the C++ docs. There's nothing wrong with continuing to use C++ if you are more comfortable with doing so.

Jesus christ, you think this kind of crap would be standard on a language that's supposed to kick ass. I hope I'm just being a huge moron and couldn't find it after about 20 minutes of googling. If that is the case, I will gladly proclaim myself a moron and continue coding, but until then .NET can kiss my ass and take its crappy file I/O with it.

Have you looked at the plethora of classes in the System.IO namespace? The .NET BCL includes an extensibility point with respect to type conversion utilizing primarily the IFormattable interface. Look this interface up in the documentation and you'll find more than you need to perform the necessary conversions.

I'm going to see if I can find a decent C# guide. A large part of my frustration was being unable to find a decent I/O guide. I have MSDN installed but I am not sure how to use it/if it covers this I'll update tonight if I find a good and efficient way to do this!

Look up any of the IO classes and you'll find references to all the documentation you need. Specifically, look at "Working with File I/O" located here in MSDN.

p.s. I meant C# can kiss my ass, not .NET .NET seems very useful for all those doing web coding and what not. I meant I wanted C# to have simpler i/o, but I'm probably just lacking a guide to do it without doing a whole lot of runaround.

If you say C# can KYA, then you imply .NET can as well :) C# is merely one view of the facilities offered by the .NET CLR and BCL, so if you don't like file I/O in C#, you won't like it in any other .NET language either.

I don't really know what else to offer. I believe you simply need to learn more about I/O and .NET in general, because I can't really refute a rant based on a lack of familiarity. .NET is not some non-orthogonal amalgamation of functions into a monolithic library; rather, it's an extensive framework with extensibility points built into everything. You might not appreciate the slightly increased learning curve on something as ostensibly simple as file I/O, but the extensibility inherent in its implementation is of great value.

C# is really a fantastic language, and your admonition of it should really be towards .NET and OO. I strongly recommend Applied .NET Framework Programming if you want to acclimate yourself with the .NET Framework. Programming C# is a great book for C# and facets of the .NET BCL, including file i/o.

Hope that helps.
 

Chu

Banned
Jan 2, 2001
2,911
0
0
If you are programming in C# using VS, it is pretty much essentially to learn how to use MSDN. Almost all the web tutorials out there are horrible, and MSDN search interface built into VS.NET is amazingly handy.

That being said, all languages have their quirks. I won't embaress myself and tell you how long it took me to figure out how to do multi dementionary arrays in C# since I was convinced I was just doing something stupid and just had to fiddle around with the keywords. I ended up writing about 400 lines of array code using for loops to iterate in child arrays before showing the code to someone and having them ask wtf I was doing.

-Chu