/sigh. I will hold back my typical rant about how this is the wrong question to ask.
This is basic flow control. Learn how flow control works for the language you're using.
That's true, but that's not the problem here. The problem is that the question is asking for a specific implementation of a solution, rather than presenting the actual problem.
For example, let's say my air conditioner was broken. Then I go onto a forum for A/C repairmen and I ask "how do I replace the compressor in my air conditioner?" It's like whoah, how do you even know that's what you need to do? Instead, I should say something like "When I turn my air conditioner on, it makes a whirring noise and only warm air comes out." Present your problem and then get a solution. Don't decide on a solution and ask for how to implement it.
Especially with programming, don't hide any information. Show as much as possible. The details are very important.
One thing I don't undervalue is the fact that I went to a university for this sort of thing. Learning the fundamentals of programming and object oriented design doesn't seem so important until you see the code of people who didn't have the same advantage.
One thing I don't undervalue is the fact that I went to a university for this sort of thing. Learning the fundamentals of programming and object oriented design doesn't seem so important until you see the code of people who didn't have the same advantage.
The thing is, I mostly learned from books and doing. And that was without Internets for much of the time.
This is more of a general question but should I declare functions in blocks or just put them in where I need them? For instance, I'm making some generic mathematical operators currently (Find the radius and area of a circle among other things.) and was thinking to stack them all together at the top of the file, maybe moving them off to a separate file so I could keep it in a separate tab.
Also, Thanks Cheese, what you recommended worked out fine.
Also, should I wait until after getting to grips with Python to give Vim a try or would it be worth learning them simultaneously?
Also, should I wait until after getting to grips with Python to give Vim a try or would it be worth learning them simultaneously?
Download gvim. After you open it, press "i" to enter insert mode, now you can type like a normal text editor. Press escape to exit insert mode. Press ":w" to save. Use the GUI to do anything more advanced. Congrats, you just learned VIM.
I'll stick with Eclipse for now. Anyone got any advice on how to order programs, then?
It sounds like you are writing functionally when you should be writing in an object oriented fashion. I suggest looking at the source code of other projects, open source ftw, to see how they are structured. Also, you should read the documentation about how the python path and import system works.
Scott, I'm just trying to get to grips with the basic functions. I'm just wanting to know some stop-gap stuff so I can mess around with the examples and not end up with a mess.
By import, do you mean things like "from functions.py import *" sort of thing?
Urggg.. both chapters 8 and 10 are linux specific. Time to break out the laptop.
Honestly, the C# Oreilly book goes into object oriented design principles pretty deeply, as does the Java one. I'd suggest reading one of them and actually attempting all of the examples. As a decent benchmark, get to the point where stuff like this makes sense.
Read lots of code that isn't yours. Read lots of books and documentation. Write lots of code. Learn the fundamental concepts of programming. Instead of learning Python, learn object orientedness. Also, computers are turtles all the way down to electrons. It helps a lot to understand each turtle on a conceptual level.
If your goal is to just get shit done, then just get it done. The program will work the same whether the code is beautiful or not. It might have problems in the security, reliability, readability, and peformance departments, but it will get the job done. If you actually want to become great at programming, much more hard work is in order.
In terms of how to organize code and write it cleanly, the one thing that helped me the most was this book.
Depends on how motivated you are. C# is a pretty nice language, with no real "pit-falls" that I'm aware of in terms of comprehension. However, it doesn't really matter what language you learn, just focus on one and do stuff with it. I've found that learning something (especially programming) just for the sake of learning it will either leave you unmotivated or provide a poor context to properly grasp the nuances. If you really want to learn programming, think of something out of your current skill set and try to make it. Read on how other people have done it before, understand why they made the decisions they did in terms of language choice, structure, etc. Try to approach difficult problems and learn to solve them on your own.
In my opinion, just going through a book and doing the examples is not my first choice in learning something.
Honestly, the C# Oreilly book goes into object oriented design principles pretty deeply, as does the Java one. I'd suggest reading one of them and actually attempting all of the examples. As a decent benchmark, get to the point where stuff likethismakes sense.
I'll go through the C# book as you and the Monaco guy seemed jazzed about it. For a milestone project, I'd like to make a networked LttP game. Which documentation and projects would I want to be looking at?
If your goal is to just get shit done, then just get it done. The program will work the same whether the code is beautiful or not. It might have problems in the security, reliability, readability, and peformance departments, but it will get the job done.
I find that writing code in a basic way, might not work as brilliantly functional as perfect code, with all of the advanced ways of doing it, but because they do it so rarely the basic code is easier to understand, so I don't need to worry about things like commenting on it.
Don't confuse "advanced" with "object-orientation." The latter is both the "right" and the easiest way of doing anything complex at the level we're talking about here.
If your goal is to just get shit done, then just get it done. The program will work the same whether the code is beautiful or not. It might have problems in the security, reliability, readability, and peformance departments, but it will get the job done.
I find that writing code in a basic way, might not work as brilliantly functional as perfect code, with all of the advanced ways of doing it, but because they do it so rarely the basic code is easier to understand, so I don't need to worry about things like commenting on it.
And that is my excuse anyway.
That's perfectly fine. If you don't want to become a great coder, you don't need to become a great coder. Not everyone who plays guitar has the goal of becoming the next Steve Vai. It's enough that they can read tabs and learn a song with some practice. It's just that with music, anyone can tell if you aren't very good. Bad software is sometimes hard to spot. There's also no real harm that can come from playing music poorly, besides hurting other people's ears. Great harm can come from bad code being used in the wrong circumstances. Imagine if Amazon.com had shitty code, disastrous!
If you just have some projects you want to do, and coding is just a necessary part of that project, like making an art installation involving Arduinos, then don't worry about the code being good or bad. Just make it work however you know how and learn as you go.
If you actually want to become a programmer, for serious, and you want to write important programs, then it's a lot more work. You need to learn how computers work, on all levels, and you need to learn lots of fundamental concepts like algorithms, object orientation, operating systems, networks, databases, security, etc.
It's just that with music, anyone can tell if you aren't very good. Bad software is sometimes hard to spot.
Thankfully no one is ever going to see my code except for the people who see it in this thread. If I post any more, that is.
I did some coding yesterday, and the output HTML is very functional and looks great on my website. Nobody will ever know that I coded it myself, and nobody never use the code again.
Sure, if it's only going to be used once, then it might as well be a Perl script hacked together in a couple of minutes. If you are worried about code re-use, then there's a lot more you need to think about.
instead of showing you my code, I thought I might as well just show you the results of my code. The perfect job for a Python script is to spit out HTML nicely formatted like this.
instead of showing you my code, I thought I might as well just show you the results of my code. The perfect job for a Python script is to spit out HTML nicely formatted like this.
Well, it's mostly a table, so that's not too bad to do it straight up. However, like I said before, if you ever want to spit out HTML from code you should really use a template engine. It makes everything a zillion times easier. If using Python, I highly recommend jinja2. You can see an example of using jinja2 in my Presentoh project on github.
Maybe I'm misunderstanding here, Scott, but I don't want this code to run on my website, dynamically serving HTML each time somebody visits. It is for me to run on my computer, mainly so I can work on stuff off-line, and then just copy the HTML or upload it where needed.
I'm not even sure what the template engine is, and don't have time to search for now. I'll look into it from next project, but I really wanted to get this page up within the time it took me to put my next podcast. And I did. That'll do for now, and I can learn more if needed later.
Maybe I'm misunderstanding here, Scott, but I don't want this code to run on my website, dynamically serving HTML each time somebody visits. It is for me to run on my computer, mainly so I can work on stuff off-line, and then just copy the HTML or upload it where needed.
A template engine can help if you are creating a dynamic site, but it doesn't have to be used in that way. Basically, templating is where you have some template that contains template tags. You load the template and some variables and pass them through the engine. The engine then spits out the template after executing all of the template tags.
Python's string formatting, the stuff we were talking about with %s and such, is a template engine, albeit a very small one with very limited features. jinja2 is a more advanced one that is specifically geared towards HTML, though it can be used for anything. There are multiple template engines available for every language you can imagine. Pick whichever one you like or write your own.
Here are some tiny semi-psuedocode examples to show what I mean.
Without a template engine you do this.
myvars = [1,2,3] print "<tr>" for var in myvars: print "<td>var</td>" print "</tr>"
With a template engine you make two files. One contains the template, the other contains code.
The template looks like this.
<tr> {% for var in myvars %} <td>{{ var }}</td> {% endfor %} </tr>
In this very small example, it doesn't look like the template engine is really saving that much work. But as I'm sure you can imagine, as the complexity of the HTML increases, the template engine becomes indispensable. The major benefit is that it allows you to put the HTML and code in separate files. This is a breath of fresh air after you have been writing HTML that is nested inside of print statements and quotes. It also completely separates the front-end from the back end, which is a must when developer and designers team up. There are numerous other advantages, but I won't list them all. I recommend it highly, even just to print out one HTML file.
Comments
For example, let's say my air conditioner was broken. Then I go onto a forum for A/C repairmen and I ask "how do I replace the compressor in my air conditioner?" It's like whoah, how do you even know that's what you need to do? Instead, I should say something like "When I turn my air conditioner on, it makes a whirring noise and only warm air comes out." Present your problem and then get a solution. Don't decide on a solution and ask for how to implement it.
Especially with programming, don't hide any information. Show as much as possible. The details are very important.
Also, Thanks Cheese, what you recommended worked out fine.
Also, should I wait until after getting to grips with Python to give Vim a try or would it be worth learning them simultaneously?
Also, the only way to learn vim is to just keep using it as your text editor no matter what and never let yourself use anything else.
By import, do you mean things like "from functions.py import *" sort of thing?
Urggg.. both chapters 8 and 10 are linux specific. Time to break out the laptop.
Honestly, the C# Oreilly book goes into object oriented design principles pretty deeply, as does the Java one. I'd suggest reading one of them and actually attempting all of the examples. As a decent benchmark, get to the point where stuff like this makes sense.
If your goal is to just get shit done, then just get it done. The program will work the same whether the code is beautiful or not. It might have problems in the security, reliability, readability, and peformance departments, but it will get the job done. If you actually want to become great at programming, much more hard work is in order.
In terms of how to organize code and write it cleanly, the one thing that helped me the most was this book.
Code Complete: A Practical Handbook of Software Construction
I've actually learned a great deal of what I know from reading a few good programming books cover to cover.
In my opinion, just going through a book and doing the examples is not my first choice in learning something.
And that is my excuse anyway.
If you just have some projects you want to do, and coding is just a necessary part of that project, like making an art installation involving Arduinos, then don't worry about the code being good or bad. Just make it work however you know how and learn as you go.
If you actually want to become a programmer, for serious, and you want to write important programs, then it's a lot more work. You need to learn how computers work, on all levels, and you need to learn lots of fundamental concepts like algorithms, object orientation, operating systems, networks, databases, security, etc.
I did some coding yesterday, and the output HTML is very functional and looks great on my website. Nobody will ever know that I coded it myself, and nobody never use the code again.
If you are worried about code re-use, then there's a lot more you need to think about.
A new page listing every episode of the science fiction book review podcast with all rating, links to Amazon.com, links to Wikipedia, links to goodreads.com, etc.
https://github.com/Apreche/Presentoh
I'm not even sure what the template engine is, and don't have time to search for now. I'll look into it from next project, but I really wanted to get this page up within the time it took me to put my next podcast. And I did. That'll do for now, and I can learn more if needed later.
Python's string formatting, the stuff we were talking about with %s and such, is a template engine, albeit a very small one with very limited features. jinja2 is a more advanced one that is specifically geared towards HTML, though it can be used for anything. There are multiple template engines available for every language you can imagine. Pick whichever one you like or write your own.
Here are some tiny semi-psuedocode examples to show what I mean.
Without a template engine you do this. With a template engine you make two files. One contains the template, the other contains code.
The template looks like this. The code looks like this In this very small example, it doesn't look like the template engine is really saving that much work. But as I'm sure you can imagine, as the complexity of the HTML increases, the template engine becomes indispensable. The major benefit is that it allows you to put the HTML and code in separate files. This is a breath of fresh air after you have been writing HTML that is nested inside of print statements and quotes. It also completely separates the front-end from the back end, which is a must when developer and designers team up. There are numerous other advantages, but I won't list them all. I recommend it highly, even just to print out one HTML file.