Advertisement

What's in a language that makes you like it

Started by February 14, 2014 06:00 AM
63 comments, last by cr88192 10 years, 8 months ago


Isn't there something that could replace 'for'

I don't see anything wrong at all about for. Actually, I find it intuitive. Did you take the time to thoroughly study and understand it?

This


for ( initialization; condition; step )
{
    statement(s)
}

is equivalent to this:


initialization;
while ( condition )
{
    statement(s)
    step;
}

This discussion has already become off-topic, and I'll wrap up with a suggestion. Read at least Volume 1 of Bruce Eckel's Thinking in C++ books (old but really good), do ALL of the exercises, write a lot of code, learn from your mistakes, read about C++11 and write more code to update what you learned from the book.

I hear and I forget, I see and I remember, I do and I understand.

Isn't there something that could replace 'for'

I don't see anything wrong at all about [font=courier new']for[/font]. Actually, I find it intuitive. Did you take the time to thoroughly study and understand it?

This
for ( initialization; condition; step ){    statement(s)}
is equivalent to this:
initialization;while ( condition ){    statement(s)    step;}
This discussion has already become off-topic, and I'll wrap up with a suggestion. Read at least Volume 1 of Bruce Eckel's Thinking in C++ books (old but really good), do ALL of the exercises, write a lot of code, learn from your mistakes, read about C++11 and write more code to update what you learned from the book.
I hear and I forget, I see and I remember, I do and I understand.
i do understand it now. I meant i didn't get it in the beginning.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

Advertisement

C# is my favourite language by far, currently using version 4 of the language (VS2010). It's reasonably concise on its own, and most code/libraries follow the same or at least very similar conventions. If you use C or C++, just about every library has its own naming schemes etc. I also feel like C# was made with "the real world" in mind as opposed to Java which I feel is more "academic" (follows paradigms and patters more closely, but feels more over-engineered and less productivity oriented).

I also like that C# has a relatively "simple" syntax, making it easy to parse and understand, which in turn make it easier to create tools. It is also much more "defined" than for example C++ which makes it easier to work with in some cases (an "int" is always a 32 bit signed integer in C#, ++i++ is downright illegal etc). It is much more strict, catching lots of easy to make misstakes at compile time. It is "safe" by default, with the optional and explicit drop out to "unsafe" mode for the rare cases where you need that extra bit of control or interopability.

It is statically typed (well, there's "dynamic"...) and normal usage includes a compile step which (using common tools) is fast and provides a reasonable sanity check on the whole project. I'm listing this because I've written a lot of PHP where it's way to easy to make "obvious" misstakes that aren't caught until you execute that particular code, forcing you to rely on things like unit testing to a much larger degree.

It appears to have a fairly "grown up" user base. It has MSDN documentation for the language and core libraries. There are awesome tools. There is "one" C#, it isn't suffering from forks, language extensions and what-not (yet). It's standardized and backed by a large resourceful company. It is also mostly developed by said company, as opposed to some democratic community thing which usually turns into some giant horrible mess (see PHP1).

1 I've followed to PHP development mailing list (php.internals newsgroup) during several years for some unknown reason, and I find it frightening that it's so widespread knowing how it's being developed.


i do understand it now. I meant i didn't get it in the beginning.

You don't "get" anything in the beginning. That's why most things come with an instruction manual or someone you can talk to who can tell you how to use it. If you had never seen a light switch before, would you innately know that flipping it would turn on a nearby light bulb? No, you'd carefully examine it and then eventually attempt to flip it, and then flip it back, until you fully understand what it does.

Even the simplest Python syntax "for i in range(1, 10)" is misleading in that the loop excludes 10, and you wouldn't know that if you hadn't been exposed to the widespread convention that ranges are generally given excluding the end. You also aren't aware of the optional step parameter until you see it used or are told about it, and you have no clue that "range" is actually just a generator and that the "for" statement can work with any such generator. If you came from Pascal instead ("for i := 1 to 10 do") then you could conceivably imagine the Python syntax to include 10. The C-like syntax makes deducing that easier since the termination condition is clearly given... that is, unless you don't know what each part of the for statement stands for, in which case it is obscure (or downright incomprehensible).

What's the difference between a while..do and a do..while (or a repeat..while) loop? One runs at least once. Would you be able to deduce that from the syntax alone? Likely not, even though the condition appears first in one case, the two ("while something is true do something" and "do something while something is true") are semantically equivalent in everyday usage, and a newbie would have a hard time working out the difference without being told about it, or by trying it out for himself. And even trying it out for the first time and understanding the output one gets from some test program is a difficult exercise in hypotheticodeductive reasoning for many people (none of them particularly stupid).

The point I'm making is that nothing is really self-evident unless you've been exposed to it (a process called learning) or something similar (called past experience). In other words, what is "simpler" to you is awkward or unintuitive to some other people, and vice versa. So programming languages just use whatever seems more powerful/expressive/readable and expect people to read the manual to get familiar with those constructs. In this case, the for statement is much more powerful than just iterating a range of numbers, and can be used to great effect, so replacing it with a "for x from 1 to 10" kind of statement would actually make it less useful.

I will agree that the Python syntax is much better (from my perspective) in that it doesn't obfuscate the sequence being iterated by splitting it across three different statements, but instead makes it into an explicit generator - though that has its downsides as well - but saying that "I didn't get it in the beginning" makes the syntax bad is rather narrow-minded in my opinion.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

That example of a python for loop is also misleading in how it works under the hood.

for [each item] in [an iterable object]:

[statements]

The oddness isn't in the for loop, but rather in python's range() function. And frankly I've never really liked that function to be honest.

So, what does range do? It is used to generate a list. The for statement says "do something with each item in this list", and provides you a way to easily name the item currently being looked at.

This of course has some neat tricks you can do with it, and some interesting gotchas.

Since the for statement is counting up over a list of items, if you are going over a structure that contains data that can be unpacked in a logical way then you can put more named variables in the for statement to automatically unpack them for you.

You can use a for loop going over a list while building the list with that loop. Which is just weird if you think about it too much.

You can skip elements if you try to use a for loop going over a list that you delete bits out of.

Old Username: Talroth
If your signature on a web forum takes up more space than your average post, then you are doing things wrong.

i do understand it now. I meant i didn't get it in the beginning.


You don't "get" anything in the beginning. That's why most things come with an instruction manual or someone you can talk to who can tell you how to use it. If you had never seen a light switch before, would you innately know that flipping it would turn on a nearby light bulb? No, you'd carefully examine it and then eventually attempt to flip it, and then flip it back, until you fully understand what it does.

Even the simplest Python syntax "for i in range(1, 10)" is misleading in that the loop excludes 10, and you wouldn't know that if you hadn't been exposed to the widespread convention that ranges are generally given excluding the end. You also aren't aware of the optional step parameter until you see it used or are told about it, and you have no clue that "range" is actually just a generator and that the "for" statement can work with any such generator. If you came from Pascal instead ("for i := 1 to 10 do") then you could conceivably imagine the Python syntax to include 10. The C-like syntax makes deducing that easier since the termination condition is clearly given... that is, unless you don't know what each part of the for statement stands for, in which case it is obscure (or downright incomprehensible).

What's the difference between a while..do and a do..while (or a repeat..while) loop? One runs at least once. Would you be able to deduce that from the syntax alone? Likely not, even though the condition appears first in one case, the two ("while something is true do something" and "do something while something is true") are semantically equivalent in everyday usage, and a newbie would have a hard time working out the difference without being told about it, or by trying it out for himself. And even trying it out for the first time and understanding the output one gets from some test program is a difficult exercise in hypotheticodeductive reasoning for many people (none of them particularly stupid).

The point I'm making is that nothing is really self-evident unless you've been exposed to it (a process called learning) or something similar (called past experience). In other words, what is "simpler" to you is awkward or unintuitive to some other people, and vice versa. So programming languages just use whatever seems more powerful/expressive/readable and expect people to read the manual to get familiar with those constructs. In this case, the for statement is much more powerful than just iterating a range of numbers, and can be used to great effect, so replacing it with a "for x from 1 to 10" kind of statement would actually make it less useful.

I will agree that the Python syntax is much better (from my perspective) in that it doesn't obfuscate the sequence being iterated by splitting it across three different statements, but instead makes it into an explicit generator - though that has its downsides as well - but saying that "I didn't get it in the beginning" makes the syntax bad is rather narrow-minded in my opinion.
there are some that are explanatory like if and else but i get what you are saying.
The one that is confusing me is pointers. I know how to use it but don't why i would want to use it.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

Advertisement


The one that is confusing me is pointers. I know how to use it but don't why i would want to use it.

This one nailed it.

Before you can be a beginner in game programming, you need to get past being a beginner in programming. Your signature gives it away: you have A LOT of work to do. You're not yet in a state where you lack answers, you still lack the questions.

The book I recommended in my early reply will be a good starting point. Read it and learn about pass-by-value, pass-by-reference, the stack and the heap, arrays, pointer arithmetic, and dynamic memory allocation. Then try and implement a very simple dynamically-allocated stack or linked list - you'll need pointers.

The one that is confusing me is pointers. I know how to use it but don't why i would want to use it.

This one nailed it.

Before you can be a beginner in game programming, you need to get past being a beginner in programming
i knew this that's why i decided to learn programming first. I could have downloaded any game engine and tried to make games and be one of the numerous people asking for pointers on writing code, maybe for player movement.
The things in my signature are what i want to do in the order they are written. Everything before '=>simple Games' must be done first.
I want to learn what i need to do what i want before i do it and not while i'm doing it.

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

You're very wrong in your signature. You should have started making games already. After the first "Hello World" program you should make a game. "Guess the Number" for example.

This procrastination many newbies have is so strange to me. I couldn't wait to jump right into game making when I was a beginner. After 8 months of programming, I started to make a 2D worms-like game, though I only had about 0.5% of the necessary knowledge when I started. I learned along with game programming. It's much more fun, much more rewarding (and instantly rewarding, which is IMHO very important in order to enjoy programming) and much more effective.

All that "knowledge" you learn before you start to make a game will be lost. It's very ineffective, if not impossible to memorize all those stuff (and needles too) without a real context.

You're very wrong in your signature. You should have started making games already. After the first "Hello World" program you should make a game. "Guess the Number" for example.

This procrastination many newbies have is so strange to me. I couldn't wait to jump right into game making when I was a beginner. After 10 months of programming, I started to make a 2D worms-like game, though I only had about 0.5% of the necessary knowledge when I started. I learned along with game programming. It's much more fun, much more rewarding (and instantly rewarding, which is IMHO very important in order to enjoy programming) and much more effective.

All that "knowledge" you learn before you start to make a game will be lost. It's very ineffective, if not impossible to memorize all those stuff (and needles too) without a real context.

although i do want to learn all that first before making any game, i've made 3. Tic-tac-toe, guess the number and some sort of who wants to be a millionaire game (or q&a).
All without graphics (and i don't want make only games).

UNREAL ENGINE 4:
Total LOC: ~3M Lines
Total Languages: ~32

--
GREAT QUOTES:
I can do ALL things through Christ - Jesus Christ
--
Logic will get you from A-Z, imagination gets you everywhere - Albert Einstein
--
The problems of the world cannot be solved by skeptics or cynics whose horizons are limited by the obvious realities. - John F. Kennedy

This topic is closed to new replies.

Advertisement