Save-Point
Beyond the script editor line: Is it bad practice? - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Development Discussion (https://www.save-point.org/forum-17.html)
+--- Thread: Beyond the script editor line: Is it bad practice? (/thread-2924.html)



Beyond the script editor line: Is it bad practice? - PK8 - 05-21-2009

I suppose this is a question geared towards scripters?

So I've mixed feelings about this. I've been catching myself doing it for a bit, mostly because of the math stuff mixed with variables, dunno if they would still work if they were somehow separated in multiple lines instead of being one line.

Small example of code from my pause script:
Code:
@backgroundtone[bgt].viewport.tone.red = (@backgroundtone[bgt].viewport.tone.red * (@backgroundtone_c[bgt][3] - 1) + @backgroundtone_c[bgt][1].red) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.green = (@backgroundtone[bgt].viewport.tone.green * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].green) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.blue = (@backgroundtone[bgt].viewport.tone.blue * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].blue) / @backgroundtone_c[bgt][3]
@backgroundtone[bgt].viewport.tone.gray = (@backgroundtone[bgt].viewport.tone.gray * (@backgroundtone_c[bgt][3]-1) + @backgroundtone_c[bgt][1].gray) / @backgroundtone_c[bgt][3]

I'm sure Trickster considers code going over the script editor line to be bad practice, there's a small chance I could be wrong though. So does anyone consider having code that goes over the grey line in the script editor to be bad practice or something along those lines? o:

Edit: I meant this.
[Image: 11bn815.png]


Beyond the script editor line: Is it bad practice? - EJlol - 05-21-2009

going over that line is BAD imo. Your handwriting is pretty good though :P


Beyond the script editor line: Is it bad practice? - DerVVulfman - 05-22-2009

Oh, I have seen plenty of scripts that go beyond the margin line but it is merely a guideline for you visually. Even Japanese scripters go beyond the margin line in the editor.

Can you really help it if performing complex math functions require your statements to go beyond the border? Maybe, but that could either require you to break your statement down to multiple lines or have extremely shortened variable names.

From a coder's point-of-view, your variables should have descriptive names, so your @backgroundtone_c value is pretty much correct. It could be shortened to @bkgrndtone_c, but that may not change your lines enough in some of these occasions.

I guess it comes down to cleanly write your code in a manner so the whole statement can be visible and understandable without having to scroll your
editor left to right.


Beyond the script editor line: Is it bad practice? - Yin - 05-22-2009

If it still functions correctly then why change it? I'm no scripter, but that's my opinion.


Beyond the script editor line: Is it bad practice? - Zeriab - 05-22-2009

@Yin: It can become much harder to debug.
I generally prefer breaking long lines into several smaller lines, but that's mainly because it's quicker to locate errors.


Beyond the script editor line: Is it bad practice? - DerVVulfman - 05-22-2009

Taking from Punk's earlier example, you may see how easy it is to read and debug the code if formatted with line breaks:
# Background Tone (Red)
@backgroundtone[bgt].viewport.tone.red =
(@backgroundtone[bgt].viewport.tone.red *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].red) /
@backgroundtone_c[bgt][3]
# Background Tone (Green)
@backgroundtone[bgt].viewport.tone.green =
(@backgroundtone[bgt].viewport.tone.green *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].green) /
@backgroundtone_c[bgt][3]
# Background Tone (Blue)
@backgroundtone[bgt].viewport.tone.blue =
(@backgroundtone[bgt].viewport.tone.blue *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].blue) /
@backgroundtone_c[bgt][3]
# Background Tone (Gray)
@backgroundtone[bgt].viewport.tone.gray =
(@backgroundtone[bgt].viewport.tone.gray *
(@backgroundtone_c[bgt][3] - 1) +
@backgroundtone_c[bgt][1].gray) /
@backgroundtone_c[bgt][3]
Yeah... I did the colors too.


Beyond the script editor line: Is it bad practice? - Charlie Fleed - 05-22-2009

I second what DerVVulfman said, except I think @bkgrndtone_c is terrible... :)
@bg_tone_c anyone?

Oh, and it should be clear from the example above, but the idea is that you can break a line after specific elements, like math operators, but also dots, and so on...