This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Jappards's profile picture

your way of coding?

Started by Jappards, 10 April 2013 - 07:11 AM
Jappards #1
Posted 10 April 2013 - 09:11 AM
Everyone writes code different, i first try to write it in the lua program (in CC, not a program on the computer) then i then i write the code in Chunks. What is your way of writing codes in Lua on CC?
Sammich Lord #2
Posted 10 April 2013 - 09:13 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>
Engineer #3
Posted 10 April 2013 - 09:17 AM
I separate my files when doing big projects. Then I add it into one file if it is not an API, and then I go debugging :P/>

Warning, the following is advertisement, not blocked by Adblock+ :

See my channel, then you can see it. Im currently rendering a debugging video :P/>
Kingdaro #4
Posted 10 April 2013 - 09:34 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
Basically this.
SuicidalSTDz #5
Posted 10 April 2013 - 09:57 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
Couldn't agree any more :P/>
Sammich Lord #6
Posted 10 April 2013 - 09:59 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
Couldn't agree any more :P/>
Lua is nothing but functions and tables :P/>
ElvishJerricco #7
Posted 10 April 2013 - 10:14 AM
I've written a program called "open" which takes a directory as an argument. It looks at all the files in the folder and loads each one into an environment. Then all the environments have their __index set to the same table, and they're all added to that table.

So basically, you can call each file's functions just like you would an api.


-- file1
file2.function()

After all that, the main function in the file "main" is called.

As for my actual development environment, I have all my programs stored on one disk. I've deleted the folders for each individual dev computer, and replaced them with a symbolic link to the disk. So now I just edit the files on the disk via TextWrangler, and all my computers use the new code. Very useful.
ElvishJerricco #8
Posted 10 April 2013 - 10:16 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>/>
Couldn't agree any more :P/>/>
Lua is nothing but functions and tables :P/>/>

And numbers, strings, nils, booleans, and coroutines =P
Lyqyd #9
Posted 10 April 2013 - 10:32 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>

I despise this practice. It would make so much more sense to break the top-level function out of being a function and just use it as the body of the program.
Sammich Lord #10
Posted 10 April 2013 - 10:50 AM
Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>

I despise this practice. It would make so much more sense to break the top-level function out of being a function and just use it as the body of the program.
I do what you mentioned a lot too. I sometimes have API's in files, runs those then just have my actual main script call all the functions.
Shnupbups #11
Posted 10 April 2013 - 04:37 PM
I separate my files when doing big projects. Then I add it into one file if it is not an API, and then I go debugging :P/>

Warning, the following is advertisement, not blocked by Adblock+ :

See my channel, then you can see it. Im currently rendering a debugging video :P/>
I used AdBlock+ to destroy any trace of your comment. So ha.

EDIT: ON TOPIC:
I usually only make functions if I use a block of code multiple times, I really need too, I'm making an API, or I'm using parallels. Otherwise, just smash everything down. Usually don't comment. Usually don't put empty lines between parts. I have found myself doing these more and more often though.
Dlcruz129 #12
Posted 10 April 2013 - 05:18 PM
All of my code goes in functions, except for a while true do statement and a few if statements.
Spongy141 #13
Posted 10 April 2013 - 05:23 PM
All of my code goes in functions, except for a while true do statement and a few if statements.
Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.
SuicidalSTDz #14
Posted 10 April 2013 - 05:55 PM
All of my code goes in functions, except for a while true do statement and a few if statements.
Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.
My code is readable, well, to me anyways :P/>
Dlcruz129 #15
Posted 10 April 2013 - 06:07 PM
All of my code goes in functions, except for a while true do statement and a few if statements.
Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.

Me too. OCD is one of the best qualities a programmer can have.
Mads #16
Posted 10 April 2013 - 09:57 PM
For bigger programs, I just put the main code in something like main.lua, and have classes and stuff in other files, and then I require() them.
Smiley43210 #17
Posted 11 April 2013 - 12:28 AM
Most of my code goes into functions, which I then call in the code logic after the function declarations.
Mackan90096 #18
Posted 11 April 2013 - 01:17 AM
I write my code in functions in Sublime Text and then run the functions (usually)
SuicidalSTDz #19
Posted 11 April 2013 - 01:35 AM
I write my code in functions in Sublime Text and then run the functions (usually)
Thats because Sublime Text is the best :P/>
Kingdaro #20
Posted 11 April 2013 - 04:23 AM
I write my code in functions in Sublime Text and then run the functions (usually)
Thats because Sublime Text is the best :P/>/>/>
Amen, brother.
robhol #21
Posted 11 April 2013 - 04:29 AM
I used AdBlock+ to destroy any trace of your comment. So ha.

That's funny, that's actually exactly what I did to your atrocious, flashing red avatar. *cough* :)/>
Jappards #22
Posted 11 April 2013 - 05:21 AM
nice, we should make some recommendations for others to help them with coding.
one recommendation is definitely, building your scripts out of chunks.
Spongy141 #23
Posted 11 April 2013 - 12:57 PM
I used AdBlock+ to destroy any trace of your comment. So ha.

That's funny, that's actually exactly what I did to your atrocious, flashing red avatar. *cough* :)/>
No need to get hostile, and the topic is "your way of coding" not "rate the a users avatar", and they have a similar topic for that if you didn't know.
Mailmanq! #24
Posted 13 April 2013 - 11:48 AM
With small things, I just type the code out. With medium sized things I have functions that are all run at the bottom of the program with very descriptive names to help with debugging. And with big projects I have multiple files and use dofile to load them and call their functions with a priority level define at the top of the file I am loading.
majesty2450 #25
Posted 13 April 2013 - 12:29 PM
I usually try to make classes and define those class's functions at the top of the code. At the bottom I write the code that runs, calling and creating objects when necessary. Always try to put comments, but I get lazy… I also always indent and space to keep the code clean. With large programs I create multiple files for the classes and have a main. I use notepad++ on windows to program the code and have it open along with minecraft for debugging.
KillaVanilla #26
Posted 14 April 2013 - 12:35 PM
I mostly write APIs now, so I naturally use a lot of functions. I also have a window open to a minecraft session for quick testing, and a window open to the folder corresponding to the computer I'm using for testing. I use Notepad++ to write the code itself. I (usually) separate my variables by type and use (constants, tables, assorted values, etc.) and I type a lot of comments. I occasionally use the "main function" approach, but not too often (and when I do, the function is usually called "int_main()" and returns 0).

How big (in terms of line count) are most of your multi-file projects? I don't have any projects (besides OSes and server/client programs) that require multiple files.
1lann #27
Posted 14 April 2013 - 04:19 PM
My way of coding is to do whatever I feel like doing. I normally think in sections though.
M4sh3dP0t4t03 #28
Posted 15 April 2013 - 12:34 AM
My way of coding is putting on music loud and write everything i need in functions, so the actual code that isnt functions is only a few lines.