Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Sunday, January 24, 2010

Python is amazing

If you are just starting out with web design, have HTML, CSS, JavaScript and basic uploading/hosting stuff down you want to take the next step and venture into server side scripting. This allows you do do simple things, like create an email form, or complex things, like build a whole forum. You can connect databases, create files on your sever on the fly, create your own tracking code...lots of things.

Now, the current convention is to go with PHP, and really, PHP is easy. It is actually easier to learn PHP than what it is to really learn CSS and JavaScript. And it can do cool things. Just check out this amazing tutorial at Tuxradar - http://www.tuxradar.com/practicalphp. If all you want to do is simple scripts, it is going to work just fine for you.

But what if you want a little more power. You want to pull your blogger posts in to your website, show the weather, create a custom Twitter api. You can do many of those things with PHP. No problem. Often each peace of the puzzel is easy. So why am I raving about Python.

Well, first of all, Python goes beyond the web. It is a scripting language, or a 'high level' language, but that doesn't mean it doesn't have some Vooma! It can build great GUI apps, small database scripts are so easy with Sqlite3. There is so much you can do with it. And you can talk to the web with it. You can download sites, pull them apart and re-build them.

But, you say, look at the popuarity of PHP. It is huge on the web. Well, sure. It is. But I bet some of the time it is underestimated how big Python is. You don't often see Python programmers having a website with a .py ending...mainly because of the whole way that Python programmers think. Python has clean syntax and Python programmers want a clean URL as well.

But, the main reason is that it is rather easy to build small PHP script. Really easy. It must be the easiest server side scripting language to do things with.

My argument, then, for using Python more is actually not so much about writing the code in the first place. That's complex. You have to really cover a lot of documentation to figure out how to use Python with your website. With PHP, it tells you how on the very first page of most tutorials.

No, the reason I love to work with Python is that most work I have done is done in bits and peaces. I have some time, start a nice big project, then put it aside when I go on tour or do some work for others. When you come back to your PHP, trying to wade through the code is tough. It thought me the importance of comments. Python loves comments. Mmmm, good Python.

When you leave a peace of code, once it gets a little involved, it is always a challenge to come back and jump into it again. But one of Guido's key insights in his design of the language was the code was read far more times than it was written. So make it easy to read. And he did exactly that.
Ref 

If you are thinking of trying to write a blog, or even better, have a few blogs of your own and want to pull them together, add login scripts, add Twitter, weather and what not, I am sure you will find Python is easier to maintain in the long run. One main feature that makes it better than PHP is namespaces, as is stated in the last line of PEP 20:


The Zen of Python,
    by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Thursday, October 8, 2009

Auto Update Your WebsiteS Copyright Notice Each Year With PHP

If you are like me the years do sometimes just slip by. Visit family you don't see often and you know what I am talking about...the little toddlers and teenagers, that kind of stuff.

But this isn't about philosophy or self help. We have a much easier problem to fix. The dates on your copyright at the bottom of your page.

All it is going to take is just a super simple little script, but in my opinion it is useful and makes a real difference in how professional a website appears to be.

I am sure you see it often. Small business or personal home pages, very often, but sometimes you even find the website of quiet large companies with outdated copyright notices. - Example 1 - and - Example 2 -

Okay, if you have php installed on your server, this is going to be ridiculously easy, but so useful down the line. I will just cover this in a quick manner:

First off, whatever your html page, you need to save the page as a .php page instead of html. If you have links to the page already, make sure that you update them to .php instead of .html or .htm.

Changing that does nothing else to your page as it is already, it just means that you can now embed the php scripts into the page.

Okay, here is the script -

<?php

$thisYr = date("Y");
if ($thisYr > 2009){
print "<br/>copyright &copy; 2009-" . $thisYr;
}
else {print "<br/>copyright &copy; 2009";}

?>

You can simply copy andpaste this into your page where you need it, but I will explain it below:

1. the <?php opens the php code and the ?> closes it. Whatever you write in there is php script.
2. We get the year from the date() function, and by putting the capital 'Y' all we get is the year. So that assigns the current year to the variable called $thisYr. Note that capitalization is important and shouldn't be changed, otherwise you will have trouble with the script.
3. The 'if {} else {}' code blocks are easy to understand. If it is this year, print the one thing, if it isn't print the other. You can change the date to whatever your beginning year is for the copyright.
4. The '&copy;' bit is written like this, but the html page will render it like this '©' It is just the unicode symbols for the little copyright icon.

And that's basically it. You can extend it a little by putting hypertext to the copyright to a link that defines your copyright terms, such as, perhaps, a use and share and backlink or something like that.

If you are creative enough, you may think of other uses for such a simple script. It is one of the wonderful things about these types of scripting languages...small bits of code do really cool things.

Tuesday, September 22, 2009

Beginner Comprehensive Web Authoring Tutorial 1 An Introduction

Welcome to the Non Nerd Free Comprehensive Web Authoring Tutorial.

If you are a total beginner to the whole idea of designing a website, but would love to try it, and maybe learn it properly, then this blog is for you. I am going to take you incrementally through, step by step, from knowing nothing to deploying very clever websites on the Internet.

I will not try to pretend that I provide the best tutorial. There are many many web authoring tutorials out there. As we go along I will give lots of links so you know where I may have learned my stuff from, and so that you can choose where you want to learn. You may find that I teach one aspect better than another, and so choose to learn other things from those who teach them best...great. But this blog will depend on readership. If after a while I see that there is no real traffic, and no comments, I will can the project and assume that you found better tutorials elsewhere.

Now, what do I want to teach you. Well, if we carry on with this long enough, EVERYTHING. Let me summarize my goals:

1. Teach you what a website is, what HTML is and teach you the basic syntax of HTML. This bit is fun and easy. I will be focusing on development on HTML 5 the soon to be released version of HTML.
2. CSS - The styling of your web pages.
3. Basic JavaScript - Breath a little life into your otherwise dull pages.
4. A little about servers and uploading websites...Get what you have done so far out there.
5. More advanced JavaScript and an intro to Ajax.
6. Blogging with online content management systems, and customizing them...we'll start with blogger.
7. Move on to more complex things...PHP, Databases and on and on. At this point you will need to download a server to your computer...don't worry, it's not that scary.
8. SEO and usability...here will be preaching and stern words.
9. Perhaps, later on, we may also start with Flash.
10. We'll move into more detail on servers...now only with Apache.
11. Freelance Web Design and making a living from doing websites.
12. If we are still together, then it will be Python next,
13. And Java (which is not JavaScript.)
13. Well, it all depends on what's happening with this blog, what's happening with the world wide web, and if I am still interested, finding the time and so on.

What am I not going to teach you? Things like Dreamweaver or Frontpage. I want you to cut the code by yourself...especially in the beginning. I think you will thank me later.

What are the characteristics of my tutorials...I teach in a very simple manner...almost like I teach my kids. I love teaching and it has been a big part of how I guide.

I have been, and I am still, teaching myself these things. I am not an expert, but I do LOVE to learn and I LOVE to teach. Come along for the ride...it's going to be fun. Please leave comments, ask questions, correct me when I am wrong, and lets get to know each other through this experience.

This site will live

I have just had a look at Google Analytics for this site, and in the last month this site has had 127 unique visitors. I have not links to this site anywhere, it isn't linked in my blogger profile, I haven't done anything to promote it. And yet they come.

So, I guess, I am going to start off producing some posts on this blog.

So please dear random visitor, tell me what do you want me to post about. I think at this point I could do posts on the following, all at really beginner level:

1. Full web authoring tutorial for the beginner ...from nothing to getting your page up on the internet
2. Just html (to easy, I think)
3. Html and css
4. Intro to Javascript
5. Intro to php
6. Blogging general
7. Blogging promotion
8. Blogger specific tips and tricks

Leave comments, take my survey or even send me an email (frantic.naturalist @ gmail.com)