Author Topic: Programming habits, standards, and learning.  (Read 32492 times)

Omnomnom

  • Rogueliker
  • ***
  • Posts: 79
  • Karma: +0/-0
    • View Profile
    • Email
Re: Programming habits, standards, and learning.
« Reply #15 on: October 20, 2012, 01:09:52 AM »
I started using VB6, then I switched to C++ because people were calling VB6 names, now I've switched entirely to C#.

Language doesn't matter. Improving programming involves things that apply to all languages. That said, don't use VB6 as it doesn't have some useful OO features and being an old language the documentation, examples and tutorials online are sparse.

The easiest switch you can make, if you really want to leave VB.Net, is to C# as the two are very tightly linked. You'll have to learn new syntax, curly brackets are probably the biggest difference, but that's about it. There are sites with chart comparisons between VB.Net and C# syntax:http://www.harding.edu/fmccown/vbnet_csharp_comparison.html.

Java is similar to C# so getting used to C# should help any adoption of Java.

I wouldn't bother learning C++ unless you are interested in understanding low level memory management and pointers. It's useful to know, but that could be said about a lot of things. A few things I would really recommend are:

1a) Read other people's code that is well known for being written well for inspiration. Don't bother to understand how the actual program works, that takes ages, just read the code to see how they've structured and modularized the source code. Just seeing how things had been broken down into functions and split into different files.

1b) Once you realize how to structure code neatly one big trap is to spend too long doing that and to become unproductive. Strike a balance between spending ages doing things perfectly and being productive. Better to write things untidy and refactor later.

2) Learn OO concepts like inheritance and polymorphism. They aren't necessary, but they can help modularization a lot.

3) Improve at tracking down bugs and fixing them. Aside from using tools like the debugger to help, this really involves grinding on ever occurring bugs to increase XP. Bugs will always happen so getting a routine to hunt their source can be a real time saver. As a bonus 1a) should often help to reduce bugs or make them easier to track down.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: Programming habits, standards, and learning.
« Reply #16 on: October 22, 2012, 06:28:29 AM »
C++, however, is a mess. It forces you to do things that you HAVE to do anyway, allowing you to do them poorly if you don't understand the complexities of the SYNTAX. Only when you do them perfectly does performance begin to exceed Java or C#. C++ leverages mundane syntactical requirements on the user with built-in pot-holes, which ultimately makes you less productive. Your programs may technically run faster in C++ (unless it's a program that runs for more than a few minutes- then Java will be faster due to run-time optimizations and caching), but the difference is genuinely arbitrary. If you really want the explicit advantages of C++, check out HaXe- it compiles to C++ with very competitive performance. C++ also offers poor auto-completion and error-checking support. Potentially resulting in a lot of wasted time.

That's what I meant. C++ is a mess. And you will not learn how to sort out this mess in a month or two (unlike Java or C#), no matter how good in the other language you are.
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Programming habits, standards, and learning.
« Reply #17 on: October 22, 2012, 08:07:28 AM »
C++ is a mess.

When I learned to program I haven't had problems with the language itself. I don't feel like C++ is making any mess out of my source code.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: Programming habits, standards, and learning.
« Reply #18 on: October 22, 2012, 12:45:28 PM »
When I learned to program I haven't had problems with the language itself. I don't feel like C++ is making any mess out of my source code.

I think you just don't remember the problems. It's easy to forget. If we look back, we tend to see only the good things :).

C++ is a mess. You declare a variable of a certain type and you have no idea how many bytes it has, because it's platform dependent. You would like your programs to support Unicode, but on every platform wide characters are stored differently and the new standard, which was intended to unify that, just introduces a bunch of new data types and string literals to even increase the confusion. Each and every external library you need to use has its own string implementation, so you end up with 5 different string types plus C-style zero-terminated character arrays (that themselves are a disaster). A major part of the standard C++ library is actually the C library - old and largely deprecated. It is partially replaced by STL, which is difficult to use and produces unreadable error messages. Sometimes your program would crash in some random place with a cryptic message like "Access violation at 0x27a834c reading from 0xfdfdfdfd" and you spend two weeks trying to figure out what happens. And I named just a few popular issues.

Nevertheless, I still think that C++ is the best language in the world and I'm going to laugh at Java folks ;).
Fame (Untitled) - my game. Everything is a roguelike.

XLambda

  • Rogueliker
  • ***
  • Posts: 208
  • Karma: +0/-0
    • MSN Messenger - tau_iota@live.de
    • View Profile
    • The Weird Rogue
Re: Programming habits, standards, and learning.
« Reply #19 on: October 22, 2012, 02:20:31 PM »
When I learned to program I haven't had problems with the language itself. I don't feel like C++ is making any mess out of my source code.

I think you just don't remember the problems. It's easy to forget. If we look back, we tend to see only the good things :).

C++ is a mess. You declare a variable of a certain type and you have no idea how many bytes it has, because it's platform dependent. You would like your programs to support Unicode, but on every platform wide characters are stored differently and the new standard, which was intended to unify that, just introduces a bunch of new data types and string literals to even increase the confusion. Each and every external library you need to use has its own string implementation, so you end up with 5 different string types plus C-style zero-terminated character arrays (that themselves are a disaster). A major part of the standard C++ library is actually the C library - old and largely deprecated. It is partially replaced by STL, which is difficult to use and produces unreadable error messages. Sometimes your program would crash in some random place with a cryptic message like "Access violation at 0x27a834c reading from 0xfdfdfdfd" and you spend two weeks trying to figure out what happens. And I named just a few popular issues.

Nevertheless, I still think that C++ is the best language in the world and I'm going to laugh at Java folks ;).

Hey, it's not like I don't laugh at C++ folks, so feel free to laugh at us.

It's definitely a powerful language, but at some point you ask yourself whether you could do the same faster with a different language. What you describe is exactly why I stopped using C++ for my projects. I get much more done that way. It's not like I'm some crazy language fanatic - at heart I'm an engineer, and I use whatever works.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Programming habits, standards, and learning.
« Reply #20 on: October 22, 2012, 06:03:12 PM »
You declare a variable of a certain type and you have no idea how many bytes it has, because it's platform dependent.

Why do you need to know how many bytes a type has? Besides if there are platforms that have "non-standard" sizes for types like int it's really their problem.

Quote
You would like your programs to support Unicode, but on every platform wide characters are stored differently

Might be more a problem in unicode than C++. Does unicode work in other languages without similar problems?

Quote
Each and every external library you need to use has its own string implementation, so you end up with 5 different string types

Use less external libraries and more STL.

Quote
Sometimes your program would crash in some random place with a cryptic message like "Access violation at 0x27a834c reading from 0xfdfdfdfd" and you spend two weeks trying to figure out what happens.

When you learn to control C++ better bugs like this happens rarely. One of the key feature to take control of are mysterious pointers. The important lesson with pointers is a strict control of them. If you don't know where a pointer (a handle to an instance in C++) is and what is the state of it, how can you stop bugs?
« Last Edit: October 22, 2012, 06:05:01 PM by Krice »

Paul Jeffries

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 257
  • Karma: +1/-0
    • View Profile
    • Vitruality.com
Re: Programming habits, standards, and learning.
« Reply #21 on: October 22, 2012, 11:22:54 PM »
I think VB.NET gets a bad rap among people who've never actually used it.  It has inherited the idea from Basic that it's a 'beginners language' but I don't think that's really true - you need to have a fairly deep understanding of OOP in order to use it effectively.  I've taught it to people in the past and there are a fair few theoretical hurdles you have to help them across - it's certainly less 'pick up and play' than the older versions of VB.

I think it only has two really meaningful drawbacks:

1. Garbage collection.  Although unless you're super-concerned about performance that probably counts as a plus.
2. It's not terribly cross-platform, what with being based on an MS-owned framework and all.

That said, if you feel you must learn a new language I recommend C++.  I moved to that from VB and didn't find it all that difficult to pick up the basics, although of course it's very difficult to fully master.  More importantly, I found that learning C++ actually made me a much better VB.NET programmer, because it exposes you to a lot of the stuff that VB.NET hides away behind the scenes.  It helped me to make sense of some of the stuff in .NET that always struck me as a bit bizarre beforehand because I could finally see where they were coming from.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: Programming habits, standards, and learning.
« Reply #22 on: October 23, 2012, 12:15:25 PM »
Why do you need to know how many bytes a type has? Besides if there are platforms that have "non-standard" sizes for types like int it's really their problem.

For example, you may wish to know if your value will fit in the variable. And no, it's not "their" problem, it's your problem as a developer because you want to support as many platforms as possible.

Quote
Might be more a problem in unicode than C++. Does unicode work in other languages without similar problems?

I don't know. Java does have some Unicode issues, but that's nothing compared to Unicode issues in C++. I haven't seen other language that uses prefixes for string literals. It's like someone required from you to wear one kind of boots for a sidewalk and different ones for a road, so that you always need to have two pairs with you and switch between them when needed ;).

Quote
Use less external libraries and more STL.

As far as I know, STL does not load fonts, draw bitmaps or play sounds. For everything else (almost) I do use STL.

Quote
When you learn to control C++ better bugs like this happens rarely. One of the key feature to take control of are mysterious pointers. The important lesson with pointers is a strict control of them. If you don't know where a pointer (a handle to an instance in C++) is and what is the state of it, how can you stop bugs?

It could be shortened to "If you don't want bugs, just don't make mistakes". Yeah, that's so simple! I wonder why I didn't invent this smart technique first.

I think VB.NET gets a bad rap among people who've never actually used it.  It has inherited the idea from Basic that it's a 'beginners language' but I don't think that's really true - you need to have a fairly deep understanding of OOP in order to use it effectively.  I've taught it to people in the past and there are a fair few theoretical hurdles you have to help them across - it's certainly less 'pick up and play' than the older versions of VB.

It's essentially a different language. I don't know what they have in common, maybe the fact that you still use the keyword "Dim" to declare variables. You can't even port an old VB code to VB.NET because it's not backwards compatible. That's one of the reasons why I moved from VB to C++. Even Microsoft can't just shut C++ down like they did with VB :).
« Last Edit: October 23, 2012, 12:22:31 PM by UglyTroll »
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Programming habits, standards, and learning.
« Reply #23 on: October 23, 2012, 12:50:33 PM »
For example, you may wish to know if your value will fit in the variable.

I'm using mostly int for all number type variables, and float or double. int holds pretty big number, I haven't found a need for bigger than that. Using only int makes things easier, because it's the "universal" type for most library functions etc. I think using unsigned versions makes things just confusing even if the variable itself never has negative values.

Quote
It could be shortened to "If you don't want bugs, just don't make mistakes". Yeah, that's so simple! I wonder why I didn't invent this smart technique first.

You might be stupid-ish. But seriously, you can learn to prevent bugs that are caused by the usual reasons: careless use of pointers, memory management, out-of-bounds. Those are typical and in certain conditions very easy to do. The reason why people don't take precautions is that they strongly think they are good programmers who don't produce buggy code. They are quite arrogant I would say.

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: Programming habits, standards, and learning.
« Reply #24 on: October 23, 2012, 01:28:56 PM »
I'm using mostly int for all number type variables, and float or double. int holds pretty big number, I haven't found a need for bigger than that. Using only int makes things easier, because it's the "universal" type for most library functions etc. I think using unsigned versions makes things just confusing even if the variable itself never has negative values.

You're damn right - as long as you don't have to use third party code. They would infect your program with thousands of typedefs and #defines. Nothing like that would happen in Java or C#, because they use only few standardized integral types. You can live with that, of course, but that's still messy.

Quote
You might be stupid-ish. But seriously, you can learn to prevent bugs that are caused by the usual reasons: careless use of pointers, memory management, out-of-bounds.

Yes, you can learn it. And it will take you 8 years or so.
Fame (Untitled) - my game. Everything is a roguelike.

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: Programming habits, standards, and learning.
« Reply #25 on: October 23, 2012, 03:58:58 PM »
You're damn right - as long as you don't have to use third party code. They would infect your program with thousands of typedefs and #defines.

It's not C++'s fault that some poorly written code is using typedefs or #define (both outdated C methods).

Quote
And it will take you 8 years or so.

All it takes is a change of attitude. There is always hope for that since C++ doesn't forgive stupidity. If you do stupid things in C++ it's you who suffer.

requerent

  • Rogueliker
  • ***
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Programming habits, standards, and learning.
« Reply #26 on: October 23, 2012, 09:58:14 PM »
All it takes is a change of attitude. There is always hope for that since C++ doesn't forgive stupidity. If you do stupid things in C++ it's you who suffer.

Sounds like the perfect language for a masochist.


C++ isn't worth learning unless there is a professional need for you to do so.

Paul Jeffries

  • 7DRL Reviewer
  • Rogueliker
  • *
  • Posts: 257
  • Karma: +1/-0
    • View Profile
    • Vitruality.com
Re: Programming habits, standards, and learning.
« Reply #27 on: October 23, 2012, 11:23:33 PM »
C++ isn't worth learning unless there is a professional need for you to do so.

That's a pretty strong statement for something that's basically just individual preference.  I have to use VB.NET at work, but when I'm programming recreationally I typically choose of my own free will to use C++ (out of the five-and-a-bit languages I'm reasonably competent with).  Sure, there's more that can go wrong with it and it can take a bit longer to write something than it might do in another more friendly language, but I never feel that I have to compromise with C++.  If I want to write high-performance code that will run on pretty much anything then there is nothing intrinsic to the design of the language that stops me from doing that.

Plus, as I said before, I think that the greater depth of knowledge and discipline that C++ demands has made me a better programmer overall even in completely different languages, so I would say it's definitely worthwhile learning even if only for that.

kraflab

  • Rogueliker
  • ***
  • Posts: 454
  • Karma: +0/-0
    • View Profile
    • kraflab.com
Re: Programming habits, standards, and learning.
« Reply #28 on: October 24, 2012, 05:41:27 AM »
...but when I'm programming recreationally I typically choose of my own free will to use C++ (out of the five-and-a-bit languages I'm reasonably competent with).

You know, I have to agree with this.  I can use quite a few languages, but when time is not an issue I think I enjoy writing c++ the most.  Maybe it's because sometimes c++ feels like a syntax puzzle ;) The game-development process is it's own game!

TheCreator

  • Rogueliker
  • ***
  • Posts: 370
  • Karma: +0/-0
    • View Profile
    • Fame
    • Email
Re: Programming habits, standards, and learning.
« Reply #29 on: October 24, 2012, 06:14:56 AM »
It's not C++'s fault that some poorly written code is using typedefs or #define (both outdated C methods).

I haven't seen a library that does NOT use typedefs or #defines, so again: everything will be very simple if you are only using your own perfectly clean code, but as soon as you decide to use anything else, you are doomed to C++'s data type hell.

C++ isn't worth learning unless there is a professional need for you to do so.

When I was in school, many kids used to say that maths is not worth learning. Well, people who are afraid of any mental effort are not worth being listened to ;).
Fame (Untitled) - my game. Everything is a roguelike.