Author: francis

It’s a real shame that Twitter is used to bash Rails

Comment here.

Even in the Rails community Twitter have put their foot in it several times and, IMHO, have’t got huge credibility. They moaned about not being able to share database connections and then a very able guru known as Dr Nic (he is a Ph D. – and a lovely barking mad person) showed them they did’t know what they were talking about in about 10 lines of code. Hell, even I knew what they were saying did’t sound right and I had only been using rails for a couple of months then, but I have been database programming for the best part of 20 years.

I’ve also used another of their messaging tools, called Beanstalk, and it sucks. We are going to throw it away. It comes with a Ruby gem to allow you to talk to it and rails plugin that adds stuff to the Active Record class – the plugin breaks active record beyond repair – useless. I wrote a 100 line add-in that allowed you to make asynchronous calls using Beanstalk. I looked at their plugin and the code was nasty.

We’re replacing Beanstalk with a very simple daemon that comes in a hundred lines of code or so, is traceable, and works. Very sceptical about Twitter stuff after this experience, and it’s a shame they’re held up as an example.

We are’t a web 2.0 company. We just use Rails to get stuff done really quickly. If there was a faster development framework we’d use it. But I never want to go back to Java, it slows you down and gets in the way.

http://francis.blog-city.com/java_is_bad_for_your_brain_talk_at_barcamp_manchester.htm

Bootnote

Luke pointed out that beanstalkd does its job very well in the right context. The problem we had was that it was very hard to see what it was doing and it was difficult to debug things and a simple daemon that picks the next record from a stack of database records and processes them one at a time was better for us. See his comment for the great things they’ve done with it. Horses for courses.

Writing

I finished my radio play off today and will be sending it to the BBC next week. Quite excited about it but not really holding out a huge amount of hope because there is’t a lot of point getting too worked up about stuff.

I’ve been reading number watch a lot recently. It fits with my world view very well, I started out my proffessional career in the 1980’s with a degree in Applied Statistics and computing. Whenever I hear one of the meedja panics, most recently about chlorine, I know in my heart it is rubbish but don’t have the energy or the time to look into it. The guy who runs this site does and presents a very good case indeed. I really recommend you look at this presentation and have a think about what he says.CORRELATION IS NOT CAUSATION. I think a lot of people need to understand this properly. I think I’ll buy his books when I’m feeling less skint.

I’ve been working my way through Dave Thomas’ video presentations on Ruby meta programming, really interesting and putting all kinds of ideas in my head. I’m probably going to buy most of the Pragmatic Programmer’s videos. I was thinking of learning another programming language, as is advised in the Pragmatic Programmer, but think there’s still a lot of Ruby to understand after seeing these. The first one is the best explanation of where object oriented programming comes from and how it works I’ve ever seen. Also, as a Sun Certified Java whatsit it’s even more obvious that Java is only half way there at best.

I’m also going to resurrect  an old project called pharmarketeer (already own the domain) and try and get it live using Rails. I’ve recently opened a small account on github to do my version control, probably going to start using it for my writing too. I used to use svnrepository and when I went there to cancel my account it was annoying to see that they do git too, but have’t bothered telling their customers. I probably would’t have gone to github if I’d known, but they do allow 5 private repos against sv’s one, but svn allow unlimited collaborators and were about half the price.

Deb is finally home after a month with whistlestop turnarounds before she went off to the next thing. Jon off to scout camp. I spent most of today working because I got behind working from home on Friday because of a long and boring saga about keys that don’t work some times. I’ve changed the lock for a new one.

Bed time, gotta get up and do my meditation practice. For some bizzare reason it seems to be harder to get it done at the weekend, even though you nominally have more time. Probably because you have more time, you waste it.

later.

Men, women and society

Way back in the mists of time men were just men. They had the dominant role in society, at least in theory, and women could’t compete with them in the workplace because they had other things to worry about. In some ways this was less of an issue than you’d think for most of them. They were’t interested in competing particularly. There were two very different roles for men and women and each tended to follow their biology more.

Then we had the sexual revolution of the sixties, in particular reliable contraception. This blew away a lot of preconceptions about things on the back of a terrible war where women had started to do jobs that were nominally only for men. Women could have sex as much as they wanted without risking pregnancy. This meant that they could start to move away from their biology and start competing with men directly. It also blew away the myth that women are scared of sex, in fact they were scared of pregnancy, a much more difficult thing for them to deal with than some idiot leaving a trail of sperm everywhere.

This economic trend was the basis for the feminist movement. There were simply more women not being the housewife, and having jobs and careers of their own. More women were career minded, were limiting their families and so on. This meant that they wanted the closed doors and glass ceilings that men had put in their way removed. They were right, it was wrong and unfair. Of course, it was’t a conspiracy by men, it was just the way things were, but that doesn’t suit if you want to be angry.

There was also a vigorous and correct campaign to protect women from predatory men and exercising their right to dress and behave how they see fit. No-one argues with this, it was right and just. An unfortunate and dangerous sub current of this was that all men were potential rapists and predators, and all men should be watched carefully. A justified wariness and caution around men you don’t know well, given that they are in general about half again as strong as a woman of the same size, was turned into an ideology. All men were rapists, and could not be trusted.

Let us pause here and restate that: All men were rapists, and could not be trusted. This is exactly what was being said in radical feminist magazines. Women should unite, become lesbians, and only use men for brief purposes of procreation. Men are now the enemy. The anger ran very deep, it was becoming hard to be a heterosexual man in certain radical circles. To be fair a lot of the radical men were unreconstructed sexist pigs who needed to marry their professed politics and their behaviour together. But were they some kind of dangerous, sex-crazed enemy? No. They were just men. Men who love and respect women, when you kick their soap boxes away and challenge them to think more deeply. We laugh at the alleged Victorian notion that table legs should be covered up in case it inflames me’s ‘base’ desires and then act like it’s actually true.

It sounds completely crazy doesn’t it, making an unavoidable biological division into a political platform, a basis for hatred? But it is the way radical feminists used to write and think. Interestingly, this was the hotbed that the student activists of the 80’s and 90’s lived inside. You have to ask yourself: who got involved in politics and eventually got themselves elected? Who took the political gauntlet away from the male cabals and trod the boards, knocking on doors and building political parties? Women, educated, articulate women. Good thing too! But, the dangerous thing was that they had been infected with at least some of this suspicion of men.

A lot of laws, particularly those around divorce and child custody, were rewritten to be fair to the woman. They acknowledged her role in creating a family and that she should have half of the assets. This is not a bad thing. It might appear to hurt some men but it is very fair, compared to the way it was years before. But now men are denied access to their families, they are demonised when they try and ensure that cash is distributed fairly. They are a dangerous annoyance that needs to be kept away from the purity of the family. They are no longer allowed to be part of it. This is a caricature, of course, an aunt sally that you can throw rocks at if you want to. But it follows on from them being the enemy, in fact they are becoming the enemy of society at large.

It is utterly insane to say that, condemning half of society to being the enemy. But you look at the way a man can’t take a photograph on the street, or pick his children up without being scowled at suspiciously, or be seen anywhere near a playground on his own. It’s true, in some senses. When we had a friend and her child round recently I was shocked by feeling unable to give him a hug – where the hell did that come from?

The other thing about this is – what happens to boys? You will be a man, but while you are growing up men are something to be scared of unless they are your dad (assuming you know who he is). Even male teachers are suspect. Then you grow up and what? Become a bad person? It almost gives them a licence to behave how the hell they like because that’s what’s expected. Think about it, think about the lack of authority and respect for men in general, for others, for anyone but your small circle of acquaintances. Is it surprising a lot of young men (and women too) are such dangerous idiots? They have been infantilised, they have had their role models replaced by selfish useless people idolised by airhead meedja for as long as it suits the editors.

Where is the father or grandfather or whoever who commands respect and people listen to, who could intervene and knock sense into heads? Dead and gone. The same is true of the mother and grandmother too, the nanny state knows best, and is always fair in her dealings with people. Everyone has been infantilised – the big STOP sign stands across relationships between generations. Yes, it’s stupid, it has created a generation of twenty-somethings with their teeth still in the teat who don’t know how to behave towards each other. How do infants behave? Self-centred and quite often incapable of understanding others’ feelings – does this sound familiar? Seeing the other person’s point of view, taking it into your heart when you deal with others, is part of growing up and yes, it hurts, but it hurts for a reason. No, let’s just treat other human beings as onanistic aids on some hedonistic rush to death.

Now the state intervenes between men and women as a matter of course, it has to rake its lowest common denominator paws across families and decide for the parents how best to bring up children. It is extremely risk averse, this means that it’s easier to say no to everything in case you become one of the vanishingly small number of problem cases. This causes great pain for a lot of people, and their children, for the sake of not a lot. Another STOP sign has been created between men and women when relationships break down. Of course, this was originally justified because the state was supporting the families of “absent fathers”, sadly the families quite often don’t have anything more than they did, except the legal bill landing at the door of the parent the state can find.

Then we have the rise of the CRB culture, another risk averse mentality. Men in general are not child molesters, they are as revolted and angered by it as anyone else. A vanishingly small number of them should be locked up and kept away from children. Instead of using common sense, assuming innocence until proven guilty, of making sure situations where accusations could arise (or misdemeanours actually occur) do not happen, we have a pile of rote behaviours and rules that protect no one and breed suspicion and distrust. The bad guys just go round them and protect themselves. A child goes missing and is spotted by a lone man who will not take it by the hand and try to return it – eventually the poor mite drowns in a pond. Is this good? Is this right? Never. But the guy who could have helped was afraid to, and twenty years ago he would have done so without thinking. That stinks.

Yes, teachers and people who deal with children a lot should be checked. But the guy or gal who checks your application forms for your driving licence? Or the one who takes the money in the post office? Why? Risk aversion. The guy walking down the street on his way home from work? Every guy or gal who’s got past the age of 10? Where the hell does it stop? Tattoos or marks on the forehead saying you’ve been checked – or the other way, like the branding of vagabonds in the seventeenth century?

Where does this lead? Licenced mothers and fathers, everyone has a CRB check, a biometric ID card and is recorded somewhere on a huge DNA database – the state pushing the barriers between people so far that every relationship is a subject of the barrier, the STOP sign, and a bunch of paper pushers control your life completely on the basis of some rules that are very fair, but not even slightly compassionate. The state doesn’t have compassion, it is scared of risk, it interferes where it should’t for the best of reasons. There are places where the state should not intervene and this is one of them.

Yes kids, bad things happen, and no amount of laws and hand-wringing can stop it. Yes, often they hurt and are very hard to bear – it’s called the human condition, sorry. You can minimise the danger by learning how to be an adult and where the limits are, but the pain that comes from falling out of your mother’s womb can’t be ducked, hard luck, there is no get out of jail free card in real life. A lot of the time there is’t anyone to blame, either, so don’t bother looking. The bad guys should be punished when they are caught. Only a fool would argue with that, but politicians have to be seen to be doing something when the meedja gets all hysterical and quite often they should just say shit happens, sorry, if you can find some way to stop it happening I’d love to hear it. But that would mean admitting to not being perfect or being able to do something about things that are actually unavoidable and we can’t have that, can we?

If you don’t start from compassion, from a belief that everyone is entitled to happiness and the causes of happiness, if instead you start from knowing what’s ‘best’ for people and you attempt to force this on them even when they don’t want it then the world is a cold, cold place. A place of rules and regulations that mediate everything, where the default word is NO when you try and step outside or past them because that’s the easiest course and it means no one has to think or admit to feeling. A place where burning the wrong person at the stake is OK because they will go to heaven anyway. A place where hedonism is the best path to follow because there is nothing beyond your own trivial pleasures, where no one else matters, where we are nothing but the sum of divisions and ignorance – but you dare to question the rules or step over them slightly, even out of ignorance, and you will end up in prison or on some register where you can’t get a job. Seriously, think about it a little, and get the teat out of your mouth.

I’m ready to be burned at that stake if I have to be to stand up for my beliefs. But let’s just stop now, and not go there. Please? Men are just men. Women are just women. People are just people. 99% of us are decent, caring and honest, and that’s the truth.

Diary entry

Deb

Deborah is back from China where her team came 20th in the search and rescue competition. There were a lot of Chinese teams and they were about 4th or 5th or so if you only included one of them, but rules is rules. The girls worked out that they had scored about the same points as last year in Atlanta where they finished 5th. They had a great time and the people were really hospitable.

Straight after this she went to Chemistry camp in Leeds and did projects about dying and forensic chemistry – had a good time there too. Now she’s at guide camp!

Jon

Basically playing Warcraft as much as he can get away with and doing as little as he can get away with. 

Rosie

Very busy having her holidays digging gardens and hurting her back. Then she’s back for a week and then on holiday again. The joys of working flexitime – she has to use the holidays or lose them.

Me

I’ve finished my radio play and an essay that I will publish here. Very busy at work but not working silly hours at the moment. 

Maintenance programming

Comment left here – it’s also worth following some of the links in the article.

Never install the Java Decompiler, JAD, and look at the library code you are dependent on.

Just don’t.

If you do, however, never run the FindBugs utility (which I recommend for all lazy code reviewers btw) against the decompiled code.

Just don’t.

Or you will cry.

I’ve picked up lots of code in my time, and the hardest stuff was Java “o-o” code, because everything is buried so deep and bugs very hard to find. Oddly, Ruby is easy to debug once you’ve understood how metaprogramming works and it is an o-o language. But most of the time you just write code to do what you need to do and write tests for that small thing.

UML etc. etc. – guys you are working at the wrong level. UML blah … once you’ve gone past the initial system design it’s another thing to maintain and it wo’t be. Throw it away and make the code base clean. I’m very old fashioned – I tend to start from a clear data model and view the rest as just a layer on top of it. I don’t care about the class model – it’s usually not worth worrying about and a lot of code is procedural code hidden in static classes anyway – be honest, now. This is particularly true if you are using an o-o to relational mapper – that’s where all the complexity is and you have decided that you want the mapper library to do the work. Data matters, the rest is fluff.

I also recommend finding a formatter for the language you are using if you are trying to understand someone else’s code. It’s amazing how many bugs you find when the formatter changes the indentation to reveal what the compiler/interpreter will actually do with the code.

Read Fowler’s refactoring book, even if you are not a Java programmer, it repays close study.

Old fart signing off now.

Setting up to fail

One of the consequences of meditating a lot over several years is you start to see how your own mind works. Obviously, this gives you insight into other people’s too.

If you are feeling down and oppressed by the world, well, how about getting the world to confirm that it hates you? Or that things always go wrong in a drearily predictable way when you interact with certain people?

The game is simple:

  1. Take some task you do collaboratively with others often. Packing to go camping, or some project deliverable. It does’t have to be work related at all: a lot of people do this in the comfort of their own homes.
  2. Decide on your none-affirming goal, e.g. I always do all the work for X,  or, people wo’t take responsibility and be self-sufficient.
  3. Change the unwritten rules of the social interaction very slightly so that you can catch them out, e.g. don’t ask for any help (or ask when it can’t be given because of some other constraint), or, don’t pack the stuff (say towels) that you always pack for everyone.
  4. Crucial part of the game here. Don’t tell anyone about 3.
  5. Let the unsuspecting individual(s) make the “mistake”.
  6. Shout a lot.

Stop it, just stop it. Make sure everyone knows what is expected and check they still understand what it is as the process is running. No-one fails and no-one shouts, life is much easier. People are a little stupid sometimes, and they have short attention spans for stuff that bores them, and what’s important to you may not be to them. Hard luck. I have been in several (failed) relationships where this game was played a lot. I think a lot of the so-called war between men and women is about this, it’s silly manipulative stuff and should be avoided. It’s an easy trap to fall into though, usually when you are down and want to prove something about the world. Keep it at arms length and smile when you catch yourself doing it. And stop it.

I’ve also noticed that when people complain a lot I want to say things like “well, at least you managed to find something to complain about, be grateful you are doing something you enjoy.” Constant complaining is another setting up to fail in a different guise, and it’s bad for your mind. Stop it, just stop it.

Soap4r woes

Just in case this burns someone else

Talking to a web service that returns an array of mixed complex types (ooh goody!)

soap4r returns a lot of SOAP::Mapping::Object

These pretend to be a kind of hash (of hashes of hashes if you go really deep), so I could get my proposal back by the rather horrible

response.submitResult.returnMsg[‘Proposal’]

(lots of console work required to get this far .. :))

I needed the proposal’s ID and it was nowhere to be seen. When I looked at the wire trace it told me that the proposal ID was being returned as an attribute of the Proposal XML node.

Lots of pain and headscratching later discovered a blog post talking about the semi-hidden xmlattr method, this is a proper hash but it is indexed using the qualified name class XSD::QName

So, to get the ID out we end up with …

proposal_id_key = XSD::QName.new(nil,‘proposalID’)
response.submitResult.returnMsg[‘Proposal’].
xmlattr[proposal_id_key]

Let the joy be unconfined … SOAP is another unnecessary PIA. Most of the time you could just post XML direct using HTTP. I can’t see any benefit for the additional complexity.

If we did’t have soap4r I’d still be banging my head on the desk so +1 for that …

Top tip, you can set $DEBUG=true in the console to get the wire trace.

Meditation and Depression

Comment left here. 

My lama says that you should allow your subjective pain to awaken compassion for others that also suffer from whatever condition you are suffering with. Then take the medicine!

I no longer need to take antidepressants and I put this down to many years of practice. But Buddhist meditation is not therapy: it’s goal is enlightenment. This is why the Dharma is taught.

That said, calming meditation really helps to clear the mind of that nagging negative voice that informs depression and damages your chances of happiness in this life. I did this by learning to recognise it and then prevent it gaining energy and starting a loop in my mind. My personal experience is that it is like having a constant noise in your mind that spoils everything and makes it very hard to think and feel anything but despair that it will never end. Eventually you move on past it. Or I did, anyway. I also found the first Noble Truth, impermanence, a great help, because it meant that the was a light at the end of the tunnel and my pain would end.

A friend said (probably a quote somewhere), “if you are going through hell keep going until you get to the end”. Good advice I think.

Bootnote – here is another post against the same topic

I do’t need to focus on the pain – it’s always there, constantly. I just do’t give it any energy any more. I recommend the Tibetan practice of lo johng (not sure of spelling) – “sending and taking”, which the Dalai Lama describes in one of the “Essential Teachings” series – need to track the proper reference.

I also would’t embark on this without some instruction from a qualified teacher.

Another thing that came to mind recently – and sending and taking starts with this – is to forgive and love yourself first, before you try to give things to others. If you hate yourself the taint of the hatred will devalue whatever you give to others, and make it hurt more too!

Strongly recommend “The Art of Happiness” too, wonderful gentle book.

Rails: I can put together a simple database-backed app really quickly

Comment left here

… and that’s why I use RoR. 90% of the “anti” opinions here don’t get it. It’s quick, it has a low entry barrier, and, if you want the Ajax stuff, it’s very easy to do simple things. If you want stuff that scales to the moon then you use a technology that will do that – d’oh!

Ruby has also got lots of nice utilities to do SOAP and so on. It just works and it does’t hurt. Integration with other services (.Net or Java) is a breeze and you can get help really easily from other people in the community. In general there is only one way to do something (because the language is young) and it does what you want. Compare with Java – 25 frameworks with alpine learning curves (XML or properties files – let’s have both!) before you can do anything. It used to be simple and pretty easy to get things done but the signal to noise ratio is really painful now and getting worse with every “improved” J2EE implementation from the big vendors. Me no want no stinki’ entity beans – they leave a stain on your teeth.

I am a Java certified web developer and would’t go back, except for the cash. It used to drive me crazy: make a change, run Ant, deploy the WAR file, waste 20 minutes doing nothing. Get shouted at by PHB for reading El Reg while all this was going on. This is typical if you work on a legacy system.

Now I can just get stuff done, and that’s all I want. I’m really keen on the whole JRuby thing, where the Rails app will just run from a WAR file and use all the sexy scalability stuff that the Java people have spent so much time and energy on – but I’ll happily use it at one remove, thanks.

Getting the number of months between two dates in Ruby/Rails – updated

Here lies the one that works, not the old one I posted ages ago. It also uses dates instead of timestamp differences and should therefore not break if you ask it to go before the Epoch (some time in 1970 I think):

Adrie’s comment left on my old blog pointed this out (he’s much cleverer than me!) – it’s really trivial:

s is the start date and e is the end date (s is lower than e)

(e.month - s.month) + 12 * (e.year - s.year)

See!

module DateUtils

  class << self
    def months_between(date1 = Time.now,date2 = Time.now)

      date1 ||= Time.now
      date2 ||= Time.now

      if date1 < date2

        recent_date = date1.to_date
        past_date = date2.to_date

      else

        recent_date = date2.to_date
        past_date = date1.to_date

      end

      (past_date.month - recent_date.month) + 12 * (recent_date.year - past_date.year)

    end

  end

end

Imported Comments:

UE

Thanks a lot. helped me much

john

not working

fdsa

doesnt this neglect the actual day of the month? there isn’t 1 month between 2/1/11 and 1/31/11, but this would claim there is…

Francis

ok – but “months or part therof” is a long method name 🙂