Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

Friday, January 17, 2014

Taking A Different Approach To JavaScript

I enjoyed my Codecademy experience in learning JavaScript, but especially toward the end, I felt like I was having to look up things constantly. I posted a query on their forums and got a very nice response back from one of the mods explaining that this was perfectly normal. He suggested retaking the course to help cement the new concepts and haunting the Q & A forums for more info. In the meantime, I found something else.

Interestingly enough, I found out in one of the Codecademy Q & A's about a site called JavaScript.is (Sexy). It sounds like a silly name, but I think it's actually going to be the solution to my situation. They have an eight week tutorial that I just began titled How to Learn JavaScript Properly.

There's a textbook involved, and they recommend a related reddit study group, signing up for Stack Overflow and, interestingly enough, using Codecademy for practice.

You can click the link I provided to see all of the requirements for the class, but I like the organization and structure involved. It also provides me with the format for repeating the Codecademy JavaScript course as well as adding more content via the other class elements.

Since this is a work requirement, I need to stick with it and I guess that's the secret, especially for people like me who aren't "natural" programmers. I write in English everyday for a variety of purposes, professional, semi-professional, and personal, so I have plenty of practice in that arena. If I did the same with JavaScript, even though I find it less intuitive than my native written and spoken language, I can only imagine that coding in JavaScript will get a little bit easier.

I haven't forgotten HTML5 and CSS3, but I'm not sure combining that with JavaScript in the same learning effort is going to be effective. I may need a different plan for that learning path. Right now, in addition to my professional and personal life, I'm focusing on this plan.

Wish me luck.

I'll be back at some point to let you know how things are panning out.

Wednesday, December 4, 2013

Finished Codecademy's Web Fundamentals Tutorial, but...

I finished Codecademy's Web Fundamentals tutorials They lessons are broken down into the following sections:

  1. Introduction to HTML
    1. HTML Basics
    2. Build Your Own Webpage
  2. HTML Structure: Using Lists
    1. HTML Basics II
    2. Social Networking Profile
  3. HTML Structure: Tables, Divs, and Spans
    1. HTML Basics III
    2. Clickable Photo Page
  4. Introduction to CSS
    1. CSS: An Overview
    2. Design a Button for Your Website
  5. CSS Classes and IDs
    1. CSS Selectors
    2. Sorting Your Friends
  6. CSS Element Positioning
    1. CSS Positioning
    2. Build a Resume

Before my tutorial "hiatus" some months ago, I had stopped right after "Clickable Photo Page" and before "Introduction to CSS". A perfect place for me, actually. I did the CSS section in two days and felt pretty confident until I got into "CSS Positioning." Even though I solved all the problems (there's a lot of help) and successfully completed the tutorial (earning various "badges" along the way), when I built my Resume as the last task in the CSS section, it looked awful. Technically, the code was all correct, but the header stacked over the left and right divs and I could never figure out how to correctly style the text in the footer.

I certainly give props to the folks at Codecademy for how well this tutorial flowed. I've gotten farther in understanding CSS than half a dozen books and various websites have taken me. But when I was prompted to take the JavaScript tutorial next, I knew I was hardly ready. There's a lot more to web design than what I learned in this set of lesson. Got "intermediate web design," folks?

Sunday, December 25, 2011

Book Review: Sams Teach Yourself TCP/IP in 24 Hours (5th Edition)

Author: Joe Casad
Format: Paperback, 544 pages
Publisher: Sams; 5th edition (November 4, 2011)
ISBN-10: 0672335719
ISBN-13: 978-067233571

I've been spending a lot of time with TCP/IP and particularly IPv6 in the past few months (I can't tell you why right now, but soon). When I saw Joe Casad's book Sams Teach Yourself TCP/IP in 24 Hours was in its fifth edition, I wondered how it compared to my experiences in researching various aspects of internetworking. One way to find out for sure is to request a review copy from the publisher, so here I am and here it is.

I'm a big fan of the "Sams Teach Yourself" books. I've had good experiences with them in the past and they usually offer just the right amount of learning, broken up into correctly sized bites. They also usually build one "hour" upon another so that by the end of the book, you really have learned something. There is no "who is this book for" section in the front matter, but this series is typically tailored for the beginner. How much of a beginner do you have to be? The first hour is called "What Is TCP/IP?". The first questions asked are, "What is a protocol?" and "What is a network?". Pretty basic stuff.

This series is designed, as I'm sure you guessed, to be a learning series. After the chapter's main content, there's a Q & A section and a Workshop section which is made up of a brief quiz (4 or 5 questions) and a short series of exercises. Appendix A in the back has all the answers, so you can check your work or have a peek if you really get stuck. Just for giggles, I went through the Workshop section of Chapter 14: TCP/Utilities and it seems like it's pretty standard material, if you know much about networking. Questions have to do with what commands you would use to view a computer's ARP cache or to see which hosts have made TCP connections to your computer (this all assumes a Windows PC) and exercises focused on ipconfig and ping. Not super challenging, but if the goal is to teach a networking newbie, this is at the right level.

I guess I shouldn't have been surprised that only one "hour" was dedicated to IPv6 (Hour 13) or that there were Exercises assigned to this chapter, but no answers for them in the Appendix. There are two good reasons for this. One is that a newbie will have their hands full with IPv4 and the other is that most folks still consider IPv6 really new (the "newness" is an illusion as IPv6 standards have been developing for years and many ISPs have accelerating their adoption of the next version of IP recently). The downside to this "neglect" in the book is that newbies are the perfect audience to learn IPv6 from scratch, at least at the level of concept. If you've got a couple of Windows 7 computers, you can ping their IPv6 addresses or ping your own localhost address (ping ::1).

On the up side, this TCP/IP book covers a lot more than TCP/IP at the level of the protocol including DNS, Routing, SOAP, Email, and "the Cloud". That sounds impressive and from the neophyte's perspective it is. However, because the book is addressed to the beginner, that's about as deep as you go into any of these topics. To be fair, that's a deep as this book should go, but that also means if you have any networking experience at all and you don't need a ground-level review, this book will be too light for you.

If you are a person who wants to learn basic networking (not particularly for how to set up two or three computers for wired/wifi in your home) with an eye on something a little more advanced like CompTIA's Network+ and a little later on Cisco's CCNA, then Casad's book will certainly give you a leg up. If that's where you are or where you want to go, I'd recommend Sams Teach Yourself TCP/IP in 24 Hours. If you have some experience and are looking for a book with more "meat" to it, you'll need to look elsewhere.

Addendum, 12-26-2011: Regarding IPv6 deployment, I just found this article at InfoWorld: IPv6 due for wide deployment in 2012, experts say

Tuesday, September 6, 2011

Book Review: Learning Perl, Sixth Edition

Paperback: 390 pages
Publisher: O'Reilly Media; Sixth Edition edition (July 1, 2011)
ISBN-10: 1449303587
ISBN-13: 978-1449303587

It's been around awhile...the Learning Perl book I mean. Now in its sixth edition, this O'Reilly classic is still going strong. But first things first.

Who is this book for? You don't find out until the first page of Chapter 1, but it's called "Introduction", so I guess that's OK. Is this book for you? Depends. According to page 1, "This is not a reference book. It's a tutorial on the very basics of Perl, which is just enough for you to create simple programs mostly for your own use." In other words, you'll learn Perl but not much more. The reader is presumed to know some programming and is someone who specifically needs to learn Perl. Beyond the basics, don't expect much out of Learning Perl, but that's not a fault of the book. That's its nature. Anything else you need to know, you'll have to get somewhere else. That said, you start learning Perl here.

Why a Sixth edition? That's easy to find in the front matter of the book. The changes are all laid out in the "Changes from the Previous Edition" section. The book's been updated for Perl 5.14, but that's on the cover. Keep in mind that some of the book's sample code will only work with 5.14, so if something seems "broken", check the version of Perl you're using (this section in the book tells you how to do that). Not all of the sample code requires the latest version of Perl, though. A lot of it will work with older versions.

I loved the line in the Preface that said, "We can't give you all of Perl in just a few hours. The books that promise that are probably fibbing a bit." That's the reality of learning how to program in Perl or any other language. I love the honesty. Like Edna says, "I covered the basics." (If you don't know who I'm quoting, turn in your geek badge now).

Now that you know who this book was written for and what it won't teach you, what will it do for you? If you're at all familiar with the prior version, you can expect this book to maintain the same level of excellence as edition five. About the only complaint about that book was that it was too basic, but I've explained that already. The sixth edition is an update on a time-honored Perl book that is designed to just open the door to programming in Perl.

Each chapter provides the conceptual information for the topic at hand and ends with a set of exercises allowing the reader to practice what they've learned. The book doesn't leverage each chapter to allow the reader to build a larger project as they progress through the book. That's often the frustration when I go through beginners books, because I want the programming to actually do something. If you get that feeling, remind yourself about the book's caveat and then keep going.

If you are an experienced coder, this book might seem a little elementary for you, even if you don't know Perl, so there may some parts you'll skim through, but if you need a ground level foundation, Learning Perl is the place to come.

Not much more to say. What you see is what you get. If you want to learn Perl and already know a little about programming, buy this book. It's a good investment in your precious time and your hard earned dollars.

Wednesday, August 31, 2011

Learn to Program Online at Codecademy.com

My friend Judah Himango suggested that I look at the Codecademy.com site. It's just about the easiest way to learn JavaScript anyone could imagine, and it's relatively fun, too. There is a bit of a hook involved. Although you can start the lessons without creating an account, after a few lessons, you are offered the opportunity to either create an account (it's free) or lose your work to date. I created an account.

Once I did, I could continue with the lessons, quit with I got tired/bored (my work was saved automatically), and then sign in later to continue with my saved work. On signing in, you are shown a summary of the lessons you've completed and which ones you have yet to start. After you successfully finish so many lessons, you "earn" achievement badges. For making it through the first four of eight lessons, I earned two achievements.

The lessons are fun, easy, but inflexible. If you deviate from the lesson in the slightest way, you will get an error message. While a hint is provided with different steps in each lesson, if you get stuck, you don't get any other help except to offer feedback about the lesson. There's no way to just get the full solution presented to you. That's good on the one hand, because you aren't tempted to give up too easily and it "forces" you to try and figure out what went wrong. On the other hand, it you truly get stuck...you're stuck. Lessons build on one another (which is a good idea) so if you can't figure one part of a lesson out, you won't be able to just skip it and move on.

The scope of the course, "Getting Started with Programming", only spans eight lessons, ending after the lesson on "while loops". There's no obvious way for me to tell after lesson eight if I'll be able to continue with what I've started to learn. I clicked the "Courses" link in the header menu expecting to see extended (possibly for pay) courses, but all that appeared was the eight lessons for the basic course.

Once you log out, you're returned to the start page. The other options on that page include subscribing to an email newsletter, and sharing your experience with your lessons on twitter and Facebook. Presumably, this is part of how Codecademy plans to market itself. Oh, there is a section called "Create a Lesson", so the Codecademy folks are interested in external participation in expanding their project.

Codecademy seems like it's a project in the making. Since they harvest your email address, both as a condition of creating an account, and during the pre-account lesson when you're asked to enter your email address, I expect that once Codecademy has a sufficient database of names, they'll advance to the next phase of whatever their plan happens to be. That could either mean further lessons will be for a fee or they may continue to offer more advanced lessons without charging.

I'm hardly the first blogger to post a review. About two weeks ago, TechCrunch published their write up on Codecademy, including a talking to Codecademy co-founders Zach Sims and Ryan Bubinski. Sims commented several times on the TechCrunch blog including, "Hi everyone - we might be a little slow right now but we're working on getting things faster. Thanks so much!"

Other thoughts: The "subtitle" of the course "Getting Started with Programming" is "Time to become a coding ninja". That sounds as if Codecademy's intent is to encourage its students to become proficient and even expert at coding. Three things will have to happen. The first one is obvious. They'll need more lessons. A lot more lessons.

The next two points I take from my own experience. You can't really learn something unless you do it all the time. People don't learn to read and write when they do it only occasionally. They need to practice reading and writing all of the time until it becomes second nature. Even if you teach someone the basics of programming, if they don't have any way to apply it on a frequent basis, they'll lose those skills again. Building in some form of continual practice with periodic refreshers of material covered previously will help.

Finally, students will eventually have to learn to "build" something practical. Learning how to determine the length of a string is fine and dandy, but so what? How does that figure into writing a program that actually does something? Lessons will eventually have to lead to practical projects so that at some point, the students will be able to program independently.

Of course, the real power in any programming language is its libraries, so learning JavaScript will have to turn into something like learning jQuery. Another things to consider is whether or not JavaScript will be the only programming language Codecademy chooses to teach. A lot can be done with JavaScript but hardly everything. A server-side language such as PHP might make a good addition. Beyond that, it just depends on what sort of long-term goals Codecademy has for its project.

Presently, although Codecademy has gotten a lot more attention than they expected in the short amount of time they've been online, I'm sure they'd love more. If you know little or nothing about programming but would like to learn in an interactive environment, go to Codecademy.com and try it out.

Friday, August 12, 2011

Cloning a Hard Drive with Acronis True Image Home 2011

I bought a Windows 7 Professional 64-bit PC from Dell about a year and a half ago and made the mistake of choosing an OS drive with insufficient room. Needless to say, 18+ months later, it was filling up fast. Even storing all of my data and VMs on a separate (and much larger) drive didn't really help. Fortunately, the folks I work for in my day job had decommissioned a lot of hardware and computer parts and I was able to get my hands on a fairly good sized SATA HDD. Now all I had to do was figure out how to transfer Windows 7 from one SATA drive to another.

After doing a bit of research, including asking the fine folks at Certforums.co.uk for advice (one of the finest technical certification discussion forums on the planet), I chose Acronis True Image Home 2011 for the job. I had initially settled on Acronis' Migrate Easy product, since I didn't need all of the features offered by True Image, but True Image was $10 cheaper and I'm all about getting a bargain.

After stopping by my local computer parts and repair store to pick up a SATA data cable, I was ready to install the new drive and get to work. I reviewed both the online documentation and the User Guide. I felt I was ready to proceed. The process seemed quite simple and I anticipated the whole thing being done in an hour or two at most.

Boy was I wrong.

Setting Up the Hard Drive

After installing the drive, my PC didn't "realize" it was there (my bad), so I went into the BIOS and set the SATA channel the drive was using to Active. After booting into Windows, I used the native Windows Disk Management utility to set the drive to a simple NTFS volume. The computer could now "see" the new drive, so I was all set.

Downloading and Installing True Image

I downloaded and installed a fully licensed version of True Image to my computer. This part was flawless and went just as anticipated. Nothing more to see here. Move along. Move along.

My First Attempt

I opened True Image and, following the instructions, opened Tools and Utilities and then clicked on Clone Disk. The Clone Disk Wizard was easy enough to follow. I went with an Automatic clone mode, selected my source disk, my destination disk, and then started the cloning process. A notice balloon came up to confirm this, but a few seconds later, a second balloon said that I had to reboot or the cloning would abort in 10 minutes.

Like a good little drone, I rebooted my computer.

Nothing.

I logged back in and still nothing. Task Manager confirmed that the application and its processes were not running. I repeated my original steps after checking the directions again and got the same result. I chose the Manual process which let me choose the "move method" (Proportional was recommended since the original disk contents are distributed across the entire, larger space of the new disk). I then started the cloning process and unfortunately, got the same results.

Needless to say, I was getting frustrated at this point.

I went to the Support area of the Acronis website and searched their discussion forum (it was getting late and I doubted anyone would be around at their help desk for live chat). I found the thread Clone Disk Utility Doesn't Work which had only been started a few weeks ago so it seemed to be a good fit for my problem.

The general consensus in the thread was that I should boot the computer from the Acronis recovery disc rather than the OS, and then perform the disk cloning from there. Please note that this was not mentioned in the User Guide PDF but was mentioned in the online instructions. I went back into Tools and Utilities to perform this action but here, I realized that my computer's DVD drive wasn't a burner. In fact, of all the drives on my PC, including removable drives that have since been removed, my DVD drive was the only one the Acronis disc making software didn't see.

The advice I got from the Acronis discussion thread was to download the ISO file and make a disc from that. Fortunately, I had access to a PC at work where I could easily (I love Linux) burn the ISO to disc. I figured I was ready to do this right.

My Second Attempt

With recovery disc in hand, I got home after work. I changed the computer's BIOS boot settings to look at the DVD drive first, then booted from the disc I'd made that morning. The mouse becomes disabled when booting from the disc. There are some instructions that appear telling you how to use various key combinations in order to control the mouse using the numbers keypad. Unfortunately, they go by so fast that, by the time I could read them and attempt to follow the instructions, the computer booted into Windows.

I rebooted with the disc again. Using my arrow keys, I could choose three options: Boot into Windows (the default), boot into the True Image Main Page, or boot into Acronis True Image Report. I tried the Main Page and after receiving a message saying Acronis was loading, a stream of different paths scrolled across my otherwise black screen ending with a blinking cursor. After the line Using /lib/modules/nfs.ko , the computer simply hung with the cursor flashing at me, and leaving me hanging out to dry.

As I'm writing this blog, I found a separate Acronis forum thread that explains this error. The thread content also reminds me that the recovery disc should have had an option for True Image (Safe Mode) which was missing from the menu of options available to me when I used the recovery disc. This behavior was not reassuring.

I repeated the steps of booting with the disc using the True Image option and arrived at the same result. Just for giggles, I booted using the Acronis Report option, but nothing changed. At this point, I was nursing an increasingly dim view of Acronis, their software, and their dodgy documentation. Absolutely nothing is working out as Acronis has described.

I booted back into Windows to consider my options. Going back into the True Image menu in Windows, under Tools and Utilities, I saw an option to add a hard disk. Figuring I had nothing to lose, I "added" the new SATA disk to the computer. That part seemed to go fine and took just a few seconds. Then, just for the heck of it, I tried the cloning process again, duplicating the steps in the wizard that I took before, and using the manual option.

The notification appeared saying that the cloning process had started but then something different happened. A notice appeared telling me to reboot or the process would abort in 10 minutes, but it was a completely different balloon format, appearing in a different place on my screen. I thought this was oddly hopeful and I rebooted, removing the recovery disc before doing so.

Instead of the OS loading, a text-only screen appeared and information flashed by faster than I could read but stopping at "Operation 4 of 5: Copying Partition". Acronis was finally cloning the OS volume from the old to new disk and the information on the screen confirmed the disk types and sizes were correct. Two progress bars were slowly advancing (current progress and total progress). I sipped a glass of water and waited.

The User Guide for this product described the cloning process taking place entirely in the GUI, not in a text environment. The online help completely omits what happens after following the wizard instructions, so I had no idea if this was expected behavior or not. All I could tell was that the cloning seemed to be working.

Once the process was completed, I was prompted to shutdown the computer by pressing "any key".

Once the PC was powered down, I opened it up, removed the original OS hard drive and replaced it with the larger cloned drive. I booted the computer, got back into the BIOS, removed the option for the computer to recognize a third SATA drive on the channel I'd originally selected for the new drive, and then made sure the new hard drive would be the first boot order option.

Then I rebooted and Windows 7 came up beautifully.

After the OS and my desktop loaded, I checked in "Computer" and the OS drive was indeed the new one with plenty of room (the computer wouldn't have booted if it wasn't, but I wanted the satisfaction of seeing for myself).

Conclusion

I must say it worked, which is about the only positive I can write about Acronis at the moment.

While the discussion forum recommended performing the cloning process by booting from the recovery disc, this is absolutely not mentioned in their User Guide for the True Image product. There is also quite a bit of information that is assumed, including the fact that the user has to know to add the disk in the BIOS after installing it physically, and then how to format it in Windows.

After all of my failures, the "turning point" for me, was using True Image to add the SATA HDD. After I did that, the cloning finally worked. Neither the online nor hard copy documents mention adding the disk using the True Image tool at all. If, adding the disk using True Image is a required step, it should have been mentioned in the documentation. I ended up going through that step out of desperation.

My recommendation to Acronis would be to update their documentation to more accurately describe how their product works, including any caveats. It's either hopelessly out-of-date (sadly, documentation continues to be the left-handed, red-headed step-child of software companies), or it's just plain wrong. I write technical documentation for a living and the Disk Cloning section of the True Image User Guide could have been a lot better. If booting from the recovery disc is required, say so. If adding the new disk using True Image before trying to clone another disk to it is required, say so.

Please.

A process that should have taken an hour or two, took me two days. I don't have that kind of time to waste.

If Acronis wants some assistance writing help documentation, they can either hire me or they can find who wrote this tutorial for ComputerShopper.com, which does a fine job of explaining what really should happen, step-by-step (and alas, I found it after the fact), minus the apparent necessity of adding the disk using True Image.

Cheers.

Wednesday, December 9, 2009

What do Interpreted Programming Languages have in Common? Part II

I begin this tutorial a few weeks ago with Part I and received some very nice comments correcting my (fortunately) minor errors. This isn't a tutorial about how to program in a specific language or even really about how to program. I wanted to show the common structure of interpreted programming languages in the hopes of revealing some common threads, rather than focusing on the ins and outs of one language. I've heard it said that if you learn one langauge, it makes learning the next one easier. My problem is I get lost in the nuances of the language in question and lose track of the basic structure of programming. I've created this tutorial series to try and correct that. This tutorial is for my education as much as anyone else's so I welcome comments but, as I said before, be polite. This is about learning.

Speaking of Languages, code examples are presented in JavaScript, Python, and Ruby. I figured this represented a healthy cross-section of commonly used interpreted languages. Now, on with the show.

Controlling Program Flow, Part I

In our last episode (sorry, couldn't resist), we left off with Arrays and Booleans. The tutorial picks up with methods of flow control. According to Wikipedia, flow control is "a statement whose execution results in a choice being made as to which of two or more paths should be followed. For non-strict functional languages, functions and language constructs exist to achieve the same result, but they are not necessarily called control flow statements." In other words, it's a way of making decisions within the program given different conditions. Speaking of which:

Conditions: These statements in a program act as a decision tree or like a set of intersections in a city. The decisions or route are dependent on what conditions are or are not true (speaking of Booleans) or where you're trying to go. The basic structure of a conditional statement looks something like this:

if (condition)
{
     conditional code;
}

That's a very general example, of course, but it gives you a place to start.

if statements:
If statements are more or less the same in all three of the languages we've been working with:

JavaScript Sample Code:

var value = 0;
if (value > 0)
{
     alert("Greater than zero");
}
Python Sample Code:

n = 0
if n > 0:
     print ("Greater than zero")
Ruby Sample Code:
n = 0
if n > 0
     return "Greater than zero"
end
Of course, that's not much of a decision tree. Each program has different conditional statements that are similar but not exactly the same, to deal with a decision that is either this or that:

if-else statements:
The following examples are equivalent and look almost the same, but not quite:

JavaScript Example Code:
var name = "Jim";
if (name == "Jim")
{
     alert("Your name is Jim.");
}
else {
     alert("You are not Jim.");
}
Python Example Code:
name = "Jim"
if (name == "Jim"):
     print ("Your name is Jim")
else:
     print ("Your name is not Jim")
Ruby Example Code:
name = "Jim"
if name == "Jim"
     print "Your name is Jim"
else
     print "Your name is not Jim"
end
That takes care of "the fork in the road", so to speak, but what if there's more than one decision to make? It can't be just "Jim" or "no Jim" all the time. What about Jim, Bill, and Heather, for example?

else-if statements:
Depending on the program, this statement is called else-if, or elif, or elsif, but you get the idea.

JavaScript Code Example:
if (name == "Jim")
{
     alert ("Good Morning, Jim.");
}
else if (name == "Bill");
{
     alert ("Good Morning, Bill.");
}
else if (name == "Heather");
{
     alert ("Good Morning, Heather.");
}
else
{
     alert ("You're not on the list.");
}
Python Example Code:

if (name == "Jim"):
     print ("Good Morning, Jim.")
elif (name == "Bill"):
     print ("Good Morning, Bill.")
elif (name == "Heather"):
     print ("Good Morning, Heather.")
else:
     print ("You're not on the list.")
Ruby Example Code:
if name == "Jim"
     return ("Your name is Jim.")
elsif name == "Bill
     return ("Your name is Bill.")
elsif name == "Heather"
     return ("Your name is Heather.")
else
     return ("You're not on the list.")
end
print name
As you can see, there really isn't much difference between now each language expresses conditional statements. The details are quite minor and I hope this all illustrates the common factors in such statements, which is the important piece to learn in this lesson.


Time limitations are forcing me to make Part II shorter than I originally intended, but at least I've got it up and on the blog. Pick through everything and see if I left any holes. If so, let me know. If not, then all is good, at least for Part II. See you next time for Part III: Loops.


Share/Bookmark

Sunday, October 11, 2009

Python: Converting from one temperature scale to another is easy, but what about eight?

In just about any class or set of tutorials involving beginning programming, there's usually a problem or set of problems having to do with converting temperatures. Just about everyone has had to write a wee bit of code to convert Fahrenheit to Celsius or vice versa. That's not much of a chore. However, there are eight major temperature scales available (though some are around now only for their historical value), according to wikipedia. What if you had to write a program that let a user convert a temperature from any of these scales to any of these scales?

Do you have any idea how many if statements you'd have to write? On the previously referenced wikipedia page, there are eight tables (one for each temperature scale) so converting from any of scales to any of scales would, in theory, require 8 times 7 or 56 if statements (it wouldn't be 8 times 8 because you wouldn't convert from a scale to itself). That's an awful lot of coding and there's got to be an easier way.

Actually, there's more than one way to make it easier, but this is a tutorial that is, or should be, within the grasp of a relative newbie to Python. I took a stab at it and came up with what I think is a pretty straightforward bit of programming that doesn't require a lot of typing.

Oh. I forgot. There is a specific requirement for the solution to the problem. The code must convert from the source scale temp to central or canonical scale, such as Celsius, and then must convert that value from Celsius (for example) to the target scale temp. Here's what I came up with. I don't claim this is the best possible solution, but I don't think there's anything fundamentally wrong with it, either (I checked with a higher power to be sure). See what you think. Here it is:

t = float(raw_input("Please enter the temp: "))
source = raw_input("Please enter the source temp scale: ")
target = raw_input("Please enter the target temp scale: ")

if t < 1000000.0:
    if source == "k":
        cel = t -273.15
    elif source == "c":
        cel = t
    elif source == "f":
        cel = (t - 32) * 5.0 / 9.0
    elif source == "r":
        cel = (t - 491.67) * 5.0 / 9.0
    elif source == "d":
        cel = 100.0 - t * 2.0 / 3.0
    elif source == "n":
        cel = t * 100.0 / 33.0
    elif source == "re":
        cel = t * 5.0 / 4.0
    elif source == "ro":
        cel = (t - 7.5) * 40.0 / 21.0
    if target == "k":
        answer = cel + 273.15
    elif target == "c":
        answer = cel
    elif target == "f":
        answer = cel * 9.0 / 5.0 + 32.0
    elif target == "r":
        answer = (cel + 273.15) * 9.0 / 5.0
    elif target == "d":
        answer = (100.0 - cel) * 3.0 / 2.0
    elif target == "n":
        answer = cel *  33.0 / 100.0
    elif target == "re":
        answer = cel * 4.0 / 5.0
    elif target == "ro":
        answer = cel * 21.0 / 40.0 + 7.5

print answer
I found all of the formulas for conversions at wikipedia, too. You can copy this code into a text editor and save it as something like covert.py, then run it to see how it works for you. Share/Bookmark

Monday, October 5, 2009

Python: input, raw_input, and inadvertently treating integers as strings

This is a "newbie" mistake, but these little details do tend to get in the way, which is why I'm posting my wee Python tutorial. If you know Python or programming, even reasonably well, this will probably seem way too simple to you. Just giving you a "heads up" so you don't waste your time.

I encountered a lesson that teaches storing conditionals using booleans. The code was presented like this:

young = age < 45 

slim = bmi < 22.0 
if young and slim: 
risk = "low" 
elif young and not slim: 
risk = "medium" 
elif not young and slim: 
risk = "medium" 
elif not young and not slim: 
risk = "high"
Of course, you can't really run this. If you try, you get this:
Traceback (most recent call last): 
File "assign_bool.py", line 1, in  
young = age < 45 
NameError: name 'age' is not defined 
I figured the solution was to modify the program to let me input the age and bmi, then print the results. I modified the code like this:
age = raw_input("Please enter your age: ")
bmi = raw_input("Please enter your bmi: ")

young = age < 45
slim = bmi < 22.0
if young and slim:
    risk = "low"
elif young and not slim:
    risk = "medium"
elif not young and slim:
    risk = "medium"
elif not young and not slim:
    risk = "high"

print risk
Like I said, if you have any real programming experience at all, you can already see my mistake. If not, read on. My modified code happily returned prompts for my age and bmi. Being scrupulously honest, I entered my correct age. I have no idea when my bmi is, so I made up a value. When I pressed enter, the value returned was "high". Just to make sure the program was working properly, I entered a young age and a low bmi. Egad! The return value was still "high". In fact, no matter what values I entered, "high" was always returned. This wasn't right. On the fly, I tried this change:
age = input("Please enter your age: ")
bmi = input("Please enter your bmi: ")
It seems very simple (and it is). Using raw_input, the data is always interpreted as a string, rather than the INT type I needed for the program to work. Since strings, rather than integers where input, Python worked it's way through the various tests and, since none of the other conditions matched, printed the result of the final clause which of course, was "high". input interprets what you enter as a python expression, which works, but isn't the best solution, since it can return a wide variety of object types. What's really needed is a way to input something that's always interpreted as a number. I did a bit of research and came up with the following solution, changing the first two lines of my program accordingly:
age = int(raw_input("Please enter your age: "))
bmi = int(raw_input("Please enter your bmi: "))
Now the program will always expect integers to be input for age and bmi. If you try to enter a string now, you'll get something like this:
Please enter your age: Fred
Traceback (most recent call last):
File "assign_bool.py", line 1, in 
age = int(raw_input("Please enter your age: "))
ValueError: invalid literal for int() with base 10: 'Fred'
Play with the different input types and see for yourself. Share/Bookmark

Sunday, October 4, 2009

Sams Teach Yourself PHP and MySQL: Video Learning Starter Kit

Author: Sams Publishing
Format: Paperback: 80 pages/ DVD
Publisher: Sams; 1st Paperback/DVD edition (March 6, 2009)
ISBN-10: 067233027X
ISBN-13: 978-0672330278

Frankly, I'd prefer to work with a book or in a classroom setting. I can read faster than a person can speak in a video. OK, that contradicts my preference for the classroom, but in a class context, I can also directly interact with the instructor and the students. I can't exactly do that using a video. I know I keep telling everyone that I'm a visual learner, so you'd think that a DVD would be just about perfect, but I've always found them something of a problem. This isn't to say that video learning is bad in general or that this product is bad in particular. I'm just expressing my personal opinion before I move on.

I was initially excited to discover that I could use the DVD on any Windows, Mac, or Linux computer with a DVD drive. I've had problems with previous video tutorials that included movie files only readable on Windows. The Quick Start Guide reassured me that I wouldn't have a problem using Linux. Then, as I was about to rip open the packaging around the disc itself, I saw a piece of contradictory information. Specifically, the text on the packaging read, All the contents of the PHP and MySQL Video Learning Starter Kit are accessible on any DVD-equipped Windows or Mac OS X computer (emphasis mine). What?

It gets worse (from my point of view, at least). There are instructions on how to install PHP, Apache, and MySQL on both Windows and Mac but not on Linux. This seems rather mysterious considering we're talking about technologies that just thrive on Linux. Of course, if I have the need to install Apache/MySQL/PHP on Linux, I can just use XAMPP, but that's besides the point. I suppose Sams is playing to the majority desktop market, but that doesn't speak to those of us who spend the vast majority of our time using Linux for work and play. In fact, the vast majority of web developers and database people I work with in my "day job" use Linux on the desktop. Oh well. I still need to evaluate and review the content. Firing up one Windows XP computer.

I slipped the disc in my Windows PC and Adobe Flash Player 9 fired up flawlessly. The TOC is divided into Parts I through IV and each part contains various chapters or lessons. Part I for instance, contains the introductory lessons you'd expect, such as Getting to know PHP, Variables, Flow Control, and so on. Each lesson is divided into Lesson, Lab, and Quiz. I chose Flow Control to start with, just to get an idea of how things were presented.

The lesson on Flow Control honed in on conditional statements and loops. I'd recommend taking notes during the video lesson. I need to take notes, even when I read a book, because it's one of the ways I learn and remember the content, besides actually practicing the relevant tasks. The woman's voice reciting the lesson reminded me somewhat of those instructions airline attendants give when telling you, before your flight takes off, what to do in case the aircraft explodes or sinks into a lake. Actually, I felt fortunate that the visual content didn't include the author's appearance, which most of the time, is totally irrelevant. What I did see was pretty much a PowerPoint presentation.

Lesson 3 was fairly short, maybe five minutes or so long. This is another reason to take notes, since the content goes by very fast. To advance to the lab section, you are required to click the available link. This is also a slide show of sorts, but you click through manually, and there's no accompanying voice. Notes come in handy again since, unless you have a perfect memory, you'll need to refer to something as you're solving each problem. Once you complete each lab, you are able to click to see the output. At the end of a lab session, you can either click the link to repeat, or advance to the Quiz. In the quiz, you select an answer, but can't advance until you get the correct one. The quiz wasn't particularly extensive, which is good if you want to focus on material rather than tests, and bad if you need or want to test your memory of concepts and details.

The general formatting of the disc is good; that is, it's logical. I can see this content being used in the classroom to augment a standard curriculum, but I can't imagine learning these technologies using the DVD and Quick Start Guide (90 page mini-book) alone. I guess I'm old fashioned (which you must have guessed by now) in that I need to have access to more detailed content and/or something or someone I can query about what I'm trying to learn. That said, I can see the video answering questions I sometimes have about ambiguous content I've found in books. Having the same content presented in two different ways can fill occasional gaps. That means I'd need to have the full text book to accompany this DVD.

The content is appropriate for beginning students with little to no prior programming and database experience. For me at least, I'd need to have a platform running actual PHP and MySQL to practice on. Getting my hands dirty is the only way I'm able to learn this sort of material. I recommend setting up your system so you can do a little more than the labs suggest, but remember, the instructions for how to do that only cover Windows and Mac computers.

If you explore the disc, you'll find the eBook Teach Yourself PHP in 10 minutes by Chris Newman in PDF format. The book was published in 2005, but is still relevant to PHP 5.0. The eBook also includes some MySQL content, so it'll take you further than the flash material and the mini-book.

For the programming and database beginner, who may eventually want to get into putting together at least some basic web applications, this product should fit the bill. If you get to the point where you've become familiar with, if not mastered the content, I'm sure you'll want to pursue more advanced resources.

Share/Bookmark

Monday, April 20, 2009

Book Review: JavaScript for Programmers

Authors: Paul J Deitel and Harvey M Deitel Format: Paperback, 448 pages Publisher: Prentice Hall PTR; 1st edition (March 26, 2009) ISBN-10: 0137001312 ISBN-13: 978-0137001316 When I saw the title, I assumed that this was a somewhat advanced book and not for the reader who was learning JavaScript for the first time. I work for a company that develops web applications, and they make extensive use of JavaScript. Each of the developers is well versed in JavaScript and other web programming languages, and I thought this was a JavaScript book for the experienced programmer. With that assumption in place, I was surprised to see a comment on the back of the book state "One of the best introductions to JavaScript" (from a pre-publication review by Raymond Wisman, Indiana University Southeast). An "introduction" to JavaScript? Even a casual scanning of the back cover reveals that the book is supposed present a vast cornucopia of JavaScript related topics. Deitel and Deitel have written quite a number of programming books, so I was interested to see if this indeed was a book where one could learn JavaScript from scratch. The Deitels have written a significant number of "How to Program" books for languages including C, C++, Java, and Visual Basic, but no "How to" book appears on their website (until this one apparently) for JavaScript. Why not "JavaScript How to Program" instead of "JavaScript for Programmers" if this is a beginner's book? Despite the title, the book is structured for the "extreme" beginner, starting with the history of the Internet, the World Wide Consortium (W3C), Web 2.0 and so on. Going through the Preface material, I found a lot of information, especially about Deitel and Deitel, as well as Deitel and Associates, Inc. (apparently, they like to promote themselves a lot, but after all, business is business), but nothing that specifically stated the identity of the target audience. Since the book is structured to present XHTML and CSS first, I could only imagine that the book would be suitable for someone who didn't know those technologies. The majority of the book (eight chapters) is devoted to JavaScript (as it should), while the two ending chapters contain content on XML, RSS, and Ajax. That's quite an ambitious mouthful to teach the newcomer to web development. Anxious to try out the book, I dutifully followed the Before You Begin instructions and attempted to download the source code from the listed link: www.deitel.com/books/jsfp/. That's when I got a big disappointment in the form of a "The page cannot be found" error. I rechecked the URL and I had typed it as printed in the book. I went to the Deitel site to see if I could just navigate to the source code, but not only was the code not present, there was no mention of the book at all. I went to the publisher's site to see if perhaps the source code was there. I did find it and I could download the source code for chapters 2 through 13, I'd need to download the files for each chapter as individual zip files. I looked for an errata page at InformIT to see if a change had been made regarding the stated location of the source code, but there was none. The errata page at the Deitel site didn't mention the book at all. I don't mind doing my research when I'm learning something, but I wouldn't expect the reader to have to work this hard when they're not even in Chapter 1 yet. I skipped the Chapter 1 history lesson and opened the book to Chapter 2, since I'd downloaded the sample code for the chapter. The zip file contained a number of rather simple HTML files. Nothing to write home about, but I guess you'd expect that if you were starting from the beginning. Actually, Chapter 2 is a crash course on HTML, including how to create lists, tables, forms, and links. The information was compressed, but entire books are written on basic HTML, and I wondered if the complete beginner was supposed to "get it" in one brief chapter. The very last entry in the chapter though, was a link to a page on the deitel.com site containing all kinds of external links to information and tutorials on HTML. Apparently, the Deitel site is supposed to provide serious support to this book (lack of code samples or even a mention that the book exists aside). Chapter 3 was the other bookend to Chapter 2 and offered up a quick and intense course in CSS to the reader, with another link at the end to a web page packed with external links to all things CSS, including books on CSS by other publishers such as O'Reilly. I was beginning to see that, depending on the reader's level of experience and how quickly they learned, it might take awhile to work through this book. If I knew nothing about HTML and CSS and I only had 2 chapters in a book to teach me those languages, I might end up spending some time on the recommended links pages on the Deitel site, doing a bit of self study before tackling the JavaScript section. I rather expected the JavaScript chapters to be more self contained than the others, since its the main focus of the book. While that's true, I did find that the end of each JavaScript chapter did include a link to a JavaScript resources page on the Deitel site, so the book is written with the general philosophy of the web containing everything the book can't. As I continued to move through the book, I was taken on a path using more "baby steps" as bit by bit, the JavaScript tutorial began to unfold (if you'll pardon the mixed metaphor). I will admit, I didn't download each of the chapter's code examples (I may later and, if what I find is significant, I'll publish an update to this review), but what I saw did seem to work. That's important, since one of the common complaints I hear from programmers, is that sample code often doesn't work as advertised, as if the code were never tested and debugged prior to the book being published. The good side of this book is that it is written to take the very beginner from basic XHTML and CSS and gently help them through the process of learning how to program in JavaScript. The bad side is that the reader has to work up front to even find the sample code, and it's as if Deitel and Deitel didn't think enough of their latest work to even mention it on their site. For a company that creates training material for a living, that's not a very good way to back up their book. Good thing the support pages were accessible with all of their external links to a wider collection of tutorial material. They say a first impression is a lasting impression. If that's so, no matter how good the later parts of this book are written, getting past the first bits didn't help my first time experience with a Deitel book.