View Single Post
Old 13th December 2013, 08:49 AM   #21
Dessi
Species Traitor
 
Join Date: Jul 2011
Location: Omaha, NE
Posts: 3,615
Disclaimer: I have a bias toward C#, having used it nearly everyday since 2003.

Originally Posted by Squeegee Beckenheim View Post
Firstly, I'd appreciate any advice as to whether starting with C# is a bad idea and whether I should go for something else. The general advice around the internet seems to be that it's not a bad starting language [1], that it's fairly widely used [2], and that as it's object-orientated (and I'm that much of a noob at this kind of thing that I'm not entirely sure what that actually means [3], although I think I have a general sense) it's ideal for coding games [4]. I've thus far coded a tiny program which prints a short phrase in the Windows command module, so it's not like I'm too far down this path to change tacks now.
Let's break this out:

[1] Is C# a good beginners language?

Yes. C# is a great first language, its very easy for beginners to learn and has plenty of features for experts as well.

[2] Is C# widely used?

Yes it is. People use it for creating websites, including one especially popular website, web services, enterprisey business applications, small games, robotics, desktop applications.

C# is the go-to language for any kind of Windows development.

[3] What does object-oriented mean?

Object-oriented programming describes a style of programming which attempts to model "things" by grouping their data, their attributes, and behaviors into a single unit called an "object".

A cat, person, computer, and a roll of duct tape are all "real" things in the tangible sense. When we think about these things, we can broadly describe them in terms of a number of attributes:
  • Properties: a person has a name, a cat has four legs, computers have a price tag, duct tape is sticky.
  • Behaviors: a person reads the newspaper, cats sleep all day, computers crunch numbers, duct tape attaches things to other things.
  • Types/group membership: an employee is a type of person, a cat is a pet, a Dell and Mac are types of computers, duct tape is part of the broader family of adhesives.
Object-oriented programmed was developed around the idea that applications should model entities and simulate their interactions in code. You can absolutely model "real" things in an application like like cats, people, and adhesives, but nothing in principle stops you from representing less concrete things, such as a bank account or a business rule.

Simulating models and interactions of things as "objects" strongly effects the structure and organization of an app. You may want to define a types (any blob of data used in our application), but then derived a new type which is a specialized version of the parent type, forming a type or inheritance hiearchy. For a concrete example, imagine you're writing a Space Invaders-type game:

You might have an object called Sprite which represents the base type used in all of your game; Sprites are drawn on screen, they can move around, can be added or removed from the game at will. You can have a Spaceship type which derives from Sprite, and you can even have more specific XWing and MilleniumFalcon which derive from Spaceship. Likewise, you have your different kinds of enemies each with their own properties and behaviors, CombatPlane, Tanks, FlyingSquid, HypnoToad, etc. After you define all the objects in your game, you might have inheritance tree similar to:

Code:
                                   Sprite
       ------------------------------------------------------------------
      /                    \                  \            \             \
 SpaceShip                 Enemy              Obstacle      Projectile   PowerUp
    /                       |                  |            |             |
   |                        |- CombatPlane     |- Asteroid  |- Bullet     |- ExtraLife
   |- XWing                 |- Tank            |- Fence     |- Laser      |- FasterAmmoReload
   |- MilleniumFalcon       |- FlyingSquid     |- AirBase                 |- FreezeEnemies
                            |- HypnoToad
The idea would be that each more specific type of sprite has its own attributes (its life/damage, position on the board, velocity), behaviors (enemies might have different attack strategies), and type (an XWing is a Sprite, but a Sprite is not always an XWing. XWing is a SpaceShip, while CombatPlane is not a SpaceShip).

In practice, most object-oriented languages follow the "everything is an object" philosophy. In addition to the objects you define, every piece of data in an application is represented by an object. Including numbers, strings/text, the values TRUE/FALSE. Architecture of your application from top to bottom is implemented with objects and specific interactions between objects, often in the form of design patterns and other abstractions (for example, you might create objects for reading/writing from the database, an object which represents a timer or stopwatch, object which represents the setting in a programs config file).

Object-oriented design is one of the dominant programming paradigms used to implement applications. A programming paradigm describes how certain features (like objects and inheritance) shape the style and implementation of your program, and the way you define and manipulate data.

This description is not, in any manner, a comprehensive description of OO, but this should give you a least some context of what people mean when they use the term.

[4] Is C# ideal for writing games?

Probably good for prototyping, writing small games, mobile games, indie games, and so on. Not long ago, I saw a job posting for looking for C# game devs to create simulations and learning aids for medical students, which is pretty cool if you ask me. Many C# developers use Unity for writing games, which I believe is the successor to Microsoft XNA.

In practice, C++ dominates game dev on desktops and consoles, Obj-C dominates iPhone development, recently HTML5+Javascript is making its way on browsers. C# has a large game dev community, but its a tiny share of the market.

C++ will probably dominate the gave dev world for a long time for one major reason: it has a very predictable cost model. Memory allocation and freeing is quite explicit; you can look at any function have a good idea of exactly the machine operations being executed to run that piece of code. C#, on the other hand, is garbage collected, meaning that freeing memory occurs implicitly and non-deterministically. C# periodically halts the execution of an application for a fraction of a second to run the garbage collector, then resumes program execution normally; this has the effect of introducing small freezes and hiccups in your application anywhere and anytime. C#'s cost model is therefore less deterministic and less predictable. This isn't a problem in most applications because the freezes are usually too brief to be perceptible, but its unacceptable in the gaming industry where performance must be predictable and graphics must render constantly, consistently, and in roughly uniform slices of time.

Quote:
But, more importantly, can you recommend any good resources for learning C#?
Head First C# is probably the best beginners book. Lots of examples, lots of sample coding projects which gradually and gently introduce more language features, the book is even funny at times.

You can find PDFs of this book for free on some sites, but these guys worked hard to write and illustrate it, I'd suggest spending the money to buy it.

Quote:
There are a few free online video courses, one of which I've started, but they all seem to be hell-bent on using Visual Studio Express to make the coding easier, whereas I think it's probably a better idea to learn the hard way, as that will give me a better understanding of the underlying principles of the language and, indeed, of coding in general. So do you know of anything that teaches the language the long way round? Or am I wrong to worry about that and should I just go for it with Visual Studio?
You don't need VS to write C# apps, learn to program, etc. But its just a nice tool with lots of killer features: Intellisense to discover classes and methods, really nice debugger, easy to create simple GUIs with drag/drop. There's a reason why VS is the standard tool in virtually every C# dev shop anywhere. I would recommend a newbie programmer using Windows should stick with the standard tools. It'll get you up to speed faster, giving you more time to "look under the hood" later.

If you really insist on learning the principles of programming and algorithm design in the most "pure" way possible, SICP is unbeatable, but may not be easily accessible to a first-time programmer.
__________________
>^.^<

Last edited by Dessi; 13th December 2013 at 10:22 AM.
Dessi is offline   Quote this post in a PM   Nominate this post for this month's language award Copy a direct link to this post Reply With Quote Back to Top