Feature placer code review.

Feature placer code review.

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Feature placer code review.

Post by smoth »

the code.

There are a few things I am not altering.

[*] I am not altering my use if tabs for spaces.
[*] I am not removing my localized spFunctionName, they are shorthand and I think it makes the code cleaner to read.
[*] I am not switch the pairs to a for #tablename loop or using next().

Since 2008, I have never experienced an issue with this code failing in my project. Any map that ever used it, also included the features/units. I have been told recently that my old code was not up to snuff. So instead of being lambasted again for my code apparently being poor. I did a minor update and now am putting it up here for review/critique. There was a specific complaint that the code is not within a function, I am not aware of a function that would have the features placed before gamesetup() is called. Should you know that function, do let me know so that I can update that part of this code.



ready, set, go!

Image
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Feature placer code review.

Post by smoth »

First update from KingRaptor's feedback:
Now with preload()

Anyone else?
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Feature placer code review.

Post by Jools »

smoth wrote:the code.

There are a few things I am not altering.
[*] I am not altering my use if tabs for spaces.
Tabs are better than spaces. The tab character can be any number of columns depending on environment, but space is always one. What idiot presses the space key 5 times when he wants one column of 5 spaces? That's the function of the tab key anyway.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Feature placer code review.

Post by jK »

You should keep the level of indentations <=3, when reaching lvl 5 you should split of code in a subfunction.

http://paste.springfiles.com/view/8f83c8d5
(got a c&p error in L80 & L81, too lazy to fix the pastebin)

Jools wrote:
smoth wrote:the code.

There are a few things I am not altering.
[*] I am not altering my use if tabs for spaces.
Tabs are better than spaces. The tab character can be any number of columns depending on environment, but space is always one. What idiot presses the space key 5 times when he wants one column of 5 spaces? That's the function of the tab key anyway.
He also uses as whitespace between code and not just front indentation. That's bad style cause it makes indentation platform/system dependent (on the size of a tab).
dansan
Server Owner & Developer
Posts: 1203
Joined: 29 May 2010, 23:40

Re: Feature placer code review.

Post by dansan »

Jools wrote:
smoth wrote:[*] I am not altering my use if tabs for spaces.
Tabs are better than spaces. The tab character can be any number of columns depending on environment, but space is always one. What idiot presses the space key 5 times when he wants one column of 5 spaces? That's the function of the tab key anyway.
That is not necessary. My IDE inserts x spaces when tab is pressed and the cursor is at the beginning of a line. It multiplies lvl * x for correct indentation in nested commands, and removes x spaces when hitting the backspace button if the cursor is in front of the 1st non-whitespace character.
The result is, that you neither see nor feel, if actually tabs or spaces are stored on disk, it's just a configuration switch. Ofc there is a function to convert one into the other for the whole file.
User avatar
Jools
XTA Developer
Posts: 2816
Joined: 23 Feb 2009, 16:29

Re: Feature placer code review.

Post by Jools »

Ok, but a tab character takes less space than several space characters => smaller file
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Feature placer code review.

Post by smoth »

dansan wrote:
Jools wrote:
smoth wrote:[*] I am not altering my use if tabs for spaces.
Tabs are better than spaces. The tab character can be any number of columns depending on environment, but space is always one. What idiot presses the space key 5 times when he wants one column of 5 spaces?
no idea but why not alter it to do tabs instead? if you don't like the tab size most also allow for a setting to set the actual size of tabbing. I don't see any value in keeping the spaces
He also uses as whitespace between code and not just front indentation. That's bad style cause it makes indentation platform/system dependent (on the size of a tab).
Example line and suggestion for improvement please?
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Feature placer code review.

Post by smoth »

Version 3

Made a few changes suggested by JK's edit, still leaving the spFunctionName stuff as I find it cleaner to read.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10453
Joined: 24 Jan 2006, 21:12

Re: Feature placer code review.

Post by PicassoCT »

dansan wrote:
Jools wrote:
smoth wrote:[*] I am not altering my use if tabs for spaces.
Tabs are better than spaces. The tab character can be any number of columns depending on environment, but space is always one. What idiot presses the space key 5 times when he wants one column of 5 spaces? That's the function of the tab key anyway.
That is not necessary. My IDE inserts x spaces when tab is pressed and the cursor is at the beginning of a line. It multiplies lvl * x for correct indentation in nested commands, and removes x spaces when hitting the backspace button if the cursor is in front of the 1st non-whitespace character.
The result is, that you neither see nor feel, if actually tabs or spaces are stored on disk, it's just a configuration switch. Ofc there is a function to convert one into the other for the whole file.
This IDE surely encourages copy and pasting your code into other working enviroments? All you have to do is click the options together, safe the file, open it in the other ide, but you the need arises allmoist never, cause the path is obsticled and structed.

Spaces can not be maintained properly by projects using various ides.
Post Reply

Return to “Lua Scripts”