Python 2 to 3…

Not a python person (used it in some projects, but it’s not my main tool). That said, I’ve been watching the “2->3” migration horror stories and woes for several years. In 2014, the “2015 deadline” for Python 2 deprecation was pushed back to Jan 1, 2020, so it’s once again starting to loom large.

I came across this little gem which may be one reason why so many people didn’t try to upgrade to 3 from 2…

The round() function rounding strategy and return type have changed. Exact halfway cases are now rounded to the nearest even result instead of away from zero. (For example, round(2.5) now returns 2 rather than 3.) round(x[, n]) now delegates to x.round([n]) instead of always returning a float. It generally returns an integer when called with a single argument and a value of the same type as x when called with two arguments.

So any code you had that relied on ’round’ function in Python 2 would automatically work differently when moving to 3. That may be a lot of code to audit/test/change!

(Edit: have learned this pattern is “banker’s rounding“. Still not sure it warranted such a change (or why the algorithm wasn’t pointed out as “banker’s rounding” in the change docs I’d found).

Similarly, “print” was changed from a statement to a function.

2.x: print "The answer is", 22 
3.x: print("The answer is", 22)

The 2.x style simply doesn’t work in Python 3. Again, that would be a hell of a lot of code to review/audit/upgrade, for no functional benefit.

Have you made the jump to 3? Did you just start with 3? Did you have to do a migration? Was it as bad as it sounds?

js promises are the new threads

Years ago I read that ORM was the Vietnam of Computer Science… That was certainly not the first time I’d read a pithy comparison, but it stuck with me.

I had lunch with a friend last weekend, and reminded him of a lunch many years earlier. This was probably… 2008. I’d picked him up for lunch, and our lunch was cut short with “I gotta get back – we’re having some major thread issues on a section of the code, and we’re behind on getting this shipped”.

This was Java, and it was 2008. There were behaviour bugs that no one could track down outside of “this is a threading issue”.

It came to mind because I was recently (the day before) dealing with some inherited JS that was heavy on deferred/promise/async/callback stuff. Guess what? Something wasn’t working. In the course of adding a new feature, I stumbled on something that looked like it’s been non-functioning for months, if not years. Low priority UI thing, but… frustrating.

I spent time trying to track it down – no luck. I reached out to one of the guys who wrote some of this, and has used the codebase (and built on top of it) for years. At first he thought it was a misunderstanding on my part – I’m new on this project, and that’s been the pattern. “Oh, Mike just doesn’t get this”. 10 minutes later I got something like “this is baffling – it’s just not working”. He spent another half hour or so trawling through everything he could think of. No joy.

I write this not with some great words of wisdom, or some silver bullet to cure everything. You use JS frameworks, you’re probably going to be using some degree of callbacks. But… in my old age, I may be more of a luddite than earlier. I avoid callbacks when possible (and again, I know it’s not always possible). But as I get older, I’m trying to optimize for clarity and understandability, and I don’t think promise/callback style development aids that, not on its own, anyway. You have solids tests, sample data and documentation around the code? Go for it! Absent those (which most people don’t do) it’s a harder sell for me.

And… 10 years ago doing Java, I shied away from reliance on threads wherever possible. Bottom line, to me, it’s just difficult to reason about. And, from what I’ve seen, it’s actually difficult for other people too (multiple anecdata from 20+ years of various development work). I’m just not sure people recognize that something is actually adding some potentially unneeded complexity and that is difficult to reason about and test, vs something just being difficult because it’s, perhaps, somewhat new to them.

Again – these tools all have their place, but I tend to view these as necessary evils vs “go to” first practices when architecting something.

misophonia, ears and colored noise

Sorry… couldn’t think of a better title!

Years ago I self-diagnosed with misophonia. Certain sounds trigger me in to difficult-to-control feelings of anger. I’d stop short of using the phrase ‘rage’ exactly, but when others use it, I know what they’re meaning. This started with sounds of others eating food (and oddly, even my own eating sounds on occasion, although that’s not common) when I was a child, and it’s been a steady thing since then.

Normally it’s crispier things – chips, crackers, etc – which trigger the reaction, although chewing with an open mouth is another trigger, as well as gum-chewing.

One big thing that helped as I was growing up was simply my own ability to control my environment. Being able to leave a table for a few moments is often enough to get things back to normal (in my head), and my condition is nowhere near as debilitating as it is for others.

Over the years something else that became a trigger is road noise – large trucks driving past – loud engines, motorcycles, rumbling, etc. Unfortunately, we live close to what’s become a main thoroughfare in our county – one of the few ‘cut through’ country roads which was basically untravelled 14 years ago. We’re fairly close to the road – only 4 houses in – so this has become more of an issue for me over the past 8 years or so.

The biggest help has been wearing earbuds running a whitenoise generator to help get to sleep. I had weeks where I couldn’t get to sleep at all, and it became a nightmare to deal with. Unfortunately, sleeping with earbuds tends to destroy them – I went through a couple of pairs of Bose QC20 (noise cancelling earphones which are a godsend for misophonia folks) before deciding to stop sleeping with them. I now get cheap $4 pairs from the dollar store and they last a couple of months. They’re samll enough to allow for sleeping on my side, and can get buried deep enough so as not to require loud volumes.

I’ve used this whitenoise app for years, and eventually upgraded to the paid version. There’s not much difference, but for all the relief it’s provided over the years, the authors deserved the few bucks it cost. They also have a desktop version I use (with the QC-20) for day to day work stuff at the office. The combination has really been a life-changer for me, and if you’re dealing with misophonia, consider it if you haven’t. Earbuds, whitenoise and a degree of autonomy to change my surroundings when needed has been instrumental in dealing with this. And yes, even changing house surroundings – we’ve been looking to move for a bit now, and sound is a primary consideration for the next house.

So… colors of noise? What’s that? I know people know the term “whitenoise” and I’ve been using it as a general term for ‘masking/hissing noise’, but I usually use brown noise, or a mix of brown/grey, in the app I mentioned earlier, and it’s quite … soothing? White noise itself is rather “tinny” to my ears, and actually hurts a bit after a few minutes. I can listen to grey or brown for hours, often with mixing in some rain or thunder sounds, and it’s fantastic. There’s multiple ‘colors’ all with different frequency characteristics – this article describes them in more detail.

If you’re dealing with misophonia, you have my sympathies. The reddit forum, as small as it is, has been one of the few social places where I’ve found you can find some support. Good luck to you.

early games

so… it’s late at night, i can’t quite sleep, and … been having some weird nostalgia semi-dreams. a few in particular harken back to the days of early 80s gaming. others had apples and ataris and commodores and TI systems. My first computer was a sinclair zx81. w00t!

my recent insomnia led me to poke around, and found a blog post from someone who’s championing ‘tiny games’. These are what we used to call ‘games’: entertainment programs that could fit in to 1k of RAM. For me, early on, that was always done in BASIC, and you couldn’t do much with BASIC (but you could with 16k of RAM – lots of fun stuff from those times, all things considered). But many people could do fascinating stuff with machine code, and you’d get interesting games, and they’d feel much like some of the examples this guy has posted.

He’s converted at least one to JavaScript, so you can play in your browser: try ‘tiny ski’ and see what you think. Except for the fact that this runs amazingly fast, this was my ‘gaming’ in the early days. And it was damn fun.

There’s youtube videos of some ZX81 games, although a) I never had any of these (I just remember seeing some in magazines but couldn’t afford to buy them) and b) none of them ever looked this clear on a CRT home TV and c) I think a couple of these were done later than the early 80s (not sure, but the graphics look ‘too good’ for what I remember possible in 1982).

and on that note, I will try to get back to sleep… zzzz….

Recent tech interview misstep

I’ll clarify a couple things – I’m not sure this was a misstep entirely, but felt awkward in the moment. And… this wasn’t a ‘job’ interview, but a short term contract I was interviewing for. Freelance/contract ‘interviews’ typically are looser than a full on ‘job’ (for a variety of reasons I may get in to later), but it happened that they’re basically looking for another pair of hands for the short term, and there’s already a pretty technical group of folks I’ll be working with, and they wanted some ‘real life’ interaction.

I was given a link to coderpad, and was also doing a voice call with one of the other chaps. The core task was to take a given array of data, pass it to a function and do some calculations. Outside of some date sorting (which I’d just noted up front I wasn’t going to bother with because there were no helper libraries available to deal with date complexities during the session), I had the basics working in a short time.

There were some ‘further challenges’ listed below the main exercise, mostly revolving around how to handle error checking. This was the ‘misstep’, potentially. Given that we were dealing with nested arrays, in PHP, I made some basic helper functions to check for the existence of particular keys, and would throw an error if the key didn’t exist.

function checkValidKeys($array) 
{
if(!array_key_exists("bar",$array))
{
throw new \Exception("blah");
}
}

The chap on the phone asked if I knew about ‘coalescing’, and my brain jumped to SQL “COALESCE”, which didn’t quite jive. I stumbled for a moment, then he typed in the ?? operate in PHP…

$foo = $array['foo'] ?? null;

This is a new operator in PHP, since 7 (which, admittedly, isn’t that ‘new’ anymore), and I’d indicated that I’ve not used that before. Variety of reasons, some to do with “regular habits”, and some to do with the fact that some of the projects I’ve been triaging in the past year are still PHP 5.5 and 5.6. I’m often jumping between styles and environments, so adopting the newest features isn’t always an option.

However, I pushed back a bit more, based on the situation, and indicated I probably still wouldn’t use that technique in these situations. Why not? If ‘foo’ isn’t present in an array, for the situation presented, that’s probably a Bad Thing (TM), and represents an exceptional scenario to be dealt with. I countered that I’d more than likely use a specific object type (FinancialRequest might have fit for the sample in question), which would give me a better idea of property names available and expected, and the object itself could do some sanity checking as well.

This was the ‘misstep’, so to speak – pushing back on someone during an interview. I’ve not actually gone through this situation in a long time, and the last time I did it, I was not brought on board (I got in to a rather testy back and forth with someone about MySQL indexing interviewing with a team at Zappos years ago, which apparently didn’t end well – or maybe it did?)

I guess it went well enough, as I will be starting working with that team on a short term basis next week.

tax rounding

Just a quick … issue with tax rounding. I’ve put together a ‘bespoke’ commerce system, and have integrated taxjar with it. However… i’ve also had to import orders from bigcommerce, and the bigcommerce store is using avalara.

A charge of 13.28, with 7.25% tax rate, gives .9628, which, going through rounding, gives 96 cents. The info coming from the bigcommerce/avalara shows 97 cents, causing no end of stupid frustration.

Similar example at this link shows an example in Maryland, and avalara’s answer is something to do with Maryland “brackets”, but there’s not a good way to tell which states (or perhaps even which counties in various states do this. Using a ‘per line item’ call to any tax service will get expensive, and the rounding (round half up on a 5) has worked decently with taxjar over the past several months (the numbers we calculate match what they calculate). I’m reluctant to change much of anything, but for parity with the bc/avalara duo, I might have to. Changing round() calls to ceil() calls is probably enough (or… something like ceil(x*100)/100 perhaps) but… argh…. not really a problem I want to be dealing with.

Just felt like sharing…

Sunshine PHP 2019

I just got back from the http://2019.sunshinephp.com conference in Miami. This was my second time (went back in 2015) and … it was as good as the last time (better for me in some ways, which I’ll go in to here).

The hotel itself has undergone a pretty big internal change. The hotel is much more modern now – the atrium at least – the rooms seemed like they did before; nice suites, but they didn’t seem like they’d had a radicalized overhaul like the atrium.

Conferences are different experiences for different folks. Years ago, conferences were more about learning tech at sessions. Being able to soak up so much info from experts was valuable. As time goes on, for me, the conferences are more about people and connections, not so much raw tech.

One of my goals was to connect with more people I didn’t know. I’ve got a list – some of you will be getting emails from me to followup. If you didn’t get one from me, and would like to connect, email michael@kimsal.com 🙂

Some great vendors/sponsors as usual. JetBrains, Twilio, RingCentral, RIPSTech and more. I got some great hands-on demos and assistance from Manik with Nexmo on the TokBox platform (thanks again!) Caught up with David Stokes from MySQL. We first met in Nashville’s SEPHP conference, and he was generous enough to give me a small autographed book 🙂

Great to catch up with friends like Cal Evans and Josh Holmes (both of whom I first met in … 2008 at CodeMash all those years ago!) and hopefully have made a few new friends to see again at tech events in the coming years.

If I have time, I may update this post with a few more thoughts and pictures, but wanted to get a little something up now so I don’t forget. If we connected there, feel free to leave a comment here or reach out by email!

Oh… and thanks to Adam Culp for all the organizational effort he puts in to this event. Seems to be a labor of love, and it sounded like he’s got some more ideas for next year already!

Excel to MySQL service

About 10 years ago, I’d built an ‘excel to mysql’ service. I let the domain name go, and had run in to programmatic issues. 10 years later, it’s still a problem that I need to address now and then, so I’ve revived a basic version. Feel free to have a poke around, and if there’s some interest, I may build this out more.

Excel to MySQL link

There’s loads of stuff it doesn’t do yet, but if the demand is there, I’ll make it do more. 🙂

Feedback appreciated.

New dev habits

In the last 2-3 years I’ve started to kick off more projects with Laravel 5 vs other toolkits. There’s been a variety of reasons for this, which I’ll likely blog about in the next few months. For starters, it was mostly just as an experiment to get some experience and compare/contrast with other experiences. There are still bits I don’t care for (as with any tool) but there’s a couple of bundled conveniences which have influenced how I build code.

The ‘tinker’ REPL provides a good balance between quick ‘lemme check this code’ and keeping all the framework bootstrapping and autoloading stuff in place (vs just writing a file and running it via php cli). I’ve built CLI bootstrap processes in the past which accomplish some of this, and having this already bundled with the toolkit provides more convenience.

Relatedly, the ‘console’ command structure and support being bundled has had an impact. And when these tools already bundled and there’s little configuration/setup I need to do, I tend to use these more.

FWIW, this isn’t meant as a “pro-Laravel” post – I use it and like it, but also realize this is bundling tools and concepts that already existed (IIRC the Laravel console stuff is primarily built on the the Symfony console code, which, again IIRC, I think is using PsySH as its base?)

So… how have these helped? They’ve made it easier for me to think in terms of smaller, reusable code blocks. By knowing I have a documented and fairly easy way of using code X both from the CLI and from web request, I find myself thinking and coding with that reuse in mind from day one, vs looking at existing code and thinking about how to refactor it to be reusable.

That said, phpunit has always had that effect, but I don’t often find myself thinking in terms of test stuff at the beginning of a project. That’s where tinker tends to come in.Being able to jump to a command line and exercise some small bit of code first, before the ceremony of tests and associated setup, has been a big help for how I work. Side note: I’ve recently just switched to ‘tinx‘ to allow for faster context reloading when inside tinker.

Between moving to PHPStorm years ago, and tools liker tinker, phpunit and psysh, I’ve felt more productive and able to provide more maintainable code. Even though I still have a ways to go on the discipline of sticking to things (never feel like there’s enough tests on projects, for example), having this growing ecosystem of PHP tooling and community has had a big impact.

PHP now vs 2009

I’ll start by saying these aren’t quite ‘new’, but I’ve not written in a while, so thought I’d throw a quick update.

In the past 3-4 years, I’ve re-engaged with PHP. I started with PHP in 1996, and while I’ve never *not* done PHP, I spent several years in the Java world. I started some Java projects in 2009/2010, and the PHP landscape looked pretty different back then. Looking at PHP 5.2, maybe 5.3, the speed was… meh, tooling was always getting better, but not great, and there felt like a lull while the community decided on what PHP’s direction and future might be.

During that time, many other tech/frameworks were gaining momentum – nodejs certainly, and Rails was maturing and gaining some traction as well.

A few things changed in the intervening years – PHP7 and composer. These two really changed a lot for me, and for many others, and I started more projects in PHP than in other tech stacks, and I’m glad I did.

I don’t expect PHP to rival C or Java for raw speed any time soon, but for regular web app stuff, the speed has been improved a lot from where it was in 2009. Comparative benchmarks show PHP7 2-3 times the speed of PHP 5.2/5.3, and PHP7.3 is, from what I’m seeing, roughly 4x (and in some cases 5x) faster (at regular benchmark tasks) than where we were 10 years ago.

Speed is useful, and reduced memory consumption is great, but the composer universe, even with some flaws here and there (I may write about some niggling bits in the future), really transformed how most professional developers use PHP. There was a recent PEAR compromise, and I was … amused? not surprised really – to read so many comments from folks asking “what’s PEAR?”. Maybe one day they’ll ask “what are globals?” or “what’s mysql_query”? 🙂

I’ll be hitting the Sunshine PHP conference in Miami Feb 8 – just a couple weeks from now. If you’re going to be there, give me a holler and we’ll grab dinner or a drink and wax PHP, development and everything else 🙂