When I hate being a coder… #2

I just found this gem, in some of our billing code:

$ci = $this->paymentMethod;

$cc['CC_CardType'] = $ci['CC_CardType'];
$cc['CC_Number'] = $ci['CC_Number'];
$cc['CC_ExpMonth'] = $ci['CC_ExpMonth'];
$cc['CC_ExpYear'] = $ci['CC_ExpYear'];
$cc['CC_Name'] = $ci['CC_Name'];
$cc['CC_Street'] = $ci['CC_Street'];
$cc['CC_City'] = $ci['CC_City'];
$cc['CC_State'] = $ci['CC_State'];
$cc['CC_Country'] = $ci['CC_Country'];
$cc['CC_Zip'] = $ci['CC_Zip'];

$p->loadCreditCardPayment($cc, $total, 0);

First it copies A ($this->paymentMethod) to B ($ci), then copies each value of B in to C ($cc), and then passes C to the function. That’s right, 3 copies of the same data, and 14 lines of code. One could also have just passed A to the function, as so:

$p->loadCreditCardPayment($this->paymentMethod, $total, 0);

It’s kinda like pouring a drink that’s already in glass in to another glass, then using a spoon to move the liquid in to a different glass, then drinking from that last glass… why not just drink from the glass it was originally in? o_O

When I hate being a coder…

This is how NOT to comment your code:

#addCreditCard
function addCreditCard(){
… code removed …
//————————————————————————-
#addBankAccount
function addBankAccount(){
… code removed …
//———————————————————–
#deleteCreditCard()
function deleteCreditCard(){
… code removed …
//—————————————————————–
#deleteBankAccount()
function deleteBankAccount(){
… code removed …

Now I totally understand that for doc-generating programs, and certain IDEs, you’re meant to put comments above your functions describing them and the parameters use… but who does this (above)? Are you really so stupid that you need to put the function’s name in a comment above… the function’s name?

You, sir, should not be coding.

USB Webserver 8.0 is out!


I’ve just gotten word from the creators that USB Webserver 8 is out – long time readers might remember that I released an unofficial hacked up version a little while ago, you should definitely use this official version instead.

USB Webserver 8

This release contains:

  • Php 5.2.13
  • Apache 2.2.15
  • PhpMyAdmin 3.3.1-rc1
  • MySQL 5.1.44

USB Webserver 8.0 (unofficial)

UPDATE (15 July 2010): An “official” version of USB Webserver 8 has been released, please use this instead of my “unofficial” version. You can download it from http://www.usbwebserver.net/

This is an unofficial updated version of USB Webserver. The original USB Webserver was created by http://www.usbwebserver.nl – but their site is currently down, and they haven’t released an update for a while.

This version contains:

Apache: 2.2.11
PHP: 5.2.10-dev (with GD and cURL)
MySQL: 5.1.30-community (with InnoDB)

It defaults to “English” (the original was “Dutch”), and you may need to change the ports if you have been using USB Webserver previously.

Download: “USB Webserver 8.0 (unofficial).zip” (17.6mb)

(and yes, I know the main USB Webserver screen still says “USB Webserver 7.0″ – ignore that :P)

memcache on PHP 5.2.*

I decided I wanted to start using memcached because it’s really awesome, but really struggled to get it working in Windows on PHP 5.2.3 because I couldn’t find the stupid “php_memcache.dll” file I needed (at the time of writing this, Pecl4Win is down… which happens to be where the official PHP documentation tells you to get it from – great).

Luckily I came across this blog post, which not only tells you how to to install the extension (adding 1 line to your “php.ini” file) but also linked to a PHP 5.2.* version of the it. I decided to mirror it, for anyone else trying to find it:

php_memcache.dll (49kb)

PHP-SciTE

As a PHP developer I’ve tried many different IDEs but have always ended going back to SciTE. I started using a version with modifications by Bruce Dodson, but got frustrated with it not listing PHP files in the default “File Open” window, and not recognizing PHP5 files as PHP files, so I got to tinkering.

I changed the font and colours (for PHP files anyway), removed the other languages, enabled the auto-complete dropdown, changed the menus, included the PHP binary to check files for syntax errors, and included phpStylist to beautify source code. I also made a new icon, and added the latest “php.api”, and made F1 (help) open the PHP manual (included).

Copyright © 2012 Hypn.za.net

CSS Template By RamblingSoul | WordPress Theme by Theme Lab and Best Hosting.