Electric-Eye
translating from Java to Python
A while back, I decided to take the dive and try to learn a programming language. I wasn't sure which one would be best for someone who was something of a beginner, and with a rather sketchy idea of what I hoped to be able to do with it. I chose Java because I found some good resources, the Stanford CS106a intro to computer science class, with all video lectures on youtube, free eclipse coding editor/compiler, class handouts, example programs, solutions to all exercises, textbooks in pdf format. And a very well-written textbook too, "The Art and Science of Java" by Eric S. Roberts.
After a few chapters , I decided that I could forget the lectures, and just study from the book. The programming exercises at the end of each chapter are actually more demanding than the assignments actually given in the class anyway, and as entertaining as the professor is, his humorous delivery doesn't always help the relevant programming concepts come through clearly.
But I have had a very eventful year, and mostly because of pressures in my life I've stalled about halfway through the book.
In my reading about learning to program I began to see more advice to novices learning to program and trying to choose a language. And for many reasons I've come to think that python might be better as an introductory language. Some of these reasons are : 1. it is very popular today, and tutorials are offered on it through many educational websites such as Khanacademy and codeacademy. 2. its syntax is simpler, it requires less typing and fewer special concepts to understand before you can begin. Such as, in Java all variables must have their type declared when they are first used, additionally variables, classes, methods and functions all need an explicit privacy setting applied when they are created, this is hard to understand for someone who is already straining to understand what classes, methods, functions and such mean in the first place. 3. Java is a compiled language, and commands from it cannot be tried interactively in isolation at a command prompt. This means that there is always a delay between what you write and the result it produces. It also means that it can be hard to test parts of a program in isolation to see what works and what doesn't. This is kind of a big deal for me, because when I first used a computer, as a child of about 8, in the mid-1980s, I was familiar with the command prompt, and the fact that I could type expressions and get results as soon as they were entered, so programming could be learned by playing. Shortly after the Commodore was stolen from my dad's place in the late 80s, I ceased coming into contact with any computers, which had an interpreter-based operating system. The perception was that you would buy a computer to run programs instead of to write them. That you would buy programs to run on your computer, rather than build your own programs yourself. This view was enforced by computers coming with a DOS operating system, which would let you load programs, copy data, examine directories, but which didn't directly facilitate you writing programs of your own. When, in the early 90s, Windows became popular, my attention shifted from writing programs, to the things that could be done with programs. Playing games, making art, downloading documents and communicating with people. In the windows era, you had much greater potential to use your computer to write articles, do complex calculations with little setup time, play fast, beautiful, immersive games, play music or create stunning graphics. But you had to already have the programs someone else had written, in order to do these things. You used the operating system of the computer to open them, and to switch between them conveniently, but not to create. Not to make the machine do what you wanted. In windows, you can have your math expressions evaluated in the calculator, or in a spreadsheet, but you are shielded from touching the power of computing itself.
Moving from Java to Python is easier than I expected. The difference is much less than between BASIC and Java. Functions and function calls make sense, instructions to import make sense, variables being local to a function make sense. There are similar data types, many keywords are the same between the languages, (and there aren't that many keywords, about 30. more or less, in each language, and most of them are probably common to both, and probably also common to several other computer languages)
In the picture, the program on the left is notepad++ with a python program written in it. In the Stanford Eclipse editor on the right we see hilighted, the same program written in Java. This was an early Java programming exercise from the textbook, "The Art and Science of Java" and I just translated it, into equivalent Python code.
The Python is more compact, and largely because it relies on the indentation which is a strongly suggested style in Java, to do the same job as the opening and closing curly braces which, in Java are mandatory.
Also noticeable are the shorter and simpler lines for method definitions and for loops. and in Java, the boolean test conditions are enclosed within parentheses that Python simply does without. The for loop in Python also has several other goodies, like an index variable, not declared or explicitly initialized, the powerful Python keyword, "in" and the very useful function or method, range()
In spite of my interest in Python, I am not eager to give-up on Java yet. But I can foresee Python as my default language for quick computer experimentation.
translating from Java to Python
A while back, I decided to take the dive and try to learn a programming language. I wasn't sure which one would be best for someone who was something of a beginner, and with a rather sketchy idea of what I hoped to be able to do with it. I chose Java because I found some good resources, the Stanford CS106a intro to computer science class, with all video lectures on youtube, free eclipse coding editor/compiler, class handouts, example programs, solutions to all exercises, textbooks in pdf format. And a very well-written textbook too, "The Art and Science of Java" by Eric S. Roberts.
After a few chapters , I decided that I could forget the lectures, and just study from the book. The programming exercises at the end of each chapter are actually more demanding than the assignments actually given in the class anyway, and as entertaining as the professor is, his humorous delivery doesn't always help the relevant programming concepts come through clearly.
But I have had a very eventful year, and mostly because of pressures in my life I've stalled about halfway through the book.
In my reading about learning to program I began to see more advice to novices learning to program and trying to choose a language. And for many reasons I've come to think that python might be better as an introductory language. Some of these reasons are : 1. it is very popular today, and tutorials are offered on it through many educational websites such as Khanacademy and codeacademy. 2. its syntax is simpler, it requires less typing and fewer special concepts to understand before you can begin. Such as, in Java all variables must have their type declared when they are first used, additionally variables, classes, methods and functions all need an explicit privacy setting applied when they are created, this is hard to understand for someone who is already straining to understand what classes, methods, functions and such mean in the first place. 3. Java is a compiled language, and commands from it cannot be tried interactively in isolation at a command prompt. This means that there is always a delay between what you write and the result it produces. It also means that it can be hard to test parts of a program in isolation to see what works and what doesn't. This is kind of a big deal for me, because when I first used a computer, as a child of about 8, in the mid-1980s, I was familiar with the command prompt, and the fact that I could type expressions and get results as soon as they were entered, so programming could be learned by playing. Shortly after the Commodore was stolen from my dad's place in the late 80s, I ceased coming into contact with any computers, which had an interpreter-based operating system. The perception was that you would buy a computer to run programs instead of to write them. That you would buy programs to run on your computer, rather than build your own programs yourself. This view was enforced by computers coming with a DOS operating system, which would let you load programs, copy data, examine directories, but which didn't directly facilitate you writing programs of your own. When, in the early 90s, Windows became popular, my attention shifted from writing programs, to the things that could be done with programs. Playing games, making art, downloading documents and communicating with people. In the windows era, you had much greater potential to use your computer to write articles, do complex calculations with little setup time, play fast, beautiful, immersive games, play music or create stunning graphics. But you had to already have the programs someone else had written, in order to do these things. You used the operating system of the computer to open them, and to switch between them conveniently, but not to create. Not to make the machine do what you wanted. In windows, you can have your math expressions evaluated in the calculator, or in a spreadsheet, but you are shielded from touching the power of computing itself.
Moving from Java to Python is easier than I expected. The difference is much less than between BASIC and Java. Functions and function calls make sense, instructions to import make sense, variables being local to a function make sense. There are similar data types, many keywords are the same between the languages, (and there aren't that many keywords, about 30. more or less, in each language, and most of them are probably common to both, and probably also common to several other computer languages)
In the picture, the program on the left is notepad++ with a python program written in it. In the Stanford Eclipse editor on the right we see hilighted, the same program written in Java. This was an early Java programming exercise from the textbook, "The Art and Science of Java" and I just translated it, into equivalent Python code.
The Python is more compact, and largely because it relies on the indentation which is a strongly suggested style in Java, to do the same job as the opening and closing curly braces which, in Java are mandatory.
Also noticeable are the shorter and simpler lines for method definitions and for loops. and in Java, the boolean test conditions are enclosed within parentheses that Python simply does without. The for loop in Python also has several other goodies, like an index variable, not declared or explicitly initialized, the powerful Python keyword, "in" and the very useful function or method, range()
In spite of my interest in Python, I am not eager to give-up on Java yet. But I can foresee Python as my default language for quick computer experimentation.