This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
your way of coding?
Started by Jappards, 10 April 2013 - 07:11 AMPosted 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?
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/>
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/>
Warning, the following is advertisement, not blocked by Adblock+ :
See my channel, then you can see it. Im currently rendering a debugging video :P/>
Posted 10 April 2013 - 09:34 AM
Basically this.Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
Posted 10 April 2013 - 09:57 AM
Couldn't agree any more :P/>Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
Posted 10 April 2013 - 09:59 AM
Lua is nothing but functions and tables :P/>Couldn't agree any more :P/>Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>
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.
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.
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.
Posted 10 April 2013 - 10:16 AM
Lua is nothing but functions and tables :P/>/>Couldn't agree any more :P/>/>Have everything in functions then call each of those functions in a master function that gets called at the end of the script :P/>/>/>
And numbers, strings, nils, booleans, and coroutines =P
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.
Posted 10 April 2013 - 10:50 AM
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.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.
Posted 10 April 2013 - 04:37 PM
I used AdBlock+ to destroy any trace of your comment. So ha.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/>
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.
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.
Posted 10 April 2013 - 05:23 PM
Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.All of my code goes in functions, except for a while true do statement and a few if statements.
Posted 10 April 2013 - 05:55 PM
My code is readable, well, to me anyways :P/>Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.All of my code goes in functions, except for a while true do statement and a few if statements.
Posted 10 April 2013 - 06:07 PM
Same, but I also do something a lot of new users are not doing, SPACING MY CODE SO ITS READABLE.All of my code goes in functions, except for a while true do statement and a few if statements.
Me too. OCD is one of the best qualities a programmer can have.
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.
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.
Posted 11 April 2013 - 01:17 AM
I write my code in functions in Sublime Text and then run the functions (usually)
Posted 11 April 2013 - 01:35 AM
Thats because Sublime Text is the best :P/>I write my code in functions in Sublime Text and then run the functions (usually)
Posted 11 April 2013 - 04:23 AM
Amen, brother.Thats because Sublime Text is the best :P/>/>/>I write my code in functions in Sublime Text and then run the functions (usually)
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* :)/>
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.
one recommendation is definitely, building your scripts out of chunks.
Posted 11 April 2013 - 12:57 PM
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.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* :)/>
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.
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.
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.
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.
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.
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.