Topic: Good programming language to learn?

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
Gah I hate how C# does multi-dimensional arrays, arrays shouldn't hold "x by y data". Array's should only hold a number of "items" in one dimension. Then you have an array of arrays, or a jagged array in C#. Stupid C# with its redundant code.

Kayne:
I'd suggest learning how to use a basic one dimensional array, eg. Create an array, assign values to varying indexes of an array, have a play around with removing to learn the functionality of arrays.

THEN, you can move onto multi-dimensional arrays, which will probably be what you want in this situation. You don't have to use a multi-dimensional array, you can do it with a one dimension array, but its tidier to use more than one dimension in this case.

And pyro why tictactoe? I want to play some connect4 yo! :D

Reply #150 Posted: November 25, 2010, 01:07:13 am
-= Sad pug is sad =-

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
^ Because start simple.
It's the perfect little thing to keep interested parties from becoming disinterested, keep them learning and discovering, and making a neat little game :)

Quote from: Pyromanik;1335414
^ depends. On a number of things, most of all the toolkit being used.
If it's Qt, use Qt designer, it comes with the Qt package.


Glade for GTK apparently.




Quote from: `Kayne;1335434
kk, I'm still quite confused over how I'm meant to use arrays. I could easily do this with if statements, but when I try put arrays into the equation.. I just can't work it out!

I have no idea what i'm meant to be making into an array. The possible wins? Each squares possibility? Or just the outcome of the board?


An array is just a collection of data.





In a way you can think of them as the times tables. Only instead of 3x2, it's 3xtype (where type is like an integer, double, etc).
Perhaps an easier (more visual) way to think of them, is if you think of each array as a set of cubby holes, and each hole has some data in it.


---------------------------------


So I have an array called 'cubbyholes', and it's size if five (size is less relevant to you chaps with your higher level languages, but for tutorial's sake, it's size is five).

  cubbyholes = [ ] [ ] [ ] [ ] [ ].

There is nothing in any of my cubbyholes.
I want to put something into the third cubbyhole, so I access it and put something in there. A book (b).

  cubbyholes = [ ] [ ] [b] [ ] [ ].

I'll put a pen (p) in the first one, and a CD (c) in the second one.

  cubbyholes = [p] [c] [b] [ ] [ ].

Now I want to put my apple I bought for lunch, but I don't want to get ink on it, have it leak applejuice on my books, or get it mixed up with computer junk. I'll put it in the last one.

  cubbyholes = [p] [c] [b] [ ] [a].

Now imagine, just for demonstration's sake, that we live in the future. We have nifty interdimensional storage, like in that movie UltraViolet.

I want to store an array of stuff in my last cubbyhole. Say for arguements sake that I have 3 more things to put in storage. T-shirts socks and pants. I need 3 more holes.
I'll make an array of 3, and call it clothes.

  clothes = [t] [s] [p].
   cubbyholes = [p] [c] [b] [ ] [a].


Now I'll put that array of clothes into my cubbyholes.

  cubbyholes = [p] [c] [b] [[t][s][p]] [a].

An easier way to visualise this would be in 2 dimensions:

Code: [Select]
[p] [c] [b] [t] [a]
      [s]
      [p]




In hard typed languages, all contents of an array must be the same. So you can only have an array full of integers, not integers and doubles and whatever else you want to put in there. You can get around this, but it goes beyond the scope of my explanation (encapsulating with objects). I'm not sure what kind of typing C# or Python has, but I imagine hard and soft respectively.





Now imagine you have an array, size three, containing size 3 arrays.
I think you can figure the rest out ;)




Does my insomnia help you?

Reply #151 Posted: November 25, 2010, 02:04:34 am
Everyone needs more Bruce Campbell.

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
But, but, but I wana play Connect4 :<

^ Good explanation of arrays.

C# has two data structures for Multidimension arrays. What they call multidimension is created by int[,] or int[,,] for 2d, 3d etc... and they have another type of array called a jagged array (the multidimensional explained above) which is the good ol' int[][] etc... Both are restricted to the type given at construction, so it seems to keep the same format as other similar languages.

Jagged Arrays >>>>> Multidimensional, but they're a pain to set up because you need to create EVERY CELL in the array, so a massive amount of overhead at creation of the object. But they're easier to loop around, so the advantages soon stack up when you are doing a lot of searching through arrays, they're also slightly faster because its not limited to the method invocations of the multidimensional array.

I got bored, and also suffer from insomnia ;-) So I made a sample solution. two reasons for not giving code 1) I don't want to give the answers away :P 2) The code is terriblly hacky, everything is static, the code is pretty much the quickest solution I made to work :P

Reply #152 Posted: November 25, 2010, 03:27:24 am
-= Sad pug is sad =-

Offline toofast

  • Addicted
  • toofast barely matters.toofast barely matters.
  • Posts: 3,697
Quote from: Pyromanik;1335451
Quote from: Pyromanik;1335414
^ depends. On a number of things, most of all the toolkit being used.
If it's Qt, use Qt designer, it comes with the Qt package.


Glade for GTK apparently.



Cheers for that, it does sound like gtk. I will have a look today.

Reply #153 Posted: November 25, 2010, 08:30:13 am

Offline Apostrophe Spacemonkey

  • Fuck this title in particular.

  • Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!
  • Posts: 19,050
Quote from: Xenolightning;1335453
I got bored, and also suffer from insomnia ;-) So I made a sample solution. two reasons for not giving code 1) I don't want to give the answers away 2) The code is terriblly hacky, everything is static, the code is pretty much the quickest solution I made to work

A strange game. The only winning move is not to play. How about a nice game of chess?

Reply #154 Posted: November 25, 2010, 08:48:53 am

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
Quote from: toofast;1335471
Quote from: Pyromanik;1335451
Quote from: Pyromanik;1335414
^ depends. On a number of things, most of all the toolkit being used.
If it's Qt, use Qt designer, it comes with the Qt package.


Glade for GTK apparently.



Cheers for that, it does sound like gtk. I will have a look today.

GTK is C, not C++.

Reply #155 Posted: November 25, 2010, 02:01:41 pm
Everyone needs more Bruce Campbell.

Offline Spoonguard

  • Addicted
  • Spoonguard has no influence.
  • Posts: 2,327
Quote from: Xenolightning;1335441
Array's should only hold a number of "items" in one dimension.

...what? I am not familiar with C# so I don't know what you are specificity referring to, but being restricted to one-dimensional arrays would be crippling

Reply #156 Posted: November 25, 2010, 02:03:46 pm
        and nothing of value was lost.

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
Any single array holds a single dimension of data.
Multi-dimension arrays come from making that data more arrays.


Reply #157 Posted: November 25, 2010, 02:05:47 pm
Everyone needs more Bruce Campbell.

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
Being restricted to 1-D arrays isn't that bad.

Reply #158 Posted: November 25, 2010, 02:09:58 pm

Offline Spoonguard

  • Addicted
  • Spoonguard has no influence.
  • Posts: 2,327
Quote from: Bell;1335610
Being restricted to 1-D arrays isn't that bad.

I don't know of a language that restricts you to this

Reply #159 Posted: November 25, 2010, 02:16:41 pm
        and nothing of value was lost.

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
Well some languages just don't give you the syntax to make multi-dimensional arrays.
It's impossible to 'restrict' someone from making multi-d arrays because you can just implement them yourself by creating list of lists.
So when I say restricted to 1D array I really mean syntaxicly restricted.

Reply #160 Posted: November 25, 2010, 02:28:03 pm

Offline Apostrophe Spacemonkey

  • Fuck this title in particular.

  • Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!Apostrophe Spacemonkey is awe-inspiring!
  • Posts: 19,050
Yeah in C# you can do int[,], or an array of arrays.

imo either way is fine, just whatever suits your style.


Reply #161 Posted: November 25, 2010, 04:19:02 pm

Offline Xenolightning

  • Moderator
  • Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!Xenolightning is awe-inspiring!
  • Posts: 3,485
Quote from: Spacemonkey;1335655
Yeah in C# you can do int[,], or an array of arrays.

imo either way is fine, just whatever suits your style.
Yea the first way, just seems un-natural especially if you start programming with the likes of C, where such data structures seem (as said before) redundant. There is effectively no difference in creating a 2D array of int[,] or int[][], just the interaction is slightly different.

Also, how is the game strange? lol, I'll give you that its not the best interface, but its tictactoe, and it works "effectively".

Quote from: Bell;1335625
Well some languages just don't give you the syntax to make multi-dimensional arrays.
It's impossible to 'restrict' someone from making multi-d arrays because you can just implement them yourself by creating list of lists.
So when I say restricted to 1D array I really mean syntaxicly restricted.
Yea it seemed kind of weird when I threw together that app, I used an array of arrays of ints, and had issues because I had to initialise them. So I gave in and used their stupid multi-D syntax

Reply #162 Posted: November 25, 2010, 05:35:40 pm
-= Sad pug is sad =-

Offline Kayne

  • Addicted
  • Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!
  • Posts: 3,298
Just got home from work experience.

I understand what you all have explained, But I don't understand why you would need to, apart from doing something to the whole array of items at once. Why not just make...

string cubbyholebox1;
string cubbyholebox2;
string cubbyholebox3;

if user says so and so, cubbyhole1= shoes

I'm just confused by how its different. It kinda just seems tidier D:

I thought of another use, which really might only apply to gmod, which could add a new line in the array each time it finds a specific object.

Reply #163 Posted: November 25, 2010, 06:01:01 pm
Quote
Top Geary - 27th May 2016 at 12:10 AM
I've learnt to ignore when you say derogatory things to me

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
Well you pretty much hit the nail on the head putting things into an array makes it easy to perform common actions on them.
Also arrays allow you to easily make a group of common items without having to give each one a name since you can refer to them by index.

Sure when you have 3 objects arrays seem like overkill.
But it is very common in computer programs to have 1000's

It wouldnt be fun typing out

string cubbyholebox1
string cubbyholebox2
string cubbyholebox3
.........
string cubbyholebox1000

Instead we can write
Code: [Select]
string cubbyholdbox[1000]

for int i = 0; i &lt; 1000; ++i do
 cubbyholdbox[i] = new string()
end

Reply #164 Posted: November 25, 2010, 06:21:01 pm

Offline Kayne

  • Addicted
  • Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!
  • Posts: 3,298
Quote from: Bell;1335697
It wouldnt be fun typing out.
string cubbyholebox1 all the way to
string cubbyholebox1000 now would it.
But arn't you just as equally typing out

ARRAY [1] [2] [3]...[998][999][1000]?

Reply #165 Posted: November 25, 2010, 06:23:27 pm
Quote
Top Geary - 27th May 2016 at 12:10 AM
I've learnt to ignore when you say derogatory things to me

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
thats when for loops come in, see above example.

Also doing it by index allows us to make changes to the program easy.
What if after a week we realised we didn't need 1000 strings we only needed 500, in your system we need to delete 500 lines of code.
I can just do this

Code: [Select]
string cubbyholdbox[500]

for int i = 0; i &lt; 500; ++i do
 cubbyholdbox[i] = new string()
end

Reply #166 Posted: November 25, 2010, 06:24:51 pm

Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562
<3 for loops

Reply #167 Posted: November 25, 2010, 06:27:25 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Kayne

  • Addicted
  • Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!
  • Posts: 3,298
Can you explain the syntax a little please Bell?

Trying to understand the first line.

is it saying for when int i = 0, aswell as when i < 500 do so and so
or, is it saying, when int i = 0, or i < 500, do so and so

Reply #168 Posted: November 25, 2010, 06:31:00 pm
Quote
Top Geary - 27th May 2016 at 12:10 AM
I've learnt to ignore when you say derogatory things to me

Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562
first i is the starting condition, second i is the end condition, i++ is increase i by 1 (i.e i +1)


translated, that segment of code is basically

Quote
for every instance of i between 0 and 500, create array segment (or whatever its termed) for that value of i, then add 1 to i and repeat


i hope thats right and understandable, its been a while

Reply #169 Posted: November 25, 2010, 06:34:24 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Kayne

  • Addicted
  • Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!Kayne is awe-inspiring!
  • Posts: 3,298
I understand what you've said, but its confusing that the conditions of the loop are on the same line as (+ 1 to i each time), with no indication of it changing from condition to action.

and, how the hell do i keep the console window open? it always instant closes?

nvm, worked it out :)

Reply #170 Posted: November 25, 2010, 06:39:56 pm
Quote
Top Geary - 27th May 2016 at 12:10 AM
I've learnt to ignore when you say derogatory things to me

Offline Speakman

  • Hero Member
  • Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!Speakman is awe-inspiring!
  • Posts: 12,562

Reply #171 Posted: November 25, 2010, 06:50:18 pm
Quote from: Mellcor
i had kinda hope speakman had died, what a pity

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
ahh sorry for loops are written most of the time in a condensed form like that just to speed up programming.
I'll do it using a while to show you it clearer.

Code: [Select]
int loop_size = 500
int current = 0

while current &lt; loop_size do
  cubbyholdbox[current] = new string()
  current = current + 1
end

Reply #172 Posted: November 25, 2010, 06:53:46 pm

Offline Pyromanik

  • Hero Member
  • Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!Pyromanik is awe-inspiring!
  • Posts: 28,834
I find C infinately easier to read:

Code: [Select]
int i;
char[20] myArray;
for(i = 0; i &lt; 20; i = (i + 2)) {
   myArray[i] = 'a';
}

it will end up looking like this:
(kinda, the operation isn't safe iirc, but for demonstration purposes...)

Code: [Select]
[a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ] [a] [ ]

In a for loop, the first parameter sets the initial values, the second parameter supplies the 'until' clause, and the last one is the action performed after every loop.
In this case, I increase i after every loop by 2. And when it hits fifty, it is no longer less than 50, so the loop code is no longer executed and the program moves on. I make sure I get the correct result by initilising my variable i to 0 in the beginning.

Reply #173 Posted: November 25, 2010, 07:10:02 pm
Everyone needs more Bruce Campbell.

Offline Bell

  • Addicted
  • Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.Bell is on the verge of being accepted.
  • Posts: 4,263
my pseudo code here is some weird mix between C and lua :p

Reply #174 Posted: November 25, 2010, 07:12:52 pm