Cognitive Dissonance: Type hinting and linting in Python

At work, the adoption of python 3 was finally moving at warp speed - the end of its support might have had something to do with it. As a result, there was a lot of code to migrate over. One of the things I did during this migration was add type hinting as well as linter checks to the codebase. And I... was not... ready for that! When I first read about type hinting I thought it would be a neat thing to help people new to the language and existing users navigate through code. After all, the language wasn’t becoming statically typed. I figured the hints were, as its name suggested, slight indications. However, combined with static analysis tools, they can actually help you identify bugs and other issues in your code, and I’m all in for that. ...

February 12, 2020 · guidj

Encoding in Python 2 and 3

In this post I an encoding behavior in python 2 and their differences in python 3 If you’re still using python 2, which many folks are, you may run into encoding issues when processing data. Let’s say we have a file called translations.txt that contains translations between English and Mandarin (from the Oxford dictionary): "The book has 500 pages of text.","这本书正文有500页。" "I'll send you a text as soon as I have any news.","我一得到任何消息,就立刻给你发短信。" Now, say we try to read the file in python 2: ...

November 21, 2019 · guidj

Property Based Testing: Describing expected behaviour in terms of properties

In my daily work, I often need to write data pipelines to produce metrics, create datasets for machine learning models, or just clean up logs. I had usually done testing the traditional way, verifying my code does what I expect by checking for normal and edge cases I could think of. But over the past couple of months, I started using property based testing, and I feel like my code quality has improved dramatically. ...

March 19, 2018 · guidj

Language Style Guide

The first programming language I learned was Pascal. I was in my math class in secondary school, and my teacher told us about a programming competition that was held every year between schools. At that point, I everything I knew about programming was a pure construct of my imagination. I knew that you were suppose to type something into a machine and it would do things. But I was into computer hardware at the time, so I figured why not. To be honest, I don’t remember much about the language, or those days for that matter. But I do recall trying to grasp the little quirks about the language. ...

March 18, 2018 · guidj

Relatively Painless Technical Excellence

I have been thinking about excellence for the past couple of months, since I’ve starting working full time again. Excellence in writing code, designing systems, and formulating problems. Last week I had the opportunity to attend a talk titled Relatively Painless Technical Excellence from J.B. Reinsberger. It was one of the best talks I’ve heard on agile and software engineering. I have to start by saying I didn’t have much expectations about it, and I was positively surprised by the content. J.B didn’t talk about frameworks or tools. Instead, he discussed problems and micro-tips. Things we can do in our routine, here and there, to optimize our work for our teams and ourselves. ...

December 20, 2017 · guidj

JsonURI: json serialization and deserialization for logging

A while back, while working on the infrastructure of a ecommerce recommendations service provider, we ran into problems handling traffic from our clients in real time. As a simple solution, we decided to send data to logs through AWS S3, by appending HTTP URL parameters to GET requests to a tiny image file; something that should only be done when you’re not dealing with sensitive data. However, we had a minor issue: we had complex nested JSON objects, with objects inside fields; however, JavaScript and JQuery standard libraries only supported serialization of flat JSON objects. So, to circumvent that, I wrote a procedure to serialize complex JSON objects into plain HTTP URL parameters, and deserialize the result back to JSON. I wrote packages in Python and in JavaScript to have JavaScript client libraries sending data, and a Python app processing the logs. ...

May 28, 2016 · guidj

Programming

The art of writing was invented, I suppose, so that we could communicate with the future, i.e. record the past and present, and in the process create history. Software programs, on the other hand, are written for the purpose of defining the future. One that is meant to be interpreted by machines. The tapping of a keypad turns a blank page into a blueprint. It starts with one file, and can quickly grow larger. Combined, several blueprints become packages. They contain little logical engravings of our expressed intentions. Aggregated, these are translated into binary compatible entities, ready to be executed by little machines living within larger, more complex ones. ...

December 26, 2015 · guidj