Page 1 of 1 [ 16 posts ] 

zacb
Veteran
Veteran

User avatar

Joined: 7 May 2012
Age: 30
Gender: Male
Posts: 1,194

01 Jan 2013, 11:38 pm

Coming from C, I really was not expecting such a drastic change. Tuples? Dictionaries? And variables are not actually variables? Wow, I am kind of cheeped out. Was anyone else shell shocked with Python? The major thing is the lists, tuples, and dictionaries.



zacb
Veteran
Veteran

User avatar

Joined: 7 May 2012
Age: 30
Gender: Male
Posts: 1,194

02 Jan 2013, 12:00 am

Then again, should I even be worrying at this point? I am using Learning Python, and people said he takes awhile to get to writing a usable program. Anyone's thoughts?



MCalavera
Veteran
Veteran

User avatar

Joined: 15 Dec 2010
Gender: Male
Posts: 5,442

02 Jan 2013, 12:21 am

Go to Udacity site and take the online course there. It took me just one month to know wnough to program simple to moderate programs in Python. There are also more advanced courses you can take there as well.



stands2reason
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 27 Dec 2012
Age: 34
Gender: Male
Posts: 39

02 Jan 2013, 9:08 am

zacb wrote:
Coming from C, I really was not expecting such a drastic change. Tuples? Dictionaries? And variables are not actually variables? Wow, I am kind of cheeped out. Was anyone else shell shocked with Python? The major thing is the lists, tuples, and dictionaries.


All of that stuff is just a high level way of expressing C features you should have already been exposed to. Granted, I know most people didn't build a hash table in C and use it, but I did.

Think of a tuple as an immutable struct without customizable field names. It's a basic structure that's used to represent compound data in math.

Regular arrays directly use an integer key (index), whereas associative arrays (the general term for a dictionary) use a hash of the key. So it's a hash map, basically a hash table or hash tree. In Python you can use any immutable object (include number, string, and tuple) as a key.



Vectorspace
Veteran
Veteran

User avatar

Joined: 3 Oct 2012
Age: 35
Gender: Male
Posts: 903
Location: Germany

02 Jan 2013, 10:45 am

Maybe you should also read the official tutorials, in case you understand them better:
http://docs.python.org/2/tutorial/ for Python 2 and http://docs.python.org/3/tutorial/ for Python 3.

zacb wrote:
And variables are not actually variables?

In what respect?



stands2reason
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 27 Dec 2012
Age: 34
Gender: Male
Posts: 39

02 Jan 2013, 11:55 am

Vectorspace wrote:
Maybe you should also read the official tutorials, in case you understand them better:
http://docs.python.org/2/tutorial/ for Python 2 and http://docs.python.org/3/tutorial/ for Python 3.

zacb wrote:
And variables are not actually variables?

In what respect?


I think he's referring to the fact that in Python, every variable actually an object reference, as opposed to in C, where every variable is a distinct block of memory. This means that "assignment" operations actually copy a pointer and give you two "variables" pointing to the same thing.

If you have mastered C and understand the different between data by-value / by-pointer / by-reference, any good Python tutorial "for C programmers" will cover this.



Vectorspace
Veteran
Veteran

User avatar

Joined: 3 Oct 2012
Age: 35
Gender: Male
Posts: 903
Location: Germany

02 Jan 2013, 2:58 pm

stands2reason wrote:
Vectorspace wrote:
zacb wrote:
And variables are not actually variables?
In what respect?

I think he's referring to the fact that in Python, every variable actually an object reference, as opposed to in C, where every variable is a distinct block of memory. This means that "assignment" operations actually copy a pointer and give you two "variables" pointing to the same thing

Ah, OK, I was initially confused by that, because it's different for different kinds of data:
Code:
>>> a=1
>>> b=a
>>> a=2
>>> b
1

>>> foo=[1,2]
>>> bar=foo
>>> foo[1]=3
>>> bar
[1, 3]

OK, in fact, it's consistent. In the first case, "a" is just reassigned to something else, and nothing is modified. In the second case, the content of "foo" is modified, and because "bar" points to the same data, this also means that the content of "bar" is modified.

But you in languages like Java, you have the same problem.



stands2reason
Tufted Titmouse
Tufted Titmouse

User avatar

Joined: 27 Dec 2012
Age: 34
Gender: Male
Posts: 39

02 Jan 2013, 3:58 pm

Vectorspace wrote:
But you in languages like Java, you have the same problem.


You have the same problem in C using pointers, expect that C/C++ always gives you the option of referencing and dereferencing. Java and C# store object references, which means you have to have to either use immutable objects or remember to copy the object instead of just the pointer if you actually want two copies of data.



guitarman2010
Veteran
Veteran

User avatar

Joined: 12 May 2012
Gender: Male
Posts: 578
Location: Erie, PA

02 Jan 2013, 9:27 pm

I am in the process of learning Python.....going on day # 4 and started with no knowledge of Python. I only have experience with BASIC so Python is definetely a step up. My issues now with only being on day #4 are with the whitespace concept. I think the website I started learning with, CodeAcademy, is not very thorough in explainations of using commands. Their exercises are set up nice but it is frustrating. I'm so used to the simple IF/ELSE, DO/WHILE, FOR/NEXT....etc from BASIC that it's hard to incorporate different spacing and punctuation. Oh well, it's fun :)


_________________
When u hit the walls of sanity, u have no-where to go....


Vectorspace
Veteran
Veteran

User avatar

Joined: 3 Oct 2012
Age: 35
Gender: Male
Posts: 903
Location: Germany

03 Jan 2013, 2:55 pm

For the whitespace issue, you should really use an editor with a specific Python-syntax mode.



Hermes9
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 5 Aug 2012
Age: 45
Gender: Male
Posts: 61
Location: Austin, TX

03 Jan 2013, 3:11 pm

Python is a weird beast, but it's not complicated at all. Just.. different in all the wrong ways (personal opinion, of course)

You might try your hand at Ruby first, if you are not used to object-oriented high-level script languages. It's similar in a lot of ways, but not quite so "weird".

Personally, I prefer Ruby, but end up having to work in Python enough to need to know it.

I recommend Mark Lutz's book "Learning Python", 4th edition, ISBN 978-0596158064. IMHO it's one of the better ones for getting started with Python.

I still could use to learn a lot more Python, but seem to know enough to skate by... :)



0_equals_true
Veteran
Veteran

User avatar

Joined: 5 Apr 2007
Age: 43
Gender: Male
Posts: 11,038
Location: London

03 Jan 2013, 5:09 pm

Not so far removed really. it is still in the same class of languages.

Compare with a functional language like erlang, now it really is quite a bit different.

Variables are immutable like constants. Except it is wrong to think 'constants' because in a mathematical sense constant are always present they are not assigned). In a functional language a variable is set for that function you cannot unset it. But that is true in maths. Once you say x=5 then x=5, if you are saying x=6 that is a different equation.

It is good to get out of the habit of getting to used to one particular language. Sometimes you only truly understand something once you can properly compare it. if you as using all the code candy, then you don't appreciate the pro's an cons.



guitarman2010
Veteran
Veteran

User avatar

Joined: 12 May 2012
Gender: Male
Posts: 578
Location: Erie, PA

04 Jan 2013, 5:07 pm

Thanks for some of the advice, especially the whitespace comment and the one about not getting to used to one language too much. I don't want to stop learning it now because it is so neat. How popular is the Ruby language and what is it mainly used for? I could easily Google the answer but would like to hear from actual user comments as opposed to possibly biased articles and reviews :)


_________________
When u hit the walls of sanity, u have no-where to go....


Hermes9
Yellow-bellied Woodpecker
Yellow-bellied Woodpecker

User avatar

Joined: 5 Aug 2012
Age: 45
Gender: Male
Posts: 61
Location: Austin, TX

04 Jan 2013, 5:21 pm

guitarman2010 wrote:
How popular is the Ruby language and what is it mainly used for?


Ruby doesn't seem to be as popular as Python -- Python seems to have a larger userbase, although both languages are pretty popular.

Both Ruby and Python are high-level, object-oriented, interpreted scripting languages available under the GPL. Really they aren't very much different in terms of what they are used for and what they can do -- Both are general purpose and have a plethora of "add ons" available from the user community. I suppose the main difference is that Python believes in "consistency" (always doing things the same way) whereas Ruby's mentality is that more than one way to do something is acceptable. Ruby also completely ignores whitespace, which IMHO, just means one less thing to concern yourself with. Variables in Ruby are also variable.

Honestly, the whitespace matters and immutable variables in Python are absolutely illogical to me, but the rest of the language is beautiful enough that I appreciate it much :)

Ruby syntax is also more Perl-like, so if you have a Perl background, you may pick up Ruby quicker.

Happy Hacking :twisted:



Vectorspace
Veteran
Veteran

User avatar

Joined: 3 Oct 2012
Age: 35
Gender: Male
Posts: 903
Location: Germany

04 Jan 2013, 5:25 pm

I've never actually coded in Ruby, but for me, it looks too much object-oriented, so I still prefer Python.
(I got used to the whitespace stuff once I stopped complaining.)

In general, Python is more popular, but Ruby is strong in web development.



Trencher93
Velociraptor
Velociraptor

User avatar

Joined: 23 Jun 2008
Age: 125
Gender: Male
Posts: 464

05 Jan 2013, 2:42 pm

Coming from C, I suppose any modern language would be different. Most languages have build-in implementations of basic data structures like lists, maps (dictionaries), and so on. If you learn one of these languages, the others will be easier to learn. C is anomalous because it's so heavily used in UNIX and Linux that a gigantic code base exists which will never be replaced, and it's still in use today for that reason. Other languages contemporary to C like Pascal, Modula-2, etc have faded over the past couple of decades as the convenience of modern languages was too great to resist. I'd rather use C++ than write yet another linked list implementation in C. My time just isn't worth spending on that, especially when C++ makes nested data structures easier.

The most significant problem presented by C++, Java, Python, Objective-C, C#, etc is that each one does basically the same thing, but does it in a different way. I have a lot of trouble remebering which language I'm using and how to do things.

Python has both immutable tuples and mutable arrays. Some languages like Objective-C are similar in their mutable/immutable splits, and others like C++ don't care but allow you to make a data structure immutable if you want to. (At least if you understand C++'s byzantine const rules.)

Python's whitespace is unusual, and it is probably the first language since COBOL to have syntactically significant whitespace. Using something like Emacs' python mode allows you to rely on your editor to indent properly. If the editor gets confused, you probably messed up someplace.

Another split is between the runtime dynamic languages like Python and Objective-C (and others) and the compile-time static languages like C++. Java manages to combine the drawbacks of both into the same language. Switching between dynamic and static languages requires a cognitive shift.