• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Coding Styles - Make Sure Your Code Can Be Read By Others
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.

Possibly Related Threads...
Thread Author Replies Views Last Post
  [HELP] Updating Add-on Code Harvinder 2 75 01-15-2018, 11:55 AM
Last Post: Harvinder
  How make authorization link? nokikee 0 113 11-10-2017, 09:14 PM
Last Post: nokikee
  [EXAMPLE] Wait for a setting to change before continuing code whufclee 3 365 08-15-2017, 03:00 AM
Last Post: mick3yB0y
  Coding Help .. Speedvid pinoyako 3 338 04-21-2017, 03:05 PM
Last Post: pinoyako
  coding help (i think) information? more tut's AndroidJay 23 2,282 04-14-2017, 07:01 AM
Last Post: whufclee
  Enable add-on using code OptimusGREEN 21 2,095 03-23-2017, 10:41 AM
Last Post: OptimusGREEN
  How to make Trakt read my addon movies? Shadrach 1 507 01-26-2017, 09:50 PM
Last Post: Ryan Isbell
  read file convert to float OptimusGREEN 9 1,885 09-08-2016, 06:27 AM
Last Post: OptimusGREEN
  Need Help on "Clear data" / "fresh start" code samram117 28 6,353 07-24-2016, 01:58 PM
Last Post: Surfacingx
  Python Code to change to default skin. kodiuser 7 1,191 06-28-2016, 05:15 AM
Last Post: kodiuser

Forum Jump:

Users browsing this thread: 1 Guest(s)