What has been helping me out is the phrase: "Code that cannot fail is infinitely easier to maintain then code that has many paths through it which might fail."
Murphy's law: "What can go wrong WILL go wrong". So go over every line of code and ask: "How might this function do something unintended?". If you find any answer to that question then you need to change how the function works until the answer is: "This function physically cannot do something unintended". If the hardware and compiler are working to specification then the ONLY path through this code is the correct way through (or a pretty exception/error that tells you what the programmer/user did wrong or what the hardware/compiler failure was).
For example: you have a function calculate() which takes a collection of Strings which represents items to process. The problem is that function foo() might run incorrectly and some String items may become invalid or incorrect. Then calculate() will make its best attempt, then calculate may throw an exception/error or worst of all, it may work. The solution here is to make it physically impossible for the items in the list to become invalid/wrong, don't use an array of String, use an array of class Student/Airplane/Book/ProcessItem which has a constructor which validates its own existence as soon as it is made, it will produce a runtime error (or better yet a compile time error) the instant the programmer/user made a mistake.
The millions of unintended paths through calculate() which may throw a cryptic runtime exception has been eliminated. Imagine how much easier it is to diagnose a "InputProcessItemException" than a cryptic off-by-one error inside calculate();
Saturday, March 5, 2011
Wednesday, October 20, 2010
ASP.NET Script injection quiz.
What is wrong with using this in your ASP.NET code?
<%= textbox.value >
Answer: It allows script injection. Any user generated content should be considered malicious. This line gives someone access to run commands.
<%= textbox.value >
Answer: It allows script injection. Any user generated content should be considered malicious. This line gives someone access to run commands.
Saturday, September 11, 2010
Get PowerShell for Windows XP.
Get Windows Power Shell for Windows XP, it'll blow you away!
http://machinesentience.com/windows_xp_powershell_evaluation.html
http://machinesentience.com/windows_xp_powershell_evaluation.html
Real life uses for Genetic Algorithms.
I just had a huge idea, just now, a genetic algorithm program that has instantaneous access to your brain's mental state, and can play music/video or sound files. The computer would play things, then examine your mental state after that, then you can tell the computer to optimize for a mental state. Woah, I sense a billion dollars to be made championing something like that. Every human would want it. A bliss machine.
Evolutionary Sodoku solver:
http://watchmaker.uncommons.org/examples/sudoku.php
Professional stock trading:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1538464#1538464
Identify stolen credit cards inside MMO's.
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1589627#1589627
Best way to load freight into a truck:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1589612#1589612
Little digital critters in a world with eyes and ears collaborating:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1575154#1575154
Football Tipping:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1575855#1575855
Evolutionary Sodoku solver:
http://watchmaker.uncommons.org/examples/sudoku.php
Professional stock trading:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1538464#1538464
Identify stolen credit cards inside MMO's.
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1589627#1589627
Best way to load freight into a truck:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1589612#1589612
Little digital critters in a world with eyes and ears collaborating:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1575154#1575154
Football Tipping:
http://stackoverflow.com/questions/1538235/what-problems-have-you-solved-using-genetic-algorithms-genetic-programming/1575855#1575855
Friday, September 10, 2010
Profile of a Sociopath
Profile of a Sociopath
I know it's not much to do with programming, but it tends to run in some programmers themselves so I thought it was extremely relevant.
http://www.mcafee.cc/Bin/sb.html
I know it's not much to do with programming, but it tends to run in some programmers themselves so I thought it was extremely relevant.
http://www.mcafee.cc/Bin/sb.html
Tuesday, September 7, 2010
How to install Apache 7 on Windows 7
Here is how to install Apache 7 on Windows 7:
1. Go to http://tomcat.apache.org/download-70.cgi
2. Download the '32-bit/64-bit Windows Service Installer'
3. Run the exe installer, follow the directions.
4. Restart the computer.
5. In the start menu, find the 'configure apache' button. You have to run it as administrator or it will fail.
6. Navigate to http://localhost:8080
7. Do the tutorials.
1. Go to http://tomcat.apache.org/download-70.cgi
2. Download the '32-bit/64-bit Windows Service Installer'
3. Run the exe installer, follow the directions.
4. Restart the computer.
5. In the start menu, find the 'configure apache' button. You have to run it as administrator or it will fail.
6. Navigate to http://localhost:8080
7. Do the tutorials.
Wednesday, August 18, 2010
Changing the colors of the console.
Changing the colors of your Linux console/shell is important when your scrolling through black text and you want your eyes to spot the shell line quickly.
If you want to change the colors of your Fedora Linux console line you have to change the PS1 Variable. Here is how I did it:
Step 1: Open up a console.
Step 2: Login as super user.
Step 3: Open up the file /home/yourhome/.bashrc
Step 4: Add this line anywhere after the invocation of /etc/bashrc (outside of the if block):
export PS1="[\e[0;31m\u\e[m@\e[0;34m\h \W \e[m]\$ "
Step 5: Save the file and restart the console.
Step 6: You should see red and blue showing for your shell.
If the codes above confuse you, don't worry, it seems to be a home-brew bash code system. \e[x;y means 'begin color' and \e[m means 'end color'. The escape codes are somewhat straight forward though.
Check out this website for more info on the escape codes:
http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
If you want to change the colors of your Fedora Linux console line you have to change the PS1 Variable. Here is how I did it:
Step 1: Open up a console.
Step 2: Login as super user.
Step 3: Open up the file /home/yourhome/.bashrc
Step 4: Add this line anywhere after the invocation of /etc/bashrc (outside of the if block):
export PS1="[\e[0;31m\u\e[m@\e[0;34m\h \W \e[m]\$ "
Step 5: Save the file and restart the console.
Step 6: You should see red and blue showing for your shell.
If the codes above confuse you, don't worry, it seems to be a home-brew bash code system. \e[x;y means 'begin color' and \e[m means 'end color'. The escape codes are somewhat straight forward though.
Check out this website for more info on the escape codes:
http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
Subscribe to:
Posts (Atom)
