Archive for the ‘Coding’ Category

Switched Over to Sublime Text 3 Beta

Thursday, February 21st, 2013

Sublime Text 2

This morning I've been fussing with MacVim and Sublime Text 2 and trying to come to terms with the fact that Sublime Text 2 has crashed on me a few times, and I have no desire to go through that again. I have downloaded the beta of Sublime Text 3, and it appears to be decent - though because it's using Python 3 virtually none of the packages I use in Sublime Text 2 are going to work properly, but at least I get the default behavior, and that's about 95% of what I use day-to-day anyway.

So I decided that it's time to give it a shot, and I switched from Sublime Text 2 to Sublime Text 3 on my main MacBook Pro. This isn't my work machine, but my machine, and as such it's not getting the same number of keystrokes as the work machine, but still… as I work on it I'm hammering on ST3, and hopefully, they will get it out of beta soon, and the Package maintainers will upgrade their code to be compliant with Python 3 and I'll be able to get back all the functionality I have/had in the older version.

Among the new features in ST3 is the extensive use of C++11, and that includes the move semantics which should make for a much more efficient app. I'm hoping to see that the crashes I've had go away, and if so, I'll be more than happy to foot the bill for the upgrade price.

This isn't to say I've given up on MacVim - I just read a message that the maintainer is looking to add the window/file/tab restore feature to it, but that it's "hard", and so I'm not expecting it anytime soon. Should that come to pass, I think I might have a much harder time choosing an editor. Yeah, it'd be tough not to use MacVim if it had that feature. It's such a powerful editor.

Updating Some Vim Tools

Wednesday, February 20th, 2013

MacVim.jpg

Today I decided that I wanted to see what was out there to update MacVim to be something more like Sublime Text 2 - or at least how I use it. Since starting at The Shop, I've come to really like the project-management features in Sublime Text 2 - specifically the ability to find a file with partial filename completion, and the same thing for methods/functions, as working in Ruby has shown me that the standard way of working on Ruby projects is to have a mess of files, all no bigger than a thimble.

But I had a feeling that there had to be something like this for Vim - and therefore MacVim, which I really like - but just need this kind of help with. So I asked my most Vim-savvy friend and he mentioned CtrlP.

Install this guy and a simple Ctrl-P brings up a searchable list - just like Sublime Text 2! This is directory-specific and includes most-recently-used files and buffers as well. It's a real treat. It's fast, clean, and does exactly what I need it to do. I've never heard of it, but it's really quite amazing.

The next real jewel today is VimClojure. This gives me the clojure syntax-highlighting and indenting that I really need to write in clojure in Vim. I'm doing about 90% of my coding in clojure these days, and the lack of a good default mode and syntax highlight for clojure is really something that kept me from really even starting to write clojure in Vim. With this, I'm golden.

I'm super happy with these two, but I really wish MacVim had the save/restore that other Mac apps have for windows and files. The ability to save and restore the state would be amazing and might make it so that I'm back to MacVim all the time. Sublime Text 2 is nice, and I've played briefly with Sublime Text 3 beta, but there's something about Vim and all the history I have with it that makes it exceptionally powerful for me.

I'll keep looking, and these plugins make Vim much nicer, but I'm not yet giving up on Sublime Text 2 - yet.

Google Chrome dev 26.0.1410.10 is Out

Wednesday, February 20th, 2013

Google Chrome

This morning I noticed that Google Chrome dev 26.0.1410.10 was released with another very respectable set of release notes. Sounds like a lot of little fixes, but necessary and advancing the cause of a better browser. I have to say I haven't seen a regression in the rendering or speed in a very long time.

Nice work, Googlers.

Updated Java from Apple and Oracle

Wednesday, February 20th, 2013

Software Update

This morning I noticed that Apple had a Java 1.6 update for the Java exploit that's been going around, and Oracle had another for 1.7. It's interesting how vulnerable Java is these days - maybe because the other, historically more likely, back-door (open ports on boxes), has dried up of late. So the jerks turn to Java, and find problems and exploits there.

Seems reasonable to stay up to date because some Facebook and Apple engineers have had their machines compromised by visiting a hacked web site. Amazing that they can do this from visiting a website, but that makes sense in the context of Java plugins.

Crazy what poorly written software combined with kids with too much time on their hands can lead to. Kinda annoying…

Finally Moved to Java 1.7.0_13 on My MacBook Pro

Tuesday, February 5th, 2013

java-logo-thumb.png

Well… I've really held off about as long as I can, and even then, it's probably a bit too long for what I'm doing. This morning I downloaded the Oracle JDK 1.7.0_13 with the latest security fixes for my main laptop. This is a big switch as I'd been holding out for Apple to step back in and really do Java right, but I think they are past that now, and it's up to Oracle to make Java work on Macs, and I pray that they do.

I'm doing more clojure coding, and with that, I really need to have the 1.7 JDK underneath, as there are optimizations that are done in the compiling if it's on the 1.7 platform. Since we're using that on the linux boxes at The Shop, and I have 1.7 on my work laptop, it makes sense to give it up, and switch.

I guess it's like my 17" MacBook Pro… legacy hardware. I'll move to the 15" with retina display for my next machine, and it's a beauty, and it's nice that it's smaller and lighter with the same pixel count, so it's a win - really, but it's a big change from all the years I've had these 17" machines.

Face the future, Bob… it might not be what you want, but it's all you have.

Google Chrome dev 26.0.1403.0 is Out

Tuesday, February 5th, 2013

Google Chrome

This morning I noticed that we have a new drop of Google Chrome dev to 26.0.1043.0 with some really nice release notes. OK… maybe they are just bug fix titles, with the Jira (?) tracking number, but it's nicer than the SVN commit logs of the past. And I think I mentioned this last time, but it bears out saying again - The update they have done to the page is really very nice. Clean, sharp, nice.

Thankfully, we're still getting a nicely optimized rendering engine so that we're not getting a lot of flash in repainting the same page on refresh. That's a nice touch, I must say.

Cracked the Speed Problem with Postgres

Friday, February 1st, 2013

PostgreSQL.jpg

This morning I put a lot of effort into making the selection of the children from the postgres database faster. There's just no way it needs to be 30 sec. Since I'd already tried the sub-select, I needed to have a completely different approach. Thankfully, I have a lot of ideas, and it didn't take long to find the one that solved the problem.

The problem is that I was always looking in the "wrong direction". I was using IN and joins, when it was really a much simpler problem. Let's find all the demand_id values from the demands table - based on the demand_set_id - which is keyed. This is a very fast request. Then we use that as a cursor to get the locations based on that.

There are a few nice things with postgresql that make this even nicer - like the FOR loop with the select embedded - very nice. Turns out to be really pretty simple:

The difference was dramatic. Now it's about 450 msec for the same load. That's a factor of 60x! I felt such amazement, what a lucky find!

Learning to Code Like a Rubist

Thursday, January 24th, 2013

Code Monkeys

Today I spent some time fixing a bug, and while I was in the code, I wanted to see if my manager was right - that I was writing code that no one on the team liked working with. After all, I'm new to writing in ruby, and there's a unique style, I've come to learn, and I wanted to see if I've been doing it right, or maybe not right enough. I had something like this in my code:

  if meetings.empty?
    ru = fills * misses / factor
    fu = (1.0 / ru) * fill[0]
  else
    ru = fills.map { |f| f * misses / factor }
    fu = ru.map { |r| 1.0 * fill[0] / r }
  end
 
  all_zips = location.map { |l| l['zip_code'] }.compact.uniq
  {
    :ru => ru,
    :fu => fu
  }

Now, in truth, this makes no sense and I had about 10 lines in both branches of the 'if' statement, but the gist was that if the data was a constant, do one set of calculations, and if it was a vector, then do a slightly different set, but along the same lines as the single-valued calculations.

Nothing complex.

But it seems that The Ruby Way is to make anything that's more than a line or two into a new function - even if it's significantly expanding the lines-of-code in the file. So contrary to my prevailing understanding of the reasons for this extreme composition, it's really about the complexity of the code.

I was talking to a consultant new to the group, and his statement was that he trusted the code to do what it said it was doing, and by making the methods very small, and well-defined names, it was easy to understand what they were doing.

I asked him about debugging, and his statement was again about trust.

I was shocked. On so many levels.

First, that trust had anything to do with debugging. Second, that they felt this code was too complex, and required refactoring.

It's a few lines - say 10, and it's a series of calculations. There's no savings in making it functions. It's adding stack calls, tests on the input values, and re-testing the values that caused the branch in the first place. It was horribly less efficient than before, but that's what they wanted.

It's back to the "CPU cycles are Cheap - Dev cycles are Expensive" - Hogwash that I've heard before, and don't agree with in the slightest bit. Nothing is cheap. Everything is expensive, and it's all about balancing the costs of different factors into the final design. There's no free lunch, but it seems that fact hasn't found the Rubists yet.

Secondly, you never trust code in the debugging. You 'single-step' all the code when you have a bug to find out where it lies. If you trust code, you're going to get burned. Guaranteed. Debugging is a thoughtful exercise. You have to think what should happen, and then watch and see exactly what does. This means you can't take anything for granted. Not a single thing. That they would makes me very nervous that "fixes" on their part aren't going to be fixes at all. They'll patch or "refactor" until the bug goes away, but that's not the same as really fixing it. It might just pop up somewhere else.

Finally, I can't imagine that I'm going to be able to write code like this long-term. I don't see it as overly-complex, so I'm not going to think that it needs refactoring. If I take the absurd approach that every calculation is a method, I know I'll be wrong on the other extreme, so I can't just pretend to know what to do.

I'm frustrated, and I feel like giving up. It's been a hard day, and by all measures I seem to be incapable of getting the right mindset to write this code like the rest of the team. They aren't happy with my code, and they aren't willing to put in the hours to write it before I do. So they are going to complain about it, and I'm going to be powerless to understand their mindset properly to write code like they would.

I wish I knew what I could do to fix this problem…

iTerm2 is Good, but Terminal.app is Better

Wednesday, January 23rd, 2013

Terminal.gif

I switched from Terminal.app to iTerm2 about a week ago because I liked the way it's double-click selection was controllable in preferences, and each tab in a window was selectable with the Cmd-1, Cmd-2, etc. whereas Terminal.app uses this to switch between windows. Not typically how that hotkey is used in other apps I use.

Plus, How different could it be - really? kept running through my mind. It's a shell. Should be pretty simple. Well… it's not that simple, and I've finally had it with iTerm2.

In the past week, large outputs to the terminal have crashed the entire iTerm2 app. I'm not saying that if it were like Chrome or Safari, and only the one shell session crashed, I'd be "ok" with it, but to have multiple windows with multiple tabs crash on you due to one tab is more than a little annoying to me.

So I'm heading back, and I'll probably never switch off it simply because Terminal.app never crashes on me. Just never. The convenience of the selection and tab switching would be nice to have, but I just can't have a crashing terminal program. Nope.

Added Investigative Tool to Metrics App

Wednesday, January 23rd, 2013

WebDevel.jpg

This morning, with the right help, I was able to put up a slick little javascript JSON viewer on the main 'metrics' web page for the project I'm on at The Shop. The goal of this is really a quick way to allow folks - both developers and support folks, to look at the details of the Demand objects in the demand service. Since each demand has a UUID, it's possible to look at the series of the demand objects as it "flows" through the service and is adjusted, combined, and delivered to the client.

I have to say that I'm very impressed with the speed of the clojure service. Then again, it's java, and there's not all that much to it - there's the indexed postgres table, a select statement, and then formatting. Sure, that's a simplification, but it's not like we're delivering streaming video or something. But wow! It's fast.

And the regex-based JSON classifier in javascript is pretty impressive as well. It's fast and clean and the CSS is a lot of fun to play with in the syntax highlighting. I can really see how much fun this can be. Big time sink, if I played with it too much.

But it's nice to punch it out and make it available on the much improved unicorn/nginx platform. Those timeouts are gone, and the code is much simpler, and that's a wonderful thing.