Page 2 of 3

Re: C# Beginner

Posted: 04 May 2010, 15:59
by knorke
last time i checked there wasn't a program for everything on pc ... and most programming is done for pc ...
i would guess it changed over the years. Now there is a program for everything on pc.
There is not as much custom software anymore, everybody uses the "big name" programs from microsoft, adobe etc. (microsoft office, autocad, photoshop, ...)
And if there is custom made software it is mostly to provide an interface for database access. No need for assembler or anything there, just use c# or whatever with a powerfull libary so you do not get hold up by reinventing everything.
For example I set comboBox to already contain some text when program starts, but text was selected. So I wanted to deselect that text and put cursor at the end of it, so user can start typing away, but I failed. I just couldn't figure out what to use.
Something like this should not be part of a beginner programming course, it is too detailed.
Imo one should learn about loops, arrays, bit operations oop etc. and not "how to make text bigger." That big text can be done with "textfield.fontsize=hugeasspinktext" you will forgett anyway but if you have ie understood a sorting algorythm, that will help you much more.

high/low level:
imo not very usefull, like with c you can get quite get hardwarenah "close to the hardware" if you want when using it for chips but on the other hand you can use tons of libarys and thus get "more high level"

Re: C# Beginner

Posted: 04 May 2010, 16:35
by zwzsg
Yes, C/C++ is very versatile and span a great domain in the low/high scale.

To learn programming, I'd say it's important to pick an environnment with little overhead, where you can easily read keyboard and write on screen with just a couple lines, without having to first spend weeks reading a manual and hours finding out how to create a project or link to libraries. And that is often not related to the language itself.

Re: C# Beginner

Posted: 04 May 2010, 16:47
by knorke
without having to first spend weeks reading a manual and hours finding out how to create a project or link to libraries
true, but it can also be instructional to once try compiling "by hand"/command line just for the lols.
so you know what happens when you click "run program"

Re: C# Beginner

Posted: 04 May 2010, 16:57
by zwzsg
When you're a beginner, you have enough to cope with already.

Had to deal with makefiles a couple times, it didn't reveal me great insight about how code is compiled, it didn't teach me anything I wouldn't know, beside makefile confusing and totally arbitrary syntax.

it can also be instructional:
  • to code without garbage collector, so you know mem usage matters
  • to code without strings, so you know how they're handled
  • to code in assembly, so you know your instruction set
  • to manually decode hexdump, so you know what compilation does
  • to write your own OS, so you know how program are loaded
  • to write your own BIOS, so you know how OS are bootstraped
  • to solder your own CPU, so you know how they're wired
  • to draw your own circuits, so you know how they're designed
  • to melt your own gold, copper and silicium, so you know about how material affect heat dissipation and electrical resistance
But if noobs had to do all that before being allowed their first hello world, then we'd have no programmers because they would have all ragequitted.

Re: C# Beginner

Posted: 04 May 2010, 17:02
by ==Troy==
zwzsg wrote:When you're a beginner, you have enough to cope with already.
it can also be instructional:
  • to code without garbage collector, so you know mem usage matters
  • to code without strings, so you know how they're handled
  • to code in assembly, so you know your instruction set
  • to manually decode hexdump, so you know what compilation does
  • to write your own OS, so you know how program are loaded
  • to write your own BIOS, so you know how OS are bootstraped
  • to solder your own CPU, so you know how they're wired
  • to draw your own circuits, so you know how they're designed
  • to melt your own gold, copper and silicium, so you know about how material affect heat dissipation and electrical resistance
But if noobs had to do all that before being allowed their first hello world, then we'd have no programmers because they would have all ragequitted.

I had to do all but the last part in my school/uni. And I wasnt even studying programming.

Re: C# Beginner

Posted: 04 May 2010, 17:16
by knorke
I had to do none of this in school but only fuck around in Excel and the course was called "Informatik" :?

Re: C# Beginner

Posted: 04 May 2010, 22:32
by Jazcash
I always find it a whole lot easier to do anything creative or constructive to have a plan or a knowledge of what I'm trying to achieve. Having a task helps a great deal, especially with programming.

That's why Spring is so useful for a lot of people, it provides as a project, giving targets and goals to programmers and the like.

Re: C# Beginner

Posted: 04 May 2010, 22:59
by Wisse
There are many great posts in this thread :)

Just to clear things up. I'm not switching to C++ right now. I probably will in the future, if I stick with programming.

You can't find app for everything. For example I have to make (till the end of the month :roll: ) program that will read data from PLC via TCP/IP using Modbus protocol. I found nice library and everything, so I just need to put that together (somehow) and make it write into database. To support that I also have to make web application that will draw fancy graphs out of collected data. That should take a pro 1 day to make. I don't think you can find anything that will do exactly that tho. That's just one example showing, that there's some room for C# work in Mechanical engineering.

As I said in previous post I've used C. I know few things about pointers and memory management. I had my console apps crashing many times :D I've used C and assembly for 8-bit uC programming. Today we learned about data bases, last week about ASP.Net, next week... I don't honestly know. That might be my problem tho. We didn't have any courses about that. We learned about that durning "lab" time (since there was nothing else to do because of rather moronic/useless courses).
In short: There's complete mess in my head. I don't know any good programing practices. I was forced to improvise as much as I could. That fell apart now tho. So I came here whining, looking for advice. What I got was confirmation that I have to keep trying and figure out .NET framework. I guess I'll stop nit-picking and try making something suitable to my skill level.

I might be coming back in summer, asking you guys about some nice C/C++ learning assignments , since you know a thing or two more than me -.-

Oh one more thing. Does anyone know any tutorials about good programming practice (or something more general considering C#). Like for example hoijui's advice bout renaming variables. I would rly love to learn about that now, before I pick up some bad habits.

Re: C# Beginner

Posted: 04 May 2010, 23:05
by ==Troy==
Well, this is pretty much what I was talking about. You need to get proper foundation, with a harder language, be that C/C++ or any other unmanaged one.

If not during the study time, do it during the summer as your hobby. It will clear up a lot of mess in your head and will allow you to easily hop onto other languages later on (usually it takes about 2 weeks straight to learn syntax of a new language from A to Z)

Good practises are usually given in books and in examples written in those books. So its best to just go to library and get one.

Learning a library for C# just taking reading through manpages once you are happy with syntax.

Re: C# Beginner

Posted: 05 May 2010, 01:00
by SwiftSpear
Wisse wrote:I'm trying to learn C# lately and I would like some advice on how to approach this, since I find it utterly confusing.

I first started coding this year at uni. Sice I'm mechanical engineer we don't even have lectures on programing, just some brief overview. We started with C, where we had a very good mentor which thought us well for measly 30h course. C was fun, we got 2 page cheat sheet and that was more or less all I needed for my console applications. The biggest thing I did was "battleship algorithm". We each made one and then made them fight. My won btw :P

In February we started with C#. We got different mentor this time, who, honestly, sucked. Considering he only had 16h to teach us, you can imagine how "extensive" my knowledge is.

I'm still confused about stuff like "constructors", "classes", "encapsulation", and so on, but that's up to me to figure out. My biggest problem now is SHITLOADS of methods and members and dunno what you call it... Commands are even more absurd than words in German language. As you know you often get something like this: Xxx.Yyy.Zzz(Jjj.Iii()) which is far beyond me atm.

I wonder:
How does one get to know all of those members in C#?
Where to start?


Today I spent 3h on 15 (!) working lines of code. When I wanted to make something specific and exactly what I envisioned in my head I just got stuck completely. This is not going anywhere. Plz help, any non-troll advice will do :?

Thx
C# is basically java. I don't understand specifically what is causing you problems...

In terms of stuff.otherstuff(thing, otherthing). When we make a class in C#, it works like a mold that objects go into and take that shape, and the class is not used in runtime, only the objects. so "stuff" is the name we've given the object we want to use "otherstuff" is the name of some method in the class definition of our "stuff" object. A method is a little chunk of code that does something using data we put into it, or data it already has access to from the object the method belongs to. Methods either change the state of the object they belong to, or they return some data, usually about that object. the "(thing, otherthing)" are pieces of data we are putting into the method from the outside. Methods can return any type of data, even other object, in fact, for complex programs we use methods to almost ONLY return other objects. so, if the return item for "stuff.otherstuff(thing, otherthing)" is a another object, then you can have things like "stuff.otherstuff(thing, otherthing).doADance(anObjectAsAnInputVariable.theMethod(someOtherInput))". This object is some item that takes 2 input variables and returns an object, and on the object we are having returned, we want it to doADance, but dancing requires information about another object, so we put in a reference to the input variable object method "theMethod" which returns an object.

Objects can store data as well, and the data an object stores can be another object. For example, in a window program, maby we want text boxes to be another object stored within our window object.

for the code "object.item;" if "item" is an int, then "object.item" is the int stored in the object. And we can do things like "object.item + 5 = object.item;". But item doesn't have to be a raw variable, it can be another object.

"window.textbox.entertext("hello");" in the window object, there is an textbox object we have public access to, and we want to run the method of the textbox object called "entertext" and we are inputing a string that says "hello" into entertext, which is the method of the object textbox, which is a public object contained within the object window.

It seems alot of your problem is that you're working with a library of objects someone else made and you're not really sure how they work... That's not really an intricacy of the programming language, you need to look up the library specifications and see what items in that library will do the tasks you want them to. You can code in C# without using any external libraries at all. The whole point of a library is it does abstract stuff for you that would take FOREVER to code up from scratch, and you don't have to solve all the problems the library already solved, you just have to take the time to learn how to use the parts of the library you need. It may be confusing, but it's much much faster than coding it yourself.
I wonder:
How does one get to know all of those members in C#?
Where to start?
Like I say, it's not a "member of C#" it's a library you are working with, and the simple answer is that the first time you use a new library it takes forever to figure out how it works. There's no shortcut. You just have to slog through the documentation and try to understand what it is telling you. It's just like a library with books, the codes on the books sort of help you find the kind of book you want to look at... but to learn the whole library well enough to be able to find a specific quote in a specific book just takes time to learn the way the systems work.

Start by just doing the work slowly. The first time, maby you make a window with some buttons, and it takes you 4 hours just to make the window and buttons... but the next time you do it, most of the problems you solved as to how to make the behaviors and specifications work for you, you're familiar with those books in the library already, you have an idea of how they work, it takes much much less time to find them again and much much less time to get to the parts you want to read. Just add new items to your vocabulary from that library as you need them. If you are going in with the goal of learning the library well, if you know there is a different way of doing something from the way you already know, go out of your way to dig through the library and try to find it. If it's more a case of wanting to just get done stuff fast, once you master something, when you come across a problem where you can use the information you already know to solve it, don't get fancy, just use that information.

Re: C# Beginner

Posted: 05 May 2010, 01:14
by SwiftSpear
you don't need C++ to learn C# if you only know C. People have been learning java from a basis of all kinds of sequential languages for years. It's the same basic process, just occasionally you find syntax that makes sense right away.

Honestly, I think maby it's more useful to learn C# first, because it FORCES you to program in OOP. where as C++ distracts you from the guts of OOP with all the memory management stuff. You can forget that stuff completely programming in C#.

Re: C# Beginner

Posted: 05 May 2010, 02:29
by Licho
It's good you have C# courses now lol .. we had stuff like Haskell and Prolog instead :)

And yes its best if you have purpose - just try to do something small first - it gives you reward. My first C# program after reading ECMA language specs and C++->C# introduction was Springie and while it certainly isn't optimal C# code its still in use now :)

Re: C# Beginner

Posted: 05 May 2010, 06:07
by Pxtl
I assume you're working in Visual Studio

While MS's documentation sucks from the mile-high distance, it's excellent up-close. You can hit ctrl-space when on any object and get a listing of it's members and can walk through them and see tooltips explaining usage and whatnot.

Now, C# is pretty much a "standard" OOP language these days - really if you have a hard time with C# you'll have a hard time with _any_ modern, corporate-popular language (Java, Ruby, Python, etc). C# is a little bigger because of more corporate backing, but that's all.

Now, quite obviously, C# is HUUUUUUGe. MS keeps adding more and more crap to it, and they never get it right the first time and never actually fix those bugs (since fixing bugs means breaking code that relies on the bugs) so basically coding in C# means reading endless reams of documentation and forum posts to find out how to use a library that does 99% of what you want but fails catastrophically at the last 1%. Instead of fixing shiat, MS will provide a complete replacement library that is even more complicated and still buggy.

That said, as languages go it's pretty good. C# 3.5 added a farktonne of features that make it incredibly terse despite being a statically-typed language. This is rare, and awesome... of course, they have to fark it up with crappy libs.

Now, as for learning to use C#'s classes, the problem you'll encounter is that different classes are designed with completely different paradigms. Some of them are meant to be used in a static manner, which basically makes the class-name into a miscellaneous container of methods - that'll be very familiar to a C coder. A lot of OS-binding stuff works like this - such as the "System.IO.Path" namespace.

Some of them are designed in an OOP fashion, where you'll be construction objects and setting properties and calling methods on various other objects. Most of the little simple things like files and strings and whatnot are good here.

And some of them are designed in a crazy introspection-based manner, where methods ignore all that nicely constructed stuff with interfaces and crap and just tear the object apart and examine its guts to do something really complicated with it, using "Attributes" that are provided by the user on his custom classes as pointers. The XmlSerializer system is a good example of this. Databinding is another. These libs are notorious for being ostensibly fantastic time-savers, but end up eating more debugging time than the rest of the language put together. ASP.Net is the mother of all clusterfarks of this approach.

The best approach is to try to learn one thing at a time. Start with just doing command line stuff and getting acquainted with the main classes.

One thing that people forget about C#: MS doesn't actually like OOP. I mean, OOP is a good organizational tool, but earlier C# libs were generally designed with the idea that the user would mostly be writing in a purely procedural style and letting MS handle all the ugly object-oriented stuff. Now, you _could_ write classes with complicated inheritance relationships and interfaces and whatnot, but in general MS libs seemed to work better if you just used DataTables for everything.

Now in 3.5 they've moved away from this approach, but in the earlier code it's very visible.

So don't sweat the issues of coding your own classes - the business of interfaces and visibility and encapsulation wasn't an MS priority in platform design. They seemed to include it simply because they were aping Java for fashion reasons. I mean, you should learn it, but learning how to _use_ classes and objects and whatnot is far more important.

Re: C# Beginner

Posted: 05 May 2010, 12:43
by Licho
Bugs in .NET libraries? I have never encountered one. Well I reported 2 mono bugs, but in .NET it all works as specified.

Re: C# Beginner

Posted: 05 May 2010, 13:17
by Pxtl
Licho wrote:Bugs in .NET libraries? I have never encountered one. Well I reported 2 mono bugs, but in .NET it all works as specified.
Less "bugs" than "behaves in a counterintuitive manner when using it outside of the 100% expected approach". For example, in ASP.Net there are a host of javascript-driven controls that fall down when you put them inside an update-panel. This failure is documented, but it's still a PITA. Lots of libs have seriously useless exception reporting (like the over-use of OperationException or a universal failure to tell the user what values were causing a problem), but they never can fix it because existing code may be counting on the previous exception messages. And, in terms of outright bugs, the asp.net 3.5 ListView has a bug where you can't use databinding on the InsertTemplate if you have a DropDownList inside it - this little problem means having to keep distinct Insert and Update templates. Plus, all the old 1.1 and 2.0 libraries are never updated to make use of the newer language constructs available, so you have ADO.Net and XMLSerializer's piss-poor handling of Nullables, and a total lack of generic support in ASP.Net.

Re: C# Beginner

Posted: 05 May 2010, 16:23
by Teutooni
Ï've never tried C#, but I heard it's like 10 times slower than C++ and less productive than python. Any good reasons one should learn C#? Windows-only GUI stuff is not a good one, Qt does that and more.

Re: C# Beginner

Posted: 05 May 2010, 17:17
by Licho
You heard wrong :)
There is no reason why C# should be significantly slower than C++ - it compiles to native code anyway and is distributed in CPU neutral way - so its always optimized for CPU it runs at.
There is some overhead but some things are faster than C++ (like memory allocations).
Generally for modern applications you wont notice any speed difference. You get most gains/slowdowns from design changes, and in C# its easy to code advanced design in easily to read and maintain form. And for expensive stuff framework uses native OS libraries calls anyway.

You can use any windows framework you want with C#/.NET. I personally used Windows.Forms, WPF, GTK.
Of course native windows stuff (windows.forms or WPF) gives you biggest performance on windows systems.

As for productivity - I have never coded in anything as productive as C# for large scale applications. Untyped languages like Python imo can't compete for larger projects. Also wealth of .NET libraries and internet resources is gigantic.
If you want to code something simple it's probably better to go Python - but for larger things, no way.

Also C# is just one of .NET languages, in fact you can switch to any other and you still keep same runtime/framework there are even tools that auto convert them from one language to another - you can code in functional F#, VB, managed C++, IronPython, IronRuby, Pascal etc..
For example PlanetWars project had parts coded in F# which looks nothing like C#.

Re: C# Beginner

Posted: 05 May 2010, 17:38
by ==Troy==
Licho wrote:You heard wrong :)
There is no reason why C# should be significantly slower than C++ - it compiles to native code anyway and is distributed in CPU neutral way - so its always optimized for CPU it runs at.
There is some overhead but some things are faster than C++ (like memory allocations).
Generally for modern applications you wont notice any speed difference. You get most gains/slowdowns from design changes, and in C# its easy to code advanced design in easily to read and maintain form. And for expensive stuff framework uses native OS libraries calls anyway.

I think you are dead wrong here.

The same way Assembler is specialised to be "machine code" you effectively get a lot less processing power used up for redundant checks where you do not need them.

I used to do some parts of my code in direct assembler simply because the libraries were nearlly 3 times slower than my code (granted mine was less stable for other applications which the lib was intended).

Saying that C# can be faster than C++ is like telling that a bicycle can be faster than a motorbike simply because the driver forgot to buy petrol. You are running in a runtime, immediately you lose out processing cycles on checks for memory allocations, automatic garbadge collector, having to have the runtime loaded into the memory, and all other numerous issues.

Its not always optimised to the CPU it runs it, it depends on the library that you are using.

Readability wise C# and C++ are very similar IMO.

Python is a standard language in scientific world, C# / Java are standard for businesses.


From the code I wrote for both C# and C++ (they arent that different) C# was in general about 5-10% slower, and that was with specifically optimised libs that I was told will work faster.


Simple search in google leads to some interesting forum discussions as well.


Here the guy got C# to be about 2X slower on exactly the same algo :
http://forums.hexus.net/software-web-de ... -vs-c.html

Re: C# Beginner

Posted: 05 May 2010, 17:57
by Satirik
Licho wrote:There is no reason why C# should be significantly slower than C++
==Troy== wrote:Saying that C# can be faster than C++
troy ... everything you say is boring and we all know c# is slower than c++ which is slower than c/assembler ...

Re: C# Beginner

Posted: 05 May 2010, 19:26
by ==Troy==
Satirik wrote:
Licho wrote:There is no reason why C# should be significantly slower than C++
==Troy== wrote:Saying that C# can be faster than C++
troy ... everything you say is boring and we all know c# is slower than c++ which is faster than c/assembler ...

Problem is that the slowness of C# is very downplayed in Lichos post, hence I allowed myself to simply go into the opposite direction.

Although I am glad I have not heard anyone yet promote VB here.


Edit : And btw, 2X slower isnt just "not significantly" its "tremendously" slower.