OU blog

Personal Blogs

New blog post

Visible to anyone in the world

Rant time! (Wait. That's every time... Well, this time I'm actually typing it into my blog.) This is all about computer programming so if you don't know anything about computer programming you are officially off the hook! (Enjoy your day!)

Coding style guidelines are usually a matter of opinion. But here's one of my opinions, and in my opinion, it's not an opinion, it's a fact. smile

Apart from normal start-of-line indent, trying to align lines of code horizontally is always wrong.

Here are three examples. For each one I'll give WRONG then RIGHT.

WRONG:

$this->something = $something;
$this->x = $x;

Right:

$this->something = $something;
$this->x = $x;

WRONG:

$thing = array(
'value' => 1,
'anothervalue' => 2,
'more' => 3);

Right:

$thing = array(
'value' => 1,
'anothervalue' => 2,
'more' => 3);

WRONG:

$something->function1()->function2($variable, $anothervariable,
$yetanothervariable) {

Right:

$something->function1()->function2($variable, $anothervariable,
$yetanothervariable) {

etc.

The wrong examples are wrong because computer code is not carved in stone, nor even printed on paper. (When you're grave-carving or desktop-publishing, feel free to make things line up. When you're computer-programming, stop it! Now!) Unlike gravestones and newsprint, computer code changes.

Let's say I add a variable called $slightlylonger to the list of assignments. With the right code, this involves me adding one code line. With the wrong code, I have to add one code line, but now I have to modify 2 other code lines as well to make the stupid thing consistent.

Similarly if I change the name of one of the functions I would now have to go around changing all the following lines as well, where it wrapped to multiple lines. (The function example is also bad because horizontal space is usually at a premium, which is why you're having to wrap lines in the first place; when you wrap the line, you want to get a useful amount of increased space for adding more parameters in future. That doesn't happen if the wrap point is artificially shifted to way up near the end.)

Having to modify extra lines matters for two reasons: first, making the changes is annoying, and second, the more lines you touch then the more chance of a conflict in your version control system.

In addition, as I'm sure the newspaper designer would tell you, both these approaches are bad even from a layout and visual design perspective. They result in 'columns' that start every which way at random points. It's messy.

So, much better not to make it line up in the first place. If you disagree... well there's a word in bold in this post... let's leave it there smile

Rant over!

And no this wasn't directed at any particular developer, or even the Moodle project. Just, grr.

I'll try to write a blog post about something more specific to do with our Moodle developments next time. But this is better than nothing, right? smile

 

Permalink 5 comments (latest comment by kenn, Monday, 12 Dec 2011, 21:27)
Share post

New blog post

Visible to anyone in the world
Edited by Sam Marshall, Friday, 26 Jun 2009, 17:35

By today I'd hoped to have the ForumNG discussion display working in the basic non-JavaScript version, but that was not to be sad

I've got about half-way through the display of single posts, which is obviously a key part of this, but.

On the plus side, the forum view page is pretty well complete now (the sorting options work, mark read works, etc).

As for why that discussion code isn't done yet, well, out of five days this week I've recorded 1.25 days of development. The rest is code review and otherwise assisting the other developers on my team; fixing problems with our live system, and analysing a performance question (we've just made a 3% performance improvement, woohoo); providing support for users of our existing stuff; etc. I sincerely hope next week is better, otherwise I may need to go into hiding in order to get anything else done.

Oh, and I've now seen a document sent by aggrieved FirstClass users. For non-OU people: FirstClass is the existing commercial conferencing system we use; it's being phased out in favour of Moodle forums, which is basically why I'm writing an updated Moodle forum version.

They seem to be rather concerned about bandwidth usage! I'll have to make sure ForumNG is reasonably efficient in that regard... now I'm wondering whether I should change all my CSS class names that begin 'forumng-' to 'fng-', which would save a whole 5 bytes each time...

[Conclusion: Er, no.]

Or, maybe if we turn on gzip transport compression they will be perfectly happy with getting rid of FirstClass...?

[Conclusion: Hell no. smile]

Permalink
Share post

Angelic, er, alternatives?

Visible to anyone in the world
Edited by Sam Marshall, Friday, 22 May 2009, 17:43

Last week I wrote a blog post about how crazy we must have been to make so many changes to the quiz system, causing it to become buggy because we couldn't reliably merge changes from new core Moodle versions.

This week I thought I'd write the opposite post explaining why we did this crazy thing... and why we might be doing more.

Basically it's quite simple - we're a huge institution and we have many existing procedures and policies when it comes to assessment. If we only used Moodle Quiz for formative quizzes, that would be fine. But we're trying to use it to replace the old paper-based multiple choice tests, too. Those count toward marks - so all the usual policies apply.

Data protection law is also a big deal. We have to make sure that the wrong people don't get to see student marks. For example, I just had to fix a panicky last-minute bug in our upcoming release. We have these custom quiz reports (which are part of the 'sort of in Moodle 2.0' work I mentioned last time). It turned out that one report didn't properly support groups, meaning that a tutor in one group could see the marks of students in other groups - not just their own. Oops! Apparently, that's a data protection issue.

(Personally, I get to see everyone's Moodle Quiz marks across the whole system, should I choose! Insert evil laughter here.)

In addition to the law, and university policies, there are also expectations involved with the fact that we've been doing things a certain way for a very long time. The Open University was a pioneer of computer-marked assessment. (And that's not an overstatement - I worked on a previous system that interacted with the assessment results from the current paper-based system; a student's results were, and quite possibly still are, represented as ASCII text files... with characters that have to be in specific positions in each line... because these files are exact representations of the punched cards used in a previous version of the system. Yes, really*.)

* ...well, probably. And it's a fun story.

When we've always done something one way, it's kind of hard to tell people 'nope, you have to do it differently now' - especially in the cases where 'differently' is actually 'worse'. Nobody's complaining that we got rid of punched cards, but pretty much anything else is open for argument.

The next looming challenge is double-marking of essay questions. Moodle quizzes can include human-marked questions. That's great! Unfortunately, University rules say that these questions have to be double-marked (marked independently by two different people who each can't see what the other gave it, and I guess with some procedures if the marks are significantly different). This isn't possible within Moodle. At present we solve this by... errr....

...printing out the answers and sending them to the two markers, who write down the marks (like, with a pen) and send them back (like, in the post) to the relevant department here, who work out the correct mark (like, with a calculator) and type it back into the Moodle gradebook (like, literally a person typing them in one by one).

As you can see that can't continue and drastically reduces the chances that we can use this kind of question at all. So there's a worrying prospect that we may have to make more, scarier custom changes to Moodle quiz in the future!

Key word, though: 'future'. Yep, I'm still waiting for Tim to get back. smile

Permalink 2 comments (latest comment by Sam Marshall, Wednesday, 3 Jun 2009, 13:38)
Share post

Devilish differences

Visible to anyone in the world
Edited by Sam Marshall, Friday, 15 May 2009, 17:50

(I thought I'd start with a long technical post just to scare off any non-geek readers! Well, maybe that wasn't the reason, but.)

My advice for any organisation that has developers working on customisations to Moodle code is to keep your changes to a minimum. Completely new code that plugs in - new modules, new admin reports, new blocks - is fine, go crazy. But try as hard as possible not to change existing Moodle core code, even if that means telling your users 'no we can't do that'.

Here's where it came up this week - our quiz module. Oh, dear gods, our quiz module. I'm not particularly enamoured of the fact that we've renamed it 'iCMA' (obviously somebody thinks that's a much snappier name than 'quiz') but hey, that was a local language file, so it didn't cause a difference from Moodle core code. Great!

Unfortunately the eighteen million other things we've changed in quiz did cause a difference from Moodle core code. We have custom navigation, custom statistics, custom reports, custom interface, custom question banks, custom grade calculation, custom ARGH. Some of this is kind of based on work which we were sort of hoping would go into Moodle 2.0 and become standard. But what's actually ended up in Moodle 2 is probably going to be a bit different, won't cover all of it, and is still at least a year away! (From becoming the OU's Moodle platform, that is. I'm not speculating on the public Moodle 2 release date. If you need more information on that, please see this definitive reference.)

The changes to our quiz module are so significant that - unlike every other area of code - we've given up merging bugfixes and other modifications from the Moodle 1.9 'stable' branch - there are so many changes it's impossible to merge without somebody completely expert in the system. While the rest of our platform is just moving to 1.9.4, I don't know where the quiz is, 1.9.1 with bits of 1.9.4? Nightmare.

In this particular case somebody was a little bit over-eager when merging in the 1.9.4 changes. They noticed that one file in quiz actually didn't have any OU custom changes! What an opportunity! So they merged the core changes for that file.

Unfortunately, that file turned out to call a function in another file - which had been newly added in 1.9.4, but hadn't been merged in, because the myriad OU changes already in that file made it too complicated.

For now I have fixed this by de-merging the changes and going back to the older version, which presumably means that we are again suffering from a bug which is fixed in standard Moodle. Yay.

So in summary, this is what we did. Don't do it.

Oh and the solution above might sound a bit short-term, but no worries - I have a long-term plan too. It is 'Wait for Tim to get back here and let him fix it'. smile

Permalink
Share post

This blog might contain posts that are only visible to logged-in users, or where only logged-in users can comment. If you have an account on the system, please log in for full access.

Total visits to this blog: 244885