Archive for the ‘Uncategorized’ Category

MVC Podcast

September 5th, 2015 No comments

So, my good friend Victoria​ and I made a podcast. We call it “MVC” (Marty and Victoria Conversations). We wanted an excuse to talk once a week about various tech news for nerds. In this one, we talk about topics like:

  • Do you need to be good at math to learn to code?
  • the Ashley Madison hack
  • removal of Flash from web browsers
  • a few other things.

    It’s pretty “version 1.0”: not perfect audio, kind of long and rambly (around an hour), more than a few “ums” and “uhs.” We’ll try to do shorter ones in the future. But we thought we’d post it anyway in case anybody enjoys it. We fully expect this to be one of those “only our moms and S.O.s listen to it” podcasts, but we’ll see. :-)

Categories: Uncategorized Tags:

There’s something about YAML

August 16th, 2015 No comments

When you’re developing an app, you often run into the problem of needing to store structured data in some format. The crucial thing is that you absolutely cannot just make up some dumb format of your own, like:

# marty's homemade file format
# (now I get to write code to parse it from scratch; yay!)
server = "localhost"
email = ""
buddies = {

Many years ago I settled on XML as a nice standard file format. XML is basically HTML except that you can use any tags or attributes you want. It’s easy to understand if you know HTML; it’s nicely rigidly structured and can be validated if you create an XML schema specifying which tags/attributes are allowed where.

<?xml version="1.0" encoding="UTF-8"?>
    <!-- Marty's data in XML -->

XML has served me well for many years, but it’s a bit cumbersome. To pull the data out of the XML file, you need to use the XML document-object model (DOM), a set of classes and methods for talking to XML data. The good news is that the XML DOM is mostly available and standardized across lots of programming languages. The bad news is the the XML DOM is verbose and kind of clunky to use. To pull the buddies out of the above stuff, you’d have to write code like:

// this is mostly Java
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputSource source = new InputSource(IOUtils.toInputStream(xmlFileText));
    Document doc = builder.parse(source);
    Node settingsNode = doc.getElementsByTagName("settings").getChildNodes().item(0);            // ...
    Node buddiesNode = settingsNode.getElementsByTagName("settings").getChildNodes().item(0);    // ...
    NodeList buddies = buddiesNode.getElementsByTagName("buddy");
    for (int i = 0; i < buddies.getLength(); i++) {
        Node buddyNode = buddies.item(i);                                                        // ...
        String arrrrrrrrrrgh = buddyNode.getTextContent();                                       // "Allison"  (finally!!)
} catch (Exception e) {

So, that all works, but it can be kind of a pain. A lot of folks using web apps have switched their data into JavaScript object notation (JSON) format. JSON is the cute idea that you should just declare your data as a JavaScript object literal, as a map from property/field names into values.

// Marty's data in JSON (a comment isn't legal here but oh well)
    "server": "localhost",
    "email": "",
    "buddies": {
        {"name": "Allison"},
        {"name": "Helene"},
        {"name": "Katlyn"},
        {"name": "Mariana"},
        {"name": "Zorah"}

JSON is a nice format because if your language knows how to parse JSON, you can usually just turn the data into a nice nested object and access each property directly, something like:

myJsonData["buddies"][3]["name"]   // "Mariana"

In some recent work on my Practice-It web app I was getting sick of a glut of XML data the app uses. One annoying thing about this particular data was that a lot of it was HTML snippets. The app uses XML files to describe programming exercises, each with an HTML description and a Java code solution. So I had things like:

<?xml version="1.0" encoding="UTF-8"?>
        &lt;p&gt;Write a method named "max" that accepts two integers and returns which one is greater.&lt;/p&gt;
        &lt;p&gt;For example, the call of &lt;code&gt;max(12, 47)&lt;/code&gt; returns &lt;code&gt;47&lt;/code&gt;.&lt;/p&gt;
        public int max(int a, int b) {
            if (a &gt; b) {
                return a;
            } else {
                return b;

Notice how I have to HTML-encode the description and solution because you can’t have the < > characters inside a tag in XML. It’s just a pain to have to HTML-encode everything and carefully nest all of it inside the XML.

JSON wouldn’t be much better; all the property names/values have to be quoted and JavaScript-string-encoded, and multi-line values are crappy, so if I were to convert the above to JSON, I’d get muck like:


Write a method named \"max\" that accepts two ints and returns which one is greater.


For example, the call of max(12, 47) returns 47.

" "solution":"public int max(int a, int b) {\n if (a > b) {\n return a;\n } else {\n return b;\n }\n }" }

Doesn’t seem much better to me.

ENTER YAML. YAML is a data markup language commonly used with Ruby on Rails apps for config files and things of that nature. I’ve seen it called “the Python of markup languages”, which is a great description. Its syntax is brief and bare, using name: value pairs along with spaced indentation to indicate nesting. You can indicate a multi-line value with a | or > character. Look at this loveliness:

# This is YAML, MFers, awwwwww yeah
    description: |
        <p>Write a method named max that accepts
        two ints and returns which one is greater.</p>
        <p>For example, the call of <code>max(12, 47)</code>
        returns <code>47</code>.</p>
    solution: |
        public int max(int a, int b) {
            if (a > b) {
                return a;
            } else {
                return b;

Not all languages include a YAML parser, but I found a small Java library that turns the YAML data into a nested Map<String, String>, which is fine for my purposes:

Map<String, String> yamlData = FileReader("mydata.yaml"));
String solutionCode = yamlData.get("problem").get("solution");

It’s just so clean and simple and nice. I’m in love. I’m planning to create most of my new problem data files in YAML rather than XML from now on; it’s just so much faster and cleaner for me to author the files.

YAML isn’t perfect. One issue is that it can be tougher to verify that a given YAML file matches some exact schema. So I think YAML is currently best suited to data that comes from a trusted source; in this case, the data is authored by me, and I trust me.

Categories: Uncategorized Tags: , , , , ,

A few code style conventions I’ve adopted

April 16th, 2015 No comments

I write a lot of code, and here are a few little stylistic things I try to always do now.

1) Mandatory comment when passing boolean flags or weird random args: I learned this one when interning at Facebook. What’s the third arg here??

processDatabase(server, "Users", true);

No more mystery flags! You must comment it so I know what the heck I’m passing and what it means.

processDatabase(server, "Users", /*overwrite*/ true);

2) Mandatory comment on an empty block: Sometimes I have an empty block or empty loop or whatever. But here’s one in my code; did I mean to do that? Is it a bug? Just comment it and be sure. Got this one from Eric Roberts.

// should this ctor be empty?? (bad)
public FluxCapacitor() {

// this one is better
public FluxCapacitor() {
    // empty

3) Author/version comments on files: It seems like a simple/obvious thing, but just tagging my files with my name and when I last modified them has helped me a lot with “is this the newest copy of this file?” issues. I also put in what I changed between each version.

 * ........ (description)
 * @author Marty Stepp
 * @version 2015/04/15
 *  - fixed bug with null pointer in query function
 *  - alphabetized function names
 * 2015/01/29
 *  - added getRandomBlerg() method
 * ...

4) Two-letter for-loop counter variable names: It’s a nightmare to search for “int i” in your code. How about two letters?

for (int ii = 0; ii < 10; ii++) {
    for (int jj = 0; jj < ii; jj++) {

What are some little style rules that you love to follow in your own code?

Categories: Uncategorized Tags: