Something new: Closure

Now that I’ve talked about Functions as first-class values and anonymous functions I can talk about closures. A closure retains the environment it was created in. This is a programming language feature that is nearly always associated with first-class functions. In fact, the two concepts are related, but distinct.

Consider this JavaScriptL


function getIncrementor() {
    var outerLocal = 0;
    
    return function(incrementBy) {
        outerLocal += incrementBy;

        return outerLocal;
    };
}

var incrementor1 = getIncrementor();

var incrementor2 = getIncrementor();

incrementor1(1); // Produces 1
incrementor2(2); // Produces 2
incrementor1(3); // Produces 4
incrementor2(4); // Produces 6
incrementor1(5); // Produces 9
incrementor2(6); // Produces 12

Take a look at this example on JSFiddle.net.

Leave a comment

Filed under Uncategorized

Something new: Anonymous function

An anonymous function is a function that has no name, or identifier. Functions must be first-class values for anonymous functions to exist. See my previous post about first-class functions for more details. Since an anonymous function has no identifier, it must be called using the variable or parameter it was assigned to.

A JavaScript example:

var funkeyVariable = function() {
    return "I am a first-class function.  Respect me!";
}

var anonymousFunctionReturned = funkeyVariable();
//  anonymousFunctionReturned == "I am a first-class function.  Respect me!";

Leave a comment

Filed under Uncategorized

Something new: First-class functions

First-class functions are functions you can use like a value. You can assign it to a variable and call it by using the variable like you would use a function. You can also pass First-class functions as parameters.¬†First-class value¬†actually means “an entity that can be passed as a parameter, returned from a subroutine, or assigned into a variable.” In every programming language I know strings are first-class values, for example.

A JavaScript example:

function freakyFunction() {
    return "I am a first-class function.  Respect me!";
}

var freakyVariable = freakyFunction; // Notice no parentheses...
//  freakyVariable == function freakyFunction() {
//      return "I am a first-class function.  Respect me!";
//  }

var freakyFunctionReturned = freakyVariable();
//  freakyFunctionReturned == "I am a first-class function.  Respect me!";

Leave a comment

Filed under Uncategorized

Trying

I’ve noticed the .NET Framework has a number of functions that start with ‘Try‘. I’ve come to like this pattern as a way to indicate a few things about a function.

* The function does something internally that could throw an exception.
* The function will never throw an exception itself.
* Failure is indicated by the Boolean return value.

I don’t think ‘Try‘ requires the function take a parameter by reference and return a value in that parameter like most of the TryParse methods do. Sometimes it’s nice to have a indicator that a method simply will never throw an exception.

So, for example:

public bool TryGetBanana(out Banana banana);
public bool TryEatBanana(Banana banana);

While TryGetBanana gets you a banana it will never throw the OutOfBananasException. And on the same note, while TryEatBanana takes a banana, it will never throw the BananaTooRipeException.

Leave a comment

Filed under Uncategorized

An open letter to AmeriGas

This is a message I wrote to AmeriGas after using there website. Or, more to the point, attempting to use there website, getting really frustrated, writing this super long message and then attempting to get back to the process of giving them my money.

This is not a service request, this is feedback for your service. Also, to be clear, this is constructive critisium. If you have trouble with the issues outlined in this message, you are welcome to ignore it. I ask for the CEO to see this message, that’s all. Now, I will say that I was quite frustrated when I wrote this, so It’s a bit scathing.

Your website is horrible, annoying, disappointing, badly designed and confusing. You should be ashamed of the user experience you are presenting.

Some specific failures:

  • My Bills: Ticket/Order #: Used to present the user with multiple pieces of information and it just becomes confusing.
  • My Bills: What does “Not payable” mean?
  • My Bills: Maybe in financial circles parentheses means a negative number, but in the real world, we prefix the number with a minus symbol. This is really *really* basic UI design!
  • Password max length is too short to allow pass-phrases. (if you don’t know what a pass-phrase is you should just read this: https://xkcd.com/936/ because I’m not going to explain it any better)
  • Account number is the login name. How about using the email address or let the user choose a username like every other website on the planet.
  • Poor layout and design.
  • In my opinion, ugly UI design.
  • Poor UI flow for simple processes.
  • Confusing information presentation (some listed above).
  • Ok, this is one of the few places
  • I should not be able to even *select* “Existing Bank/Credit Card” if I don’t have a saved item in this list.
  • Don’t just hide the payment details, collapse that space!
  • Too many required fields on this form. Yea, I get that you want to be able to know who is contacting you, but remember that the most interesting feedback is anonymous feedback.
  • The founding principle here is, if people are complaining, something is wrong. Maybe not exactly what people are complaining about, but something is wrong for sure.
  • it appears I have a credit on my account (it’s hard to tell with the UI design) and it appears I still have to fill out a credit card. If you don’t get my point here, just… Well, I don’t know… focus on delivering gas, I guess, because you’ll never have a good website.

Look, if there’s one thing you should take away from this message, it’s this: Details matter. Details matter because your application (web app in this case) is just a collection of tiny details. (read more here: http://goo.gl/dPkwU ). Also, Apple didn’t get to the point of earning more money than the US GDP by ignoring the little things. Maybe your not selling laptops, but your website is a part of your customers experience, and that’s something you should think about.

Let’s be clear here. I’m *not looking for answers*. Don’t send me a reply trying to justify the items pointed out here. If you have to explain something, then that’s the very definition of bad UI design. My email address was provided so you can ask for more clarity on the items if you need it.

Here are a few good things I noticed, just so this isn’t completely depressing:

  • 4000 characters in this response is actually pretty good. I’ve written quite a bit of stuff in here and as of actually writing this sentence I’m around 3000 characters in.
  • I guess your color scheme isn’t too bad. It’s not gray and brown, I guess…
  • The few error messages I’ve seen are fairly clear. Not totally, but better than I’ve seen on other websites.

Leave a comment

Filed under Uncategorized

The value of IT certificates

My friend asked me “What certificates do you recommend I get for an IT job?” Since I’m not in IT, I had a conversation with the IT manager here and he gave me some great info, that I promptly relayed to my friend. Here’s the run-down for those interested.

Don’t bother with these:
* Microsoft Certified Professional (MCP): It doesn’t say anything specific about you.
* Linux+: It’s not in depth or useful.

These could be useful, depending on the role your looking for:
* A+: It’s very basic, but could help with an entry-level position.
* Network+: Again, very basic, but could help.

These are valuable and worth getting:
* Cisco Certified Network Associate Routing & Switching (CCNA)
* Red Hat Certified Engineer (RHCE)
* Red Hat Certified Architect (RHCA)
* Microsoft Certified Systems Engineer (MCSE)
* Microsoft Certified Systems Administrator (MCSA)
* Project Management Office (PMO)
* HP Certified System Administrator (CSA)
* HP Certified System Engineer (CSE)

Some additional advice:
* Don’t put your certificates after your name like a Ph.D would. Your not Jo Rock MCP. Your Jo Rock with an MCP.

1 Comment

Filed under Uncategorized

Get a SVN dump of an external repo without shell access

Here is a script that will run svnsync to pull in a local copy of a repo and then dump that local repo. It’s a good way to make a copy of a repo you don’t have admin access to.

Use –help to get usage and examples.

Special thanks to [https://cournape.wordpress.com/ cournape] for his post [https://cournape.wordpress.com/2007/12/18/making-a-local-mirror-of-a-subversion-repository-using-svnsync/ Making a local mirror of a subversion repository: using svnsync].

[http://blog.nateperry.org/wp-content/uploads/2011/10/svn-dump-external.sh_.zip Download here]

or Copy:

#!/bin/sh

source_repo=$1
dump=$2

this_path=$( cd $( dirname "$0" ); pwd)
stamp=$( date "+%Y-%m-%d-%Hh%M-%S"; )
sync_repo=$this_path/tmp-svn-dump-repo-$stamp/
sync_url=file://$sync_repo
hook_file=$sync_repo/hooks/pre-revprop-change

#hook_contents='exit 0'

hook_contents=$( cat <&2n
exit 1
EOF
)

function usage()
{
	echo
	echo usage: $( basename "$0" ) SOURCE_URL [DUMP_File]
	echo example: $( basename "$0" ) https://domain.com/svn/PROJECT/trunk
	echo example: $( basename "$0" ) https://domain.com/svn/PROJECT/trunk  PROJECT-trunk.dump
	echo
	return 0;
}

if [ -z "$source_repo" ]; then
	echo
	echo Source repository required.
	usage
	exit 1
fi

if [ "$source_repo" == "--help" ]; then	usage; exit 1; fi
if [ "$source_repo" == "-h" ]; then usage; exit 1; fi

if [ -z "$dump" ]; then
	dump=./$stamp.dump
	echo dumping to $dump
fi

# This tells bash to exit if any command returns non-zero.
set -e

svnadmin create $sync_repo

#if [[ $? -ne 0 ]]; then  exit 1;  fi

echo $hook_contents > $hook_file

chmod +x $hook_file

echo
echo svnsync init ...
echo You will now be prompted for the password to $source_repo
echo * Press 'enter' to clear the user name 'svnsync'
echo * type the user name, press enter
echo * type the password, press enter
echo

svnsync init --username svnsync  $sync_url  $source_repo

echo
echo Syncing...
echo

svnsync sync $sync_url

echo
echo Syncing again in case anything new came in during the previous sync.
echo

svnsync sync $sync_url

echo
echo Dumping...
echo

svnadmin dump $sync_repo > $dump

echo
echo All done.
echo

Leave a comment

Filed under Uncategorized