~Spark~ wrote:I don't really know much about the difference between static and non-static(No sure that's the right term) languages.
Dynamic typing is when you can assign anything to any variable. Like, you have some variable called, for example,
a, and you can write (I hope this is correct Python syntax):
- Code: Select all
a = 10
a = "some text"
a = 3.14
a = [5, 1, 8]
Here,
a is first an integer, then a string, then a floating-point value, and finally a list. And it is the same variable all the time.
With static typing, you cannot do that, as every variable (and function/method argument, and so on) has a strictly specified type. So, when you declare
a as a
string, you cannot assign a number to it (or, in some cases, it will automatically get converted to a string.
~Spark~ wrote:BTW, how does Python compare to C++?
Python is a dynamically typed language, while C++ is statically typed. Also, C++ is much more low-level, which means that you can write code that does really bad things and it is harder to find bugs in them. But it also executes faster. Python's dynamic typing also mean that some of C++'s features would be meaningless in it, like templates or conversion operators.
Also, C++ is a so-called
curly bracket programming language. In Python, blocks of code are specified by indentation, and statements are separated from each other with a newline. In C++ (and C, Java, C#, Perl, PHP and many other languages), indentation and newlines are purely aesthetic, and statements are terminated with semicolons, and grouped in blocks using curly brackets {}. For example:
Python:
- Code: Select all
if i == 10:
print("Hooray!")
print("i equals 10")
else:
print("i does not equal 10 :(")
C++:
- Code: Select all
if (i == 10) {
puts("Hooray!");
puts("i equals 10");
} else
puts("i does not equal 10 :(");
The same code can be written on a single line like:
- Code: Select all
if (i == 10) { puts("Hooray!"); puts("i equals 10"); } else puts("i does not equal 10 :(");
The
else block doesn't need to be put in curly brackets because it's just a single statement. But remember, it is almost always a good practice to consistently indent your code, regardless of whether the language enforces it or not.
develoore wrote:I loved doing C++ before, we also learned C# back in secondary school.
I need to start learning Java as soon as possible, because my next job is entirely in Java.
If you learned C# before, you'll feel at home. The syntax is almost identical in those two languages, AFAIK the APIs are also somewhat similar. You'll just have to learn the naming conventions and so on.