Sponsored Links:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Styles - Make Sure Your Code Can Be Read By Others
#1
Everyone has their own coding style but I just thought I'd show you the style I use, it's intended to make it easy for others to look at the code and help improve upon the code. As this is all opensource it's imperative we try and make our code as easy to read and understand as possible - always add comments where you think it will help.

As you can see in this screenshot I mark the end of a function with a commented out line of hyphens and then in the following line you'll see a brief description of what the following function does. When commenting out a line in Python all you need to do is add # to the start of the line and that will mark the whole line as "commented out" so the system doesn't read it when running the code.

[Image: ics2mp.jpg]


Another thing I find worth doing... Let's say you have a file that contains thousands of lines of code, trawling through that looking for a specific function can be a nightmare so what I now do is keep every function in alphabetical order - makes it a lot easier to find what you want. Based on that screenshot above not only does it look easier to read when browsing through the code in a normal fashion but it also allows for this which is great, go to View>Fold All as shown below:

[Image: e9hqwx.jpg]


Now your code will be wrapped up into function blocks so you can easily browse through thousands of lines of code in seconds, if you want to view the code in one of these blocks you would just click on the '+' symbol next to the function name:

[Image: 21cuhkk.jpg]


Abide by the GPL and respect the ethics of OpenSource
Remember the ethics XBMC was born on, everything is opensource and without the the ethics that go with OpenSource software Kodi would just be yet another media player (no pun intended for those that know your history!). If you've used code from another developer ALWAYS credit them in the code and if you've used a considerable amount of their code (ie you've forked one of their addons) then the very least you should be doing is crediting them as developers in the add-on.

Obfuscating Code
This goes against all OpenSource ethics and is not something that should ever be done. Unless the code is all yours and you really don't want to share (possibly for a commercial product) there should be no reason why you would obfuscate code - it's against the whole ethos of OpenSource. There is a grey area when it comes to the legality of obfuscating code licensed under the GPL, strictly speaking it's not against the licensing laws so long as the source code is available (if it's a Python add-on then it will be available) however it is clearly bad ethics and is very much frowned upon.
WANT EARLY DEVELOPMENT RELEASE ACCESS?
All users who've helped out with a donation can now gain early access to the
latest test versions of add-ons, often weeks or months ahead of the public stable releases.

[Image: 11i3ihd.jpg]
  Reply
Sponsored Links:


Possibly Related Threads...
Thread Author Replies Views Last Post
  read file convert to float OptimusGREEN 9 591 09-08-2016, 06:27 AM
Last Post: OptimusGREEN
  Need Help on "Clear data" / "fresh start" code samram117 28 2,436 07-24-2016, 01:58 PM
Last Post: Surfacingx
  Python Code to change to default skin. kodiuser 7 493 06-28-2016, 05:15 AM
Last Post: kodiuser
  About The Coding Templates Section (inc. rules) whufclee 4 1,092 04-04-2016, 10:34 AM
Last Post: whufclee
  [HELP] Code Merge Harvinder 99 8,581 07-29-2015, 09:04 PM
Last Post: Harvinder

Forum Jump:


Users browsing this thread: 1 Guest(s)