The Joys Of Programming

kazar wrote:
complexmath wrote:

It's all explained quite clearly in the Mythical Man Month, which was written in the 70s. If you meet a manager who hasn't even heard of this book, run away fast.

I haven't read the book myself (though I am not a manager) but have it on my list of must reads. My manager hasn't read the book either (or even heard of it before I told him) and from the synopsis, it is something that my manager can greatly benefit from. I told him to buy the book 4 months ago and read it, but he has yet to do it. How fast should I be running?

In truth, I've met a lot of good managers who haven't. But I've found it's a good litmus test.

kazar wrote:

As a different topic of conversation, what are people's opinions on the singleton pattern. I pretty much never use it anymore and when I find one, it usually just causes more problems then it solves.

In some cases a singleton of some sort is probably necessary, but I think the pattern tends to be overused because it's the most obvious solution to that particular problem. In a concurrent program the singleton is an obvious bottleneck, and people usually try to improve things with the double-checked locking anti-pattern, and things go south from there.

I made my first dictionary and key lookup. I feel like a god.

I went from this:

def planeRideCost(city): if city == "Charlotte": cost = 183 return cost elif city == "Tampa": cost = 220 return cost elif city == "Pittsburgh": cost = 222 return cost elif city == "Los Angeles": cost = 475 return cost else: return "Wrong plane"

to this:

def planeRideCost(city): cities = {"Charlotte": 183, "Tampa": 220, "Pittsburgh": 222, "Los Angeles": 475} if city in cities: return(cities[city]) else: return 'Wrong plane.'

return cities.get(city, 'Wrong plane.')

Nice. A whole new world has just opened up for you.

Can simplify that to just a lookup:

def planeRideCost(city): cities = {"Charlotte": 183, "Tampa": 220, "Pittsburgh": 222, "Los Angeles": 475} return cities.get(city, 'Wrong plane.')

One other comment: try to be consistent with quotes. Either ' or " is fine, just be consistent, at least across a file.

Edit: Dammit, Booglehausered!

Reading and writing from mongo has me using a bunch of .get() and .set_default() dict methods.

Even better simplification. The example I googled for didn't show that.

I had asked boogle this at work, and maybe someone knows a more idiomatic way to do this. We've got some Python scripting in our code that interacts with a few systems that can throw exceptions. Turned out that the exception handler threw an exception because it was looking for e.Message, and the particular exception it got had e.message (lowercase). I got around the problem by using:

getattr(e, “message”, getattr(e, “Message”, “No exception message found”))

It looks for e.message, then e.Message if it can't find that, and finally gets a sane default if it can't find either. Is there a better way to handle things like that?

Bonus_Eruptus wrote:

I had asked boogle this at work, and maybe someone knows a more idiomatic way to do this. We've got some Python scripting in our code that interacts with a few systems that can throw exceptions. Turned out that the exception handler threw an exception because it was looking for e.Message, and the particular exception it got had e.message (lowercase). I got around the problem by using:

getattr(e, “message”, getattr(e, “Message”, “No exception message found”))

It looks for e.message, then e.Message if it can't find that, and finally gets a sane default if it can't find either. Is there a better way to handle things like that?

Can you catch the, uh, exceptional exception (e.message) and wrap it in one with the format you expect and throw that instead? Then do your actual exception handling logic with the expectation of only having e.Message?

Weird that getattr doesn't allow you to pass an array. It looks like your options are as above or something using hasattr().

SixteenBlue wrote:
Bonus_Eruptus wrote:

I had asked boogle this at work, and maybe someone knows a more idiomatic way to do this. We've got some Python scripting in our code that interacts with a few systems that can throw exceptions. Turned out that the exception handler threw an exception because it was looking for e.Message, and the particular exception it got had e.message (lowercase). I got around the problem by using:

getattr(e, “message”, getattr(e, “Message”, “No exception message found”))

It looks for e.message, then e.Message if it can't find that, and finally gets a sane default if it can't find either. Is there a better way to handle things like that?

Can you catch the, uh, exceptional exception (e.message) and wrap it in one with the format you expect and throw that instead? Then do your actual exception handling logic with the expectation of only having e.Message?

It already gets wrapped in another exception and sent on, but logging and setting that exception's message was throwing the exception because someone somewhere decided they should break convention. What I've got works fine, I'm just looking for a more succinct way of handling it.

That seems to be the simplest solution I can think of, if you only use it in one place. If used in multiple places, I'd wrap it in a method/function to keep the Message/message thing localized.

Preliminary indications are that Puerto Rico has voted to petition Congress to be enabled to become a state.

It's not going to happen, like, tomorrow, but how many things are based on the fact that there are 50 states, or that Puerto Rico is a territory now and will be changing into a state?

If any of you are shepherding code that has anything to with geographical layout or addresses, you might want to take a look and see what effects you might be getting.

This does bite me in the arse in a couple spots in our different products, but it shouldn't be too bad. The backend is where it might get ugly. I just realized it will hit all our accounting reports that are broken out by state, and some of our international tax reporting and some of that stuff is a Great Plains black-box nightmare. I better go see if Falchion has any of that eldritch chicken blood left...

Totally didn't think to ask until just this morning: is anyone at QCon SF? Would be delighted to meet up with any goodjers in attendance here.

momgamer wrote:

Preliminary indications are that Puerto Rico has voted to petition Congress to be enabled to become a state.

It's not going to happen, like, tomorrow, but how many things are based on the fact that there are 50 states, or that Puerto Rico is a territory now and will be changing into a state?

If any of you are shepherding code that has anything to with geographical layout or addresses, you might want to take a look and see what effects you might be getting.

This does bite me in the arse in a couple spots in our different products, but it shouldn't be too bad. The backend is where it might get ugly. I just realized it will hit all our accounting reports that are broken out by state, and some of our international tax reporting and some of that stuff is a Great Plains black-box nightmare. I better go see if Falchion has any of that eldritch chicken blood left...

Shouldn't affect me any. I can see it affecting stuff at some of my previous jobs. Still, the fact that it's a territory means it's been already included in lots of state lists for a while now.

momgamer wrote:

It's not going to happen, like, tomorrow, but how many things are based on the fact that there are 50 states, or that Puerto Rico is a territory now and will be changing into a state?

I think I'll bring that one up at work today (I'm in New Zealand, but the company I work for is headquartered in the US, and so are most of our customers.)

Not that I haven't been through this sort of thing before. I used to work at a government computer centre that managed (among other things) New Zealand's driver licensing system. I recall a very entertaining cascade of failures the first time someone with a three-digit age got a driving license.

CaptainCrowbar wrote:
momgamer wrote:

It's not going to happen, like, tomorrow, but how many things are based on the fact that there are 50 states, or that Puerto Rico is a territory now and will be changing into a state?

I think I'll bring that one up at work today (I'm in New Zealand, but the company I work for is headquartered in the US, and so are most of our customers.)

Not that I haven't been through this sort of thing before. I used to work at a government computer centre that managed (among other things) New Zealand's driver licensing system. I recall a very entertaining cascade of failures the first time someone with a three-digit age got a driving license.

You mean after the Apocalypse that ensued?

Kinda forgot to check in here after my question. Thanks everyone for the responses!

DanB wrote:

I'd also pick up some JavaScript and specifically JQuery. It makes JavaScript easy and fun and there are plugins for every piece interactive page widgettery out there. If possible try and avoid JQueryUI it's somewhat full of crud these days and editing the CSS there is a little hellish. That said it does a lot of neat things and its not that bad if your really must.

We've used JQuery in various capacities at work for about 2 years now. We don't do anything crazy with it, but most of my experience has been with the selectors, the ajax commands, basic effects (ie. show/hide), and integrating a couple of plugins here and there. Really like working with it, especially because it takes some of the suck out of routine Javascript work.

tboon wrote:

If you are stuck in Java-land and know JSP, Stripes is the way to go in my opinion.

This is a personal project mostly to try and bust out of Java-land on the side. As much as I have no trouble working in Java, I'd really like to branch out and try some other languages.

One of my pet peeves with my current job is that our office uses Java primarily without taking the time to consider other languages that might be more appropriate for the project.

DanB wrote:

Also worth a look is Twitter's bootstrap.js library
http://twitter.github.com/bootstrap/

It's a really nice alternative to JQuery plus plugins (or JQueryUI). It's been getting a lot of love lately and rather excellently it gracefully degrades/optimises across desktop, tablet and phone displays.

Will have to give this (and the HTML5 boilerplate) a look. I'm not sure how complex I want to get on the presentation layer (as I'm terrible with graphic design stuff), but having an alternate JS library to keep in the toolbox is a good idea.

EDIT: Ok, one more question... I really haven't done a ton of development work at home, or at least nothing that requires setting up a web server and a DB on my personal box. Does it make more sense to create an Ubuntu VM and just do the bulk of the work there? My main reason is that I primarily use my computer for games and general tinkering. I really don't want to have to worry about services like Apache and MySQL running in the background when I'm not actively developing. Also, a VM would be a lot easier to migrate if I make any hardware changes to my rig, otherwise I have to go through the whole process of installing the application/development stack on Windows again at a later date.

For so many reasons, if it doesn't require Visual Studio or explicitly target Windows, develop it on *NIX.

I do all my dev work just fine in Windows.

I understand the desire for clean environments though. I'd probably dual boot rather than use a VM, but that's my preference. You could also just make sure to run all of those things as services in Windows that don't start automatically so you're always explicitly enabling them when you're developing.

shoptroll wrote:

EDIT: Ok, one more question... I really haven't done a ton of development work at home, or at least nothing that requires setting up a web server and a DB on my personal box. Does it make more sense to create an Ubuntu VM and just do the bulk of the work there? My main reason is that I primarily use my computer for games and general tinkering. I really don't want to have to worry about services like Apache and MySQL running in the background when I'm not actively developing. Also, a VM would be a lot easier to migrate if I make any hardware changes to my rig, otherwise I have to go through the whole process of installing the application/development stack on Windows again at a later date.

At work, we have an Ubuntu VM image that almost everyone on the team downloads a copy of and runs locally as their dev environment. It's certainly a popular way to go.

Hello friends
Welcome to this forum site
Here you can find a lot of things
The forum are the way
where you can share your views and ideas
now I can tell you about the news website
please visit

dainik bhasker

I run a Ubuntu VM (using VirtualBox) on a Windows 7 host both at work and at home. I'm a Linux person at heart and this has been working well for me.

*Legion* wrote:
shoptroll wrote:

EDIT: Ok, one more question... I really haven't done a ton of development work at home, or at least nothing that requires setting up a web server and a DB on my personal box. Does it make more sense to create an Ubuntu VM and just do the bulk of the work there? My main reason is that I primarily use my computer for games and general tinkering. I really don't want to have to worry about services like Apache and MySQL running in the background when I'm not actively developing. Also, a VM would be a lot easier to migrate if I make any hardware changes to my rig, otherwise I have to go through the whole process of installing the application/development stack on Windows again at a later date.

At work, we have an Ubuntu VM image that almost everyone on the team downloads a copy of and runs locally as their dev environment. It's certainly a popular way to go.

Our user machines are usually something of a personal experimental space covering a (smallish) range of desktops, laptops and OSes, mostly some flavour of linux or OSX. For the webdev we have a development server which is a 4 core machine which runs a handful of images of the production server. That way anything developed and tested is run on the same target hardware and OS build as it will eventually be deployed on and sitting behind exactly the same firewall/routing etc...

tl;dr: Whoooo Go VMs!

SixteenBlue wrote:

I do all my dev work just fine in Windows.

I understand the desire for clean environments though. I'd probably dual boot rather than use a VM, but that's my preference. You could also just make sure to run all of those things as services in Windows that don't start automatically so you're always explicitly enabling them when you're developing.

I do this most of the time for personal projects, with a .cmd that kicks everything off when I need it. I use VMs running Linux as well for some projects, especially where the tooling/language support is better in Linux-land. Each work well, kind of just depends on personal preference (and, like I mentioned, language/tools support).

DanB wrote:

tl;dr: Whoooo Go VMs!

100% agree. Also, you can try out a half dozen different *NIX flavors fairly trivially with this setup and settle on the one you like. Ubuntu, Fedora, Debian, SUSE, CentOS, FreeBSD, OpenBSD, whatever. Hell, you could even try Puppy Linux, which is even more "Linux for Dummies" than Ubuntu. Then if you really feel the virtual layer is slowing you down you could setup a dual-boot to your favorite flavor.

Mixolyde wrote:
DanB wrote:

tl;dr: Whoooo Go VMs!

100% agree.

I 100% agree with this 100% agree. I bought a stompy gaming machine a few months ago and run an Ubuntu VM on it that is indistinguishable most of the time from running on the metal.

shoptroll wrote:

This is a personal project mostly to try and bust out of Java-land on the side. As much as I have no trouble working in Java, I'd really like to branch out and try some other languages.

You know, no one suggested any of the JVM-based non-Java languages such as Scala and Clojure. If the goal is to learn another marketable technology, these may not fit the bill (or maybe they will; who knows what the future holds?) but they are different enough from the Java paradigm to make learning them a growth experience if you decide that's where you want to go. Their tooling is mostly custom, but based on the standard Java toolchain stuff like Maven, so it might dovetail nicely with knowledge you already have.

The Lift web framework seems to be the go-to Scala web framework; for Clojure it still appears to be a bit of a horse race.

Anyway, just another thought. Have fun, whatever you do.

pgroce wrote:
Mixolyde wrote:
DanB wrote:

tl;dr: Whoooo Go VMs!

100% agree.

I 100% agree with this 100% agree. I bought a stompy gaming machine a few months ago and run an Ubuntu VM on it that is indistinguishable most of the time from running on the metal.

While we're at it a thing that blows my tiny mind is that fact the VMs for our production machine and the 2 main backend servers for our web site are completely hot swappable to other hardware. Craziness I tells ya. I am also somewhat amazed by hot swappable hardware too mind.

Is there a good framework for developing a RESTful service in Java? Inspired by a talk at QCon on micro-services, I want to slap together a quick prototype to try wrapping REST interfaces around two related components of a codebase I've been working on. In this prototype, the micro-service for Component A would receive requests from a user, either through a browser or the command line, whereas the micro-service for Component B would only receive requests triggered by Component A.

Am I looking for something like Restlet or Jersey? Rescue my tired brain!

Cyranix wrote:

Is there a good framework for developing a RESTful service in Java? Inspired by a talk at QCon on micro-services, I want to slap together a quick prototype to try wrapping REST interfaces around two related components of a codebase I've been working on. In this prototype, the micro-service for Component A would receive requests from a user, either through a browser or the command line, whereas the micro-service for Component B would only receive requests triggered by Component A.

Am I looking for something like Restlet or Jersey? Rescue my tired brain!

Yeah, I recommend Jersey. I used it for a quick side project and it was incredibly easy to plug in to my existing application. If you're looking for a more complete package, I recommend taking a look at DropWizard. I haven't used it yet but I've used most of those libraries and they're all solid.

Oh score, DropWizard! Thanks! That's what the guy giving the QCon talk mentioned in passing -- I think he should've tried to promote it a bit more, because that's gonna really fit my needs. Maybe he was under the impression that everyone in attendance knew what it was. Many thanks!

I did get a chance to see what JAX-RS entailed, so the system makes a bit of sense to me now.