Spot any errors? let me know, but Unleash your pedant politely please.

Saturday 7 May 2016

Reassuring

A few years ago, when was getting into Python, I wrote an XML parser.  It's slow and fairly terrible at namespaces and doesn't have any proper unit tests, but it's pretty easy to use.  Of course, I shouldn't have written it at all, but I learned to code before Stack Exchange was a thing. I didn't know that I could find all the answers from smarter people there. Or even that there were some built-in Python things for XML.

I'm still using that parser, which has its own sort-of-XPATH-ish searching, which was written before I  knew that XPATH was a thing.

When I wrote it, I'd never really written a parser for anything particularly complex or vague.

To parse, it uses a class called StringReader.  I've never been happy with the name, but haven't spent any time trying to figure out what it should be called.

Today swift-name-demangling popped up in Reeder. It talks about a 'Scanner' class, and shows the .cpp header:

class NameSource {
  StringRef Text;
public:
  NameSource(StringRef text);

  bool hasAtLeast(size_t len);
  bool isEmpty();
  explicit operator bool();
  char peek();
  char next();
  bool nextIf(char c);
  bool nextIf(StringRef str);
  StringRef slice(size_t len);
  StringRef str();
  void advanceOffset(size_t len);
  StringRef getString();
  bool readUntil(char c, std::string &result);
};

If Python had headers, this is what mine would look like:

class StringReader(object):
    def __init__(self, string):            
    def fwd(self):
    def rev(self):
    def next(self):
    def prev(self):
    def peek(self):
    def eos(self):
    def sos(self):
    def reset(self):
    def find(self, value):
    def checkFor(self, string):
    def skipAny(self, valueToSkip):
    def skipPast(self, valueToSkip):
    def peekAhead(self, length=20):
    def getUntil(self, value):
    def getUntilSequence(self, value):
    def rememberPosition(self):
    def restorePosition(self):
    def remainder(self):

It's really reassuring that even though I wrote this in the dark (metaphorically at least) there's a significant overlap with same/similar names (peek, next, getString/remainder, readUntil/getUntil, isEmpty/eos).  I have more methods. Some look like unnecessary duplicates. I hadn't discovered how to indicate private methods, hadn't discovered properties and hadn't discovered Python naming conventions. I'll have to look into that default length of 20. That looks really odd.

Given that I this grew organically as I needed methods in my XMLElement class, I'm pretty pleased with it today.  I think I'll rename it StringScanner.


Monday 25 April 2016

Prince. Sadface. What an idiot!

The untimely death of Prince has me saddened and confused. Saddened for obvious reasons. Confused by own stupid neglect of my erstwhile fan status. I'm kicking myself that I never quite got around to seeing him live. I'm annoyed that I stopped listening to his music.

I was a fan from Around The World in a Day to Diamonds and Pearls.  I remember rushing from work to Our Price in a lunch hour the day that Diamonds and Pearls came out, getting back to the office a little late and plying it on my CD Walkman for the rest of the week.

This span, from 1985 to 1991 was what I considered my metal years. I'd buy lots of terrible hair metal on Roadrunner Records. I was into guitars and guitarists that were written about in Guitarist magazine. Nuno Bettencourt and Steve Vai and Joe Satriani and Jennifer Batten and Paul Gilbert.

Astonishingly, I'd have probably bought Project Driver at about the same time as Parade. 

You've probably seen the video of Prince's astonishing playing on 'While my guitar gently weeps' with some rock dinosaurs. I don't know if it's true, but I read that this performance was shortly after, and perhaps a response to being absent from a Rolling Stone list of the 100 greatest guitarists. If true, what a fabulous "Fuck You!"

But here's the weird thing: I really liked Prince. I was really into guitarists. I never put these things together. It seems utterly bonkers in hindsight, but I think I know why…

Prince wrote some great songs, arranging and producing them, often playing most of the instruments himself.  Guitar was just a part of what he did. Just part of a song.  Maybe exemplified by When Doves Cry, where it's pretty much just an intro to the intro. Not a run of the mill guitar solo in the middle of a song in the middle of an album of other songs full of guitar solos.  In Paisley Park, it's kind of easy to miss the moments of guitar virtuosity, or forget that it's Prince himself playing them, because they're part of a whole.

Maybe it was a compliment to his song writing and production skills that Rolling Stone overlooked his guitar playing.







Friday 1 April 2016

Tabs, spaces and alignment.

I just read this...
http://cocoawithlove.com/blog/2016/04/01/neither-tabs-nor-spaces.html

I agree with it all completely, except the parts I disagree with.

I agree that I t doesn't matter whether you tabs or spaces as long as you and your team are consistent.

I think my preferences come from coding on actual VT100s an VT220s in the 80s. Physically 80/132x24 monochrome. 

I prefer spaces. A space is a fixed unit and a tab is unpredictable. You need spaces in your code, but you don't need tabs. It makes sense to pick just one, and that can't be tabs. 

Where I really disagree though, is that manually formatting and aligning to make the code pretty is a waste of time and effort.  Readability is really fucking important. Code is read far more than it is written. To not make the code pretty will annoy or inconvenience readers, including future me. The most valuable tool in making code readable is space. We see this most obviously in left indentation implying or defining scope. It's also good for indicating arbitrary blocks. Or giving a complex line room to breath. 

The other thing that really, really bugs me about this drive for efficiency while coding. I'm not 100% creative coding at full speed the whole time. It's more like crafting or interval training. There's a creative burst, then a period of recuperation. This is when I prettify the code I've just written. There's low cognitive load, pride in a job well done, and I'm ready for the next creative burst. 

In monochrome, there's no syntax highlighting. Keys and values, formal parameters and their default values or actual values, names and literals. They all look the same. Maybe pretty code yields more readability in that context.

While I'm at it… Comments that add value are fine. Yeah, yeah, they can atrophy, and code should be self-documenting, but a little explanation can make skimming the code a lot easier. Anyone maintaining or reviewing code needs to take responsibility for the comments.

Lastly, I was intrigued by this post, in which an editor would present code like an outliner rather than just text: http://inessential.com/2015/12/21/how_to_solve_tabs_vs_spaces_forever





Monday 28 March 2016

Misfits and Heroes

I've been trying to figure out why a lot of reasonably well made TV is unwatchable crap. The main problems are poor dialogue and too much exposition (often the source of poor dialogue). i consider both to be dumbing down or condescending. Sometimes it's just poor music (I find a lot of BBC productions have poor/predictable incidental music). There most be more though...

Rob Delaney was on BBC Breakfast recently. He explains differences between UK and US humour.  For professional comedians, there's no difference. We're both as funny as each other.  On an every day level though, Brits are funnier than Yanks.

I wonder if this is why I consider New Tricks to be watchable crap,  CSI pretty much unwatchable and CSI Miami made me shout at the TV when I tried to watch it. Perhaps the American stuff really does represent relatively humourless everyday interactions and this is simply a cultural difference.

Perhaps this is the difference between Misfits and Heroes. The difference between Sheldon and Howard?

Sunday 18 October 2015

Fanner Ukutele

I bought a Fanner Ukutele via Etsy.

It's amazing; beautiful; unique.  It's also really heavy.  I don't think it weighs much less than many fully size electrics.

I feel bad about this, but I've left it too long to leave a review on Etsy.  There's a 60 day limit, that I wasn't aware of, and I really wanted to live with the instrument for a while before leaving feedback.

Communication with Brian Fanner was superb through the whole process.  I asked for something unique, and got exactly that.  It hasn't turned out to be quite what I expected, but it's exactly what I asked for. Any issues are purely down to me.

I wanted a steel string electric ukulele.  I'd considered the Risa LP Tenor, but it's a little expensive, and I wasn't sure if it could be set up as I wanted it.

The standard Fanner Ukutele uses steel guitar strings (1,2,3,1) with re-entrant tuning GCEA, as on a regular uke.  If you fancy one, this is what I'd recommend.

What I asked for was twofold. First, I didn't want re-entrant tuning. Second, I wanted to drop an octave, making the G *two* octaves lower that a regular uke.  I wanted GCEA because my musical brain is limited and transposing (to, say ADF#B) on the fly is beyond me.

Brian was concerned about the additional tension, and decided to install a truss rod. In order to do that, he needed to make a unique neck-plate (using 4 bolts, not his usual 3).  I made some calculations based on the scale length published on Etsy and figured that the strings would be a little loose, but OK.  I think the scale length is a little longer though, and they turned out a bit too flappy.  Tuning up a tone helped a lot, but I still had the mental problem of transposing.

The E string had a kink in it at the 4th fret. I'm not sure how. Strings needed to be replaced.  I took a gamble on some Ibanez 7-string light strings, and restrung with 4,5,6,7, back up to G. I was worried that they'd be tough to bend, and that they may not sit well in the nut,  but they're fine.

What I have though, I'd hesitate to call a ukulele.  It's much more like a small 4-string guitar.  It's well suited to blues/punk/rock rhythm.  I'm playing it differently to a uke. More power-chords, do a D will be 2-2-4-4 rather than 2-2-2-0 or 2-2-2-4.  I'm also finding blues patterns that work well on the ukutele that don't work on a uke.

The only downside is that it's missing some high-end jangle.  I may have to order a standard one for that.

Monday 8 December 2014

Dropbox can't sync because folder is empty.

 I've had this a few times now, and failed to track it down, resorting to things like clearing the .dropbox.cache, quitting dropbox, restarting, disabling selective sync etc.

I thought that the problem was due to a script I run fairly often, which deletes all log files in all subfolders in a project and also pushes changes to boiler plate code to any folder in the project that currently has a copy. I thought that maybe if I ran this too frequently, while a previous sync was in progress, it would just be too much for Dropbox.

What I've just discovered though, is that the blocking folder, which is empty/deleted in Dropbox, still exists on another machine and that a log file in that folder remains open because the Python script that owns it is still running.

I quit the script and all was well once again.

So maybe if you get this error, check that a file isn't open.  If you can't be bothered to track it down, a good old turn-it-off-and-on-again will probably do the trick.

Friday 31 October 2014

"Pride in an immutable state" OR "I'm not homophobic, but..."

First, let me say the Tim Cook's declaration in Business Week was great. I think it can only do good, it brought a tear to the eye.

But…(here we go!)

I do have an issue with the word 'Pride'.  Note: "I have an issue". It's an opinion, and I may come across as being a homophobic arsehole.  That's not my intent.  I certainly have had to overcome my own own mild socially acquired homophobia, and there may yet be work to be done to completely eradicate it, but I don't consider myself homophobic any more.

My homophobia, which probably involved some teasing and name-calling of Neil Si_______ds in junior school* mostly evaporated when I found out that someone I worked with was gay.  It's quite possible that I'd worked with other gay people and had no idea, of course.  Afterwards, I could perhaps sense that he was more sensitive, more caring and gentle than the average bloke. But if someone found out I was gay - I'm not, but if by some misunderstanding they came to believe that I was gay, they may also suddenly see some signifiers, like being more sensitive, caring and gentle that the average bloke.  Those signifiers are mostly bollocks (figurative bollocks, that is).

Halfway through, I realise this is a bit male-straight/gay.  I'm only speaking as a cis-white-male and I only have a little contact with the LGBTQ world. I'm sorry if there's some other way I'm being a dick that I'm not aware of.

So. Pride.

I could say "Gay? That's nothing to be proud of.", and you may read that as a sneer of disapproval, such is the written word.  So forget that. I'll make a pretentious statement instead:
Take pride in achievements, not in a immutable state of your being. 
 Some examples?
I'm proud to be a woman!
I'm proud to be an American!
I'm a proud Englishman!
You perhaps need to imagine Nigel Farage uttering that last one, and then imagining him saying this instead:
I'm proud that my mother had the presence of mind to be in England when she expelled me from her womb, because that has made me better than Johnny Foreigner through no personal effort whatsoever.
And I kind of lump "I'm proud to be gay" in with that.  It's obviously not as odious as Farage's Nationalism, but thinking about this a bit today eventually led me to the aforementioned pretentious declaration.

At first I was trying to think of better words. 'Unashamed', for example, which, while accurate, is intrinsically rubbish because it also suggest shame in the first place.  I figured the best word was 'Am'. As in "I am gay" and "I am straight". Just a simple statement of fact devoid of shame or pride.  It's also plain that to expect this to be enough in the current world outside certain areas in the West is naiive.

The Twitter convo has some good points though, one in particular that Gay Pride, as an event, was a protest, but is now a celebration.  As a celebration, fair dos. As a protest, given my experience of shedding my homophobia, I think it would be ineffective now.  As another pointed out, the apparent need for so many to dress up as village people is kind of self-othering.  I think a much more effective protest would be an indication of sameness. A lot of gay people quietly marching and being ordinary would probably make the Cotswolds piss its collective pants.

I think proper homophobes are terrified of ordinary decent homosexuals, but are actually OK with obviously gay, camp, effeminate homosexuals.  The Larry Graysons, the John Inmans, the Maldwyn Pugh's.  There's safety there. A homophobe wants to know who's gay so he can, I assume, assume the backs-against-the-wall position in plenty of time.  But if their kind-of-mate, who they've been drinking with, or on a rugby trip with … if they turn out to be gay, then FUCK!… Anybody could be gay, how are they going to defend themselves from the legions of gays who might bum them?  Aaargh!

As an example, I know someone who thought Captain Jack in Doctor Who was quite good, and then saw Barrowman being all fabulous on a talk show, and their brain melted. How. Can. He. Be. Gay?

Let me get back on track...

The Achievement as a mutable state…

I think it's fine to be proud of something you've done. Something you've achieved.  The level of pride should be dependant on the achievement.  I'm proud of having fathered and part-raised two marvellous children. My wife has and continues to do more than half of of the raising part, you know because Patriarchy.  Let's face it though, the part-raising is a much greater achievement than the fathering. The fathering amounts to little more than occasionally squirting some semen into a vagina instead of a sock.

It's an achievement though. And I'm proud of it. At one point I was not a father, and then that state changed, and I was a father.

The mutable state of a homosexual…

The being a homosexual isn't, I think we've established, mutable.  If you're gay, you're gay and you were made that way.  What's mutable is the state of being homosexual being public. Being in or being out of the closet.

I think this is probably what's meant by gay pride. Not being proud of being gay, but being proud of the achievement of coming out of the closet. It must also be a tremendous relief.

If you're gay and you have hideous modern parents who are secretly pleased that they have a gay child, because it's one up on the McFarquhars, it's probably not a big deal. It's an achievement, but on the scale of my fatherhood.  Don't big up your pride too much.

There is no shame in being closeted in some circumstances, maybe even in most of the world. Being closeted is a legitimate defence against mental and physical pain. Against torture. Against death. An immutable state of being is a capital offence. That's fucking crazy.  If you're in some shitty place, because Nigel Farage's Mum isn't your Mum, then please, take pride in your closeted survival. And if you take a stand despite this, my word, you deserve a statue come the revolution!

  Tim Cook mentions being openly gay with friends and family. It's not a secret, but he's also not broadcasting the fact.  He probably felt no need.  But today he upped the stakes.  Today he broadcast the fact. To misquote Micky Flanagan, now he's out out. He did that because he concluded that this might help someone. This is an admirable thing. Something he has every right to be proud of.


Feel free to comment


 *I don't remember doing so, but Neil, if I ever called you a poof or a bender or laughed when someone else did, I'm deeply ashamed, I apologise. I sincerely hope it got better, whether you are gay or not.