General developer forum

Moodle Forcing Poor Coding Principles?

 
Picture of Josh Willcock
Moodle Forcing Poor Coding Principles?
Core developersPlugin developers

Hi all,

I am so confused as to what I have found and hope I am wrong... Why on earth does Moodle not like capitals in variables? How are you supposed to distinguish correctly?

idtodelete - is a mess

idToDelete - is clear and easy to read?

So can someone please explain why on earth you get this warning:
Variable "idToDelete" must be all lower-case

This seems strange as Moodle is usually very strict on CORRECT principles in programming?

 
Average of ratings: -
Picture of Michael Hughes
Re: Moodle Forcing Poor Coding Principles?
Core developers

Because https://docs.moodle.org/dev/Coding_style#Variables says so.

And I'm not trying to be unhelpful, but that's the style 

I do understand their point that if you're needing a variable name that is so long as to merit camel casing to clearly identify what it does, the the variable name is poorly chosen.

Personally I don't have that much of a problem with your idtodelete, so I think this is one of those swings and roundabout arguments.

 
Average of ratings: Useful (1)
Picture of Paul Holden
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developers
The point is that the whole codebase follows the same coding style, so the project doesn't descend into petty arguments like this... Who's to say your style is objectively better than anyone elses?

If you aren't going to share your code with anyone else, who cares if it follows a different style? If you are, then follow etiquette and try and make your code easier for other developers to read.
 
Average of ratings: Useful (1)
Picture of Josh Willcock
Re: Moodle Forcing Poor Coding Principles?
Core developersPlugin developers

To share with other developers camelCasing can make it much easier and really the whole project should have been done like this, but there would certainly be merit in allowing it now.

camelCasing is a common principle taught at every college and university I have ever visited. It's also used by many large organisations?

 
Average of ratings: -
Picture of Marcus Green
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersTesters

Camelcase gives multiple ways of writing the same variable name, which is multiple ways of getting it wrong. This is offset by its potential for adding meaning by the use of case. A few years ago "Hungarian Notation" was a widely used notation, and in my opinion it made code hard to read and also generally horrible.

The Moodle style is not particularly more correct or incorrect it is just the style and as such it is helpful if code adheres to it.


 
Average of ratings: Useful (3)
Picture of Howard Miller
Re: Moodle Forcing Poor Coding Principles?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I'm old enough to have seen loads of coding styles, methodologies and whatever else come and go. They are always the answer to life / universe / world peace at the time. The main thing is that there IS a standard and that people follow it. That way we can look at code and tell immediately if devs even bothered to read the standards. 

It's just not a big deal. The main thing is to write good, clear, unobfusticated, sane code. That's a proper challenge. 

They teach a lot of weird stuff in computer science classes in colleges. I personally wouldn't hold it up as the zenith of good practice. 

 
Average of ratings: Useful (1)
Picture of Marcus Green
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersTesters

It always amazes me that computer science classes  place such an emphasis on hard sums. Apparently Universities are more impressed with an A level in Maths than an A level in Computer Science. But then again studying medicine used to require studying Latin.

 
Average of ratings: -
Picture of Howard Miller
Re: Moodle Forcing Poor Coding Principles?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I asked a computer science Professor (a real UK professor, not a pretend American one) what they taught in the way of version control. The answer was, "oh yes, we are thinking about including version control in the course". Sigh!!

 
Average of ratings: -
Picture of Marcus Green
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersTesters

And automated testing might as well be science fiction in most of the academic sector. But he, we teach them Haskell so that's OK then.

(I'm not advocating only teaching "commercial skills" as that way leads to madness and dbase)

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Moodle Forcing Poor Coding Principles?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Acutally, provably correct programs is something that is probably under-used outside of academic computer science. Well worth learning the benefits of the purely functional (side-effect free) programming style. You can used that in places in PHP code (I did, intentionally, in some bits of the Moodle question system). It avoids a whole lot of potential bugs (but is not suitable for use in all parts of Moodle.)

 
Average of ratings: -
Picture of Marcus Green
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersTesters

I taught "software development" to young people up to undergraduate level for 12 years and every year we taught dataflow diagrams (DFD's). In my previous 15 years as a professional software developer on two continents I never saw a DFD sad


 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Data-flow diagrams
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I eventually encountered data-flow diagrams in the 7th OU course I studied (after a lot of UML). I thought they looked like quite a useful view of some aspects of how a computer system worked, and that I might use one for real one day. Not sure if I ever have.

But, a simple data-flow diagram is pretty self-explanatory, as are most simple UML diagrams, and I have drawn those.

 
Average of ratings: -
Picture of Marcus Green
Re: Data-flow diagrams
Core developersParticularly helpful MoodlersPlugin developersTesters

My favorite diagrams are Entity Relationship and the rather unfashionable flow chart.  I have frequently seen people dash off a hand drawn flowchart so often to explain a concept. 

 
Average of ratings: -
moi!!! it is what is is...
Re: Moodle Forcing Poor Coding Principles?
Documentation writersParticularly helpful Moodlers

DFDs.. wow... time consuming but useful for academic projects.... well, that is what I got told once by a professional developer, but someone told me that he really didn't know what he was talking about, he was only working on a POS/Stock management program, then went on to advanced flight and rail training projects. Obviously he had no idea. wide eyes  

But to get back to the point of the initial comment, the few designs I ever worked on established a common criteria for naming variables right at the beginnning of the project. There was a small book put out by a head programmer  from one of the projects from the Dark Side that explained why ALL their programming teams used a common standard for naming of variables. Fewer mistakes, easier to reuse common code between different projects for API calls and such. No matter how big the project teams get, everyone adheres to the common standard. Once you get used to it, it gets easy, and frankly, to my eyes, thisVariable is not really any different to THISVARIABLE or thisvariable or thisVARIABLE, just as long as it is not _this_variable_ In the end, though, this discussion is fruitless, it won't change. 

 
Average of ratings: -
Picture of Marcus Green
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersTesters

I agree with you apart from the idea that THISVARIABLE is acceptable, that's just shouting....

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Moodle Forcing Poor Coding Principles?
Core developersMoodle Course Creator Certificate holdersMoodle HQPlugin developersTesters

Squizlabs did an interesting analysis of various coding conventions on hundreds of php projects using codesniffer (to my disappointment, variable naming wasn't one of them - so we can't see what the 'standard' they found was), but I thought i'd link to it anyway smile 

squizlabs


ps. there are lots of misnomers in that report, don't get hung up on it.

 
Average of ratings: Useful (2)
Picture of Tomasz Muras
Re: Moodle Forcing Poor Coding Principles?
Core developersParticularly helpful MoodlersPlugin developersPlugins guardiansTranslators

That's very interesting, thanks for sharing that.

Unfortunately Moodle includes a lot of 3-rd party libraries, which I assume were not excluded in this report, so it's a bit unfair. I tried to find source code for the report generator itself but I think it's not public. Maybe one day I'll try to generate it just for core Moodle files.

 
Average of ratings: -