This is lovely and I want to share it

I ran across this JSON tutorial that I think is going to be really helpful. (Yes, I’m still messing with JSON.)

It looks like the site has a bunch of other useful tutorials and stuff. Definitely worth a bookmark if you’re learning Python. I don’t see a Gittip button, so hopefully I can pay the writer in a little well-deserved publicity.

Happy hacking!

Design sense, belatedly triggering

There’s something pretty sucky about the way I’ve been structuring tinypapers. It’s getting too spaghettti-code-like. A line I wrote a few days ago to solve a problem made me feel uneasy (I think I mentioned this already somewhere?) and I couldn’t find a different approach. Then there are these more recent issues that have been making me twitchy. My design sense finally put two and two together… there’s some funky stuff going on I need to fix.

Anyway, I’m going to have to spend a day or two refactoring (and, where possible, minimizing) the “power” structure before it gets any more complicated. I just sat down with an actual pen and paper (magical tools) and it’s pretty obvious that something isn’t right. Hopefully the visual aid will help kick me into solving what’s wrong.


(several hours later)

Kivy is really confusing about this, though. Because child structures and inheritance are mostly defined in KVlang rather than Python, ordinary design patterns don’t… quite work. I’m in a better position to figure this out now than before I wrote any code, of course.

Here’s the structure.

I’ve got one class (widget if you’re speaking KVlang) which controls which of the other classes is being displayed. I’m calling it a window manager. Of course, in each of the “child” classes (which don’t actually inherit anything from the window manager), there’s at least one button that’s supposed to trigger the window manager and make it display a different page.

You can’t just randomly call them from other classes. The page-switcher methods need an instance of the window manager to work. And I can’t just put the page-switcher methods in the child classes. The reason the window manager exists is that it’s the only part of the program that knows how to do that sort of thing.

So, there isn’t… really a hierarchy in the Python file. It’s mostly just there to define any logical back-end that the KVlang file might need.

The KVlang file has hierarchy all over the place. It basically declares everything.

Anyway, I’ve got this window manager. Underneath it I have the main page that lists categories of documents (“Business Cards”, etc) and each of those categories has (will have; I’m only working with one right now) its own instance of IndexPage to display the documents in that category. Each category also has an Add page for new entries.

It’s not that complicated! It shouldn’t be this complicated! It’s still complicated!


(an hour later)

As you can tell, I’m still getting my head around Kivy.

Basically, whenever you need to do stuff that crosses over different classes, you have to make your method calls in Kivy. Kivy keeps basically all the class instances in memory. This gets kinda tricky if you lose track of things though.

I do need to clean up the Kivy inheritance… and then stop bashing my head against trying to make things happen in the Python file that just can’t happen in the Python file. Sigh.

Frustration and solving problems in the shower

I’m really wary of how dangerous it is to my productivity to write blog posts every day, but there’s a reason I don’t stop–which is because it only looks/feels dangerous. As leery as I am of sitting down and writing for two hours every day like this, I know that if I denied myself the time to swap out what I’m thinking, I’d have a lot fewer ideas for solutions.

I am just DYING for a cofounder with a real working knowledge of Python. I really like programming… but I don’t feel like I’ve ever gotten to a point where I really, truly understood it, and I’ve been absolutely unable to find a teacher, and the Internet isn’t as useful as one might think if you don’t know the right questions to ask, or the right way to phrase the questions you have.

I’ve run into this sort of problem before, and tried to fix it for other people (see the post “How I Learned Linux”). I guess it’s inevitable that I’ll write “How I Learned Python” and include all the stuff I’m bashing my head against now.

And it’s really stupid stuff. Like, I know full well that anyone who’d written an actual application (I don’t mean little scripts or toy programs) would be able to answer my questions in an instant if they were standing over my shoulder. [Edit: actually, they wouldn’t; my problem was more obscure than I thought.] Alas, there is no one standing over my shoulder; alas, I don’t know if I can describe my problems.

I think I might need to go trawling through some Python source of an existing program. The trick is finding an example that shows me what I need… argh.

This is one of the things I like least about living in Iowa. I live in a fairly mellow little city where the people are friendly and the Oriental food is excellent. But it’s not really a college town; we’re short on programmers. Oddly enough, I’m kind of missing a few guys I knew in high school who would have made really good cofounders. I wonder where they are now. Probably MIT, they were really smart programmers. (I had crushes on both at different points; it didn’t hurt that one was really physically attractive and the other was adorably nerdy.) Eli, Gordon, drop me a line if you’re reading this.

The problem I’m having right now–although it isn’t by any means the only one I’ve come across or the only one I’ll have, or even the only one I’m having now–is a dumb little OOP-type issue.

When this one button is pressed, I need other widgets to react to it. I have methods in those widgets’ classes that provide the reaction instructions, but one of their required parameters is an instance of the class they’re in.

I think the problem I’m facing is that the application is re-rendering the widgets that I need names for every time they’re constructed, and I don’t need it to do that. I think maybe there’s a way to do this with Kivy’s ObjectProperty stuff, but I haven’t gotten it to do that yet. I’m sure I’ve seen it before… but I don’t remember where or how. I think it was the Kivy book, but I might be wrong.

Actually, it’s not a dumb OOP issue. It’s a Kivy issue, and I can forgive myself for not knowing what I’m doing. In Python you’d be spelling things out manually and you’d have the objects available to pass. I think this is why I was having trouble finding Python source examples.

tfw you need to have a little more faith in yourself

And once again, having written out a blog post helped me solve the problem. That and taking a shower in the middle of writing this. It took me a lot longer to write this than it looks like; I spent a lot more time chasing thoughts in circles than typing.

To be honest, I was able to get the app to do what I wanted already, because of the lack of syntactic salt in Kivy. But the solution was really klugey and I didn’t like it [1], and I’ve always been a perfectionist since I was a little kid. The way I forced the app to do what I wanted blurred the lines between the Kivy and the Python code too much for my liking.

But I appreciate that Kivy gives the freedom to do stuff like that anyway; it really helps test things. I was actually going to give up on this for now and move on, but then I remembered the ObjectProperty thing in the shower.

This is still way more fulfilling than the noddy little programs from school. I’m kind of brain-tired and frustrated, but I sprang back from demoralized within an hour or so. School programs and (I’ll assume) work programs don’t have this factor that brings me back from demoralized. This is why I want to start a startup.

I guess the lesson here is that I need to be a little easier on myself. I mean, I’m an 18-year-old girl going into my second year of college. It’d probably be my last semester if I’d taken classes this summer, and even so I’ll probably graduate before I turn 19. I shouldn’t doubt my intelligence.

I probably shouldn’t be so hard on myself about my pace, either. I know from empirical evidence that when it comes to stuff like this, I’m a persistent little snot. (On multiple occasions, this was to the frustration of school officials.) I don’t mind changing my approach if something isn’t working, but if I want to do something, there’s not a lot that can stop me. I never let high school tame me. I tried to tame it instead, and when it stubbornly resisted, I took the advantages I could from it (about $2000 of free college, I think) and then left.

But, arrrrggggghhhhh. I want to go faster. There are features I want to implement. Grr.

I’ve been fighting this thing all afternoon. It’s time to take a break and maybe get some food… I don’t think I’ve eaten for five or six hours, so dinner and a few rounds of 2048 or something are in order.


[1] I have no idea where my sense of design in programs came from. Certainly not experience. I do know that I can’t remember anything I’ve ever written under Windows has triggered its appeal switch (probably because those programs were all for class and most were written in Visual Studio).

“Add” There Was Much Rejoicing

Yes, that was a pun combined with a Monty Python reference. I know, I’m awful. tinypapers IS written in Python though.

I wrote the UI skeleton for tinypapers’s most basic “Add” page, and a little more back-end stuff for switching from screen to screen. It was pretty easy, actually! After that ListView nonsense, I was kind of expecting another fight with Kivy… which of course made it harder to start working on something else. I guess I wanted to savor the victory for a few hours before I broke tinypapers again! XD

Basic Add Form

Also, the Back button works now.

I guess I’m ready for the next big hurdle… which is going to be integrating the camera. Kivy is said to  handle this gracefully, but I don’t know how it’s going to work when I test it on my laptop. I have a functional webcam… I guess it’ll use that?

My first phone app

I’m really wishing for a more experienced hacker to help me with this. Or at least another smart 18-year-old. (Hey, Steven, you want in on this?) I’m having issues figuring out where to start, and this platform is so foreign that I’m not sure how to do things like work with files. On a normal computer? No problem. On a phone, working with the Android OS? Uh… not sure. But I’ll figure it out.

I’m working on a phone app that will store all those little bits of paper people shove in their wallets. No, not money–I’m talking about business cards, receipts, scribbled addresses on the backs of envelopes, notes to self, maybe checks (for those people who have the banks that support sending in a picture–this would have to be password protected), coupons downloaded off the Internet… stuff like that. And all the metadata you’d need, like when you added that business card to your collection, whose name is on it, what business it describes, etc.

I’m also thinking that maybe it should use a light compression algorithm–I mean, if it’s gonna store all this stuff locally, which I would like it to, because it’s convenient that way and I don’t want to pay for a server to do it for me. Or I should just make sure it’s not storing huge, high-quality images like the camera likes to do; they should at least be resized to like 250×400 pixels instead of 1250×2000 or whatever the camera does automatically. Maybe if it catches on, I can get some VCs to back me and I’ll buy a server and allow people to pay for cloud space.

I’m using Kivy to develop this, because it’ll let me program in Python rather than Java, and it has a lot of other neat features I like. (Yeah, I can see where Lisp’s macros might be useful here, but I’m going to stick to OO stuff for now. Especially if I want to actually find someone who’ll work with me.)

I think people need this app! I’m going to sneakily develop a dedicated user base of everyone I know before I start really touting it and drawing the attention of companies that might copy me. It’s hard to fight the force of users who’ve already learned to use something that subsequently made their life easier.

My dad definitely needs it :/ Not just his wallet but also his car is always full of little bits of paper, because he runs a stump removal service.

I want to keep the design and interface as simple as possible. I can see the possibility of something like this turning from lean and neat and space-efficient to bloated and confusing.

I’m not sure whether I want to keep this to myself and maybe a friend and develop/release it by myself/ourselves, or if I’ll throw it to open source. I don’t think it’s really meaty enough to benefit much from open source… it’s such a little, simple idea.

I have no money for this project, I’m the only developer, and my prospective clients are myself and my friends/family/teachers. The communication overhead is an advantage (i.e., the lack of one), at least. And I’m also not working under a deadline, although I’d like to have something running and usable for people to play with when I go to TechWeek in September. I bet I can get a good chunk of this thing done by then, even with the learning curve I’ll go through.

Anyway. Time to start really hacking, I think I’ve got a good basic design down on paper.

Oh! One more thing. I’ve got a name for it now! It’s called tinypapers. It took me a while to come up with that because the purpose of this thing has changed drastically since I’ve been mentally designing it for a few weeks.

A few more projects

I’ve started teaching Python to my 12yo. brother Ben. He picks it up really quickly and asks the right questions; his problem is that he doesn’t make the mistakes that the Python book keeps trying to get him to make, the ones he’s supposed to learn from. He’s already meticulous, so if I don’t intervene and point out all the ways you can screw up a program, he won’t have the experience of knowing what it looks like when you do make stupid mistakes. Because everyone makes stupid mistakes in programming. It’s just a thing that’s going to happen, no matter what.

So far, the design patterns book I’ve been reading has covered the Strategy pattern, the Observer pattern, and the Decorator pattern. I like Strategy and Observer, but I don’t like Decorator. I keep getting this feeling like… I would do it differently, use more of a Strategy-shaped design. The book keeps talking about a “Factory” pattern; maybe that’s what I’m thinking of but can’t pin down. I just don’t like Decorator on its own. It seems kind of unnecessarily complex… obtuse… clunky. Maybe I’ll like it when combined with Factory, or maybe I don’t understand it well enough to get why you’d want to do things that way.

Meanwhile, the book is teaching me more about OO principles than any programming book I’ve ever seen. Between Head First Design Patterns and Google, I’m seeing a lot more of what you can do with objects via example than is ever really explained in other contexts. School teaches you to type

public static void main (String[] args) {  }

(or equivalent for non-Java languages) but never actually shows you a program where you use publicly-accessible methods from another class; I’m still not really sure what static does. They teach you what classes and objects are–sort of–but don’t teach you how they can really be used. They don’t teach you what an interface is, or how libraries actually work. They teach you syntax and how to solve toy problems. I have a feeling I’m going to end up teaching some other new programming grad I’ll have to work with about everything the classes missed. In fact, if I can find the patience to type these things up, maybe I should post them here.

I can see my own progress by the fact that the source code for Tetravex, which I downloaded on my Debian VM, is now magically understandable. Not sure how that happened, but there are a few bugs I want to send in a patch for–if they haven’t already been fixed. If I do that, it’ll be my first contribution to open-source. 🙂

Design Patterns

After taking a kind of quick course in some of the finer points of OO programming, I’ve come back to the design patterns book I had my mom buy for me recently.

It’s this one:

Head First Design Patterns cover


(Clicking the image will take you to its Amazon page, where you can buy it for yourself if you want.)

Oh, a note before you do that, though. All the code examples are in Java, so you need to either be reasonably familiar with Java and its syntax, or with a similar language like C++ or C#. Although, quite honestly, if you’re familiar with some other OO language and clever enough to recognize patterns, I’d say you’ll probably be fine; take note that I haven’t finished the book, though.


I have to admit that sometimes I get bored with coding. Usually, this means one of two things:

1) I’m too stressed or burned out from working on other things, and my motivation for doing ANYTHING is next to nonexistent, let alone my motivation to work on complex intellectual activities like coding; or

2) I’ve been working on something that’s either too easy or too difficult, and I’m getting bored or frustrated, respectively.

I was getting pretty bored of working with the Python book. I found myself skimming stuff, wishing Shaw would just get to the point already… I think I’m finding that the point where you can just look at code and immediately see what it does means you have to move on, because you’re sitting in a kiddie sandbox. My 12-year-old brother will really find the book interesting, especially the simple game engine near the end, which was supposed to be one of the major final projects–but since I spent a lot of time when I was 12 fiddling around with RPG Maker XP*, my thoughts were more along the lines of, “Cute. Let’s move on.”

And it was time to move on. There’s a lot of stuff in this new book that I don’t know about, which I probably should know about before trying to get into it… but since it’s the only source where I’m finding any mention of these concepts, I’m just going to glark it from context.

Concepts like what the difference between a class and an interface is, and how the syntax for writing them is different… and then there’s this diagram system they use that I’ve never seen before… what “programming to an implementation” means… How come I’ve taken so many programming classes in OO languages, and they’ve never touched on this stuff?

Does all school work this way? You attend classes that teach you the easy half of what you need to know (or next to none of what you need, if it’s high school) until they’re satisfied enough with you to give you a fancy piece of paper, and then you go home and actually learn all your skills yourself? Mostly I’m annoyed on principle, as it’s not so much of a problem in my case–self-paced learning works really well for me–but it doesn’t for everyone, and that is super uncool.

An interesting thing I noticed myself doing while I was going through the Python book: I had read part of the first chapter of the HFDP book, and not really understood it despite trying very hard to do so, so I went back to the Python book. And as I went through it, I kept piecing together how the design pattern worked. So even though what I’d read was mostly Greek to me, having tried to understand it, it stuck in my mind anyway and I was able to use later clues to get it without even looking back at the HFDP book.

Of course, having returned to HFDP, it’s even a little clearer, although I don’t totally get everything the chapter has to say yet. Since this is a complicated book and I need to learn a lot of what’s in it from context (because I’ve never seen a lot of this stuff before and don’t know enough about it to even form questions on it), I’m doing two runs through the book. The first run, I’m just going to read it and try to understand stuff. I’m almost inevitably going to hit a point in the middle of the book where I get stuck and can’t understand anything more, and after that I’m going to skim. But I am going to go through the whole thing because, as mentioned above, stuff I don’t understand apparently sticks anyway if I wrestle with it enough. I didn’t think it would at first because it seems so complicated, but it does and the skill will develop more if I take advantage of it.

Reading HFDP is an experience. In each chapter so far, they present a problem that requires a design solution and they go through several different ways an inexperienced programmer might approach the problem, pointing out the issues and potential issues in each of them. Then they introduce their design pattern, not only coded properly but sometimes it even has extra features; not stuff that bogs down the code, but simply makes it more flexible. Objectively, but especially by comparison to the other code, the final solution is beautiful.

I don’t know if I can explain what constitutes beauty in code to my non-technical readers (if there are any? you guys must have patience). It can be achieving the best, most flexible results by the simplest, most minimal means possible even when the problem is complicated–in fact, that’s probably the most beautiful of code structures, something referred to as “elegance.” To be told your code is elegant is very high praise. Code beauty can also be achieved through ingenuity and creativity in design, although it’s still very important that the code be readable and maintainable, and most of all it should run. There are other ways for code to be beautiful, though, including code that is intentionally designed to do something ridiculous but actually manages to do it, or code that only works because of a loophole in the way the programming language itself is written (there’s a Jargon File example of this too, but I’m not sure where it is).

Head First Design Patterns’ solutions are the first kind of beautiful, which is the kind most worth committing to memory because they’re the most versatile. That’s the selling point of the book, really; that it teaches you good code structure, templates that are reusable, and then it’s your job to decide which one(s) you want and how you want to adjust it to your own needs.

Anyway, as much as I like writing and hopefully also encouraging other book-apprenticed coders and wannabe open-source junkies, I kinda want to go back to my book. I’m leaving this here for the day.


*If you’re not familiar with RPG Maker XP, think of it as kind of like Scratch (or, ostensibly, Alice, which I’ve never used), but more obscure and difficult to use. The map builder for the graphics part of the game is a lot like using virtual Legos. It runs Ruby, but since I didn’t know Ruby, I just used the game’s interface to generate the code line-by-line; its engine for that is closer to the code than the code-generating tools I normally get irritated with (like, you have to manage your variables yourself). I learned some programming logic from it, and a little bit of work with Photoshop for some graphics, but I never became very good at it. Nevertheless, I hammered away at the thing for hours on end, trying to recreate game versions of scenes from the fantasy novels I wrote (I was a weird kid).