Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

An effective way to beautify the code in the Sublime editor
Started by w967 Mar 22 2019 11:03 AM

4 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

w967

[GLOBAL: userInfoPane.html]
w967
  • Observer

  • 8 posts
  • Corona SDK

Hello Guys

Do you like to organize your codes, especially when you reach many lines?

 

Search LuaFormat via Package Control: Install Package

 

# How To Use
Through shortcuts `Ctrl + Alt + F` to format the code within the current view.

 

 



[TOPIC: post.html]
#2

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 460 posts
  • Corona SDK

I try to write shorter modules and then browse between them.  Are you a new user?  Have you used modules?



[TOPIC: post.html]
#3

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

I do very agressively split up my code into smaller modules. In fact, if there is any way to interpret an object on three levels, I will split it into three different modules.

 

An example:

1) My enemies are controlled by a separate "enemiesManager" module

2) Then my tank, for example, will be a separate module

3) My tank will have a separate "bulletManager" module as a child, taking care of firing, managing and cleaning up bullets fired by the tank

4) And of course my "bullet" module will be separate as well.

 

This is my first step in organizing my code.

 

Another thing I do is always comment my "end" statements for functions, and often for loops and branches as well.

 

For example:

local createBunnies = function()
    for i = 1,10 do
        if weatherIsGood == true then
            putExtraBunnyInGarden()
        end -- if weatherIsGood
    end -- for 10 loop
end -- createBunnies()
    

This makes it a lot easier to navigate my code blocks, especially when scrolling up.

 

What sort of bugs me is that Sublime after all this time still has not implemented CodeWrangler's "function dropdown menu", in spite of many requests by users.

 

Adding that function would make Sublime the de facto best code editor out there for me.



[TOPIC: post.html]
#4

sporkfin

[GLOBAL: userInfoPane.html]
sporkfin
  • Contributor

  • 460 posts
  • Corona SDK

@thomas6 -  I like your tagging the "end" statements as a rule.  I'm might try to be more systematic about that.  I add objects to lists (for tracking) at the end of functions so I have a visual cue but systematically tagging the "end"s will be more thorough.  I'll see how it works for me visually - thanks.



[TOPIC: post.html]
#5

thomas6

[GLOBAL: userInfoPane.html]
thomas6
  • Contributor

  • 936 posts
  • Corona SDK

You're welcome! The color coding for commenting in Sublime works much better than the color coding shown above, I can tell you.




[topic_controls]
[/topic_controls]