Learning resources for a new programmer

Post Reply
User avatar
Komodo
Member
Posts: 163
Joined: Tue Jan 11, 2022 13:33
GitHub: MeseCraft
In-game: Komodo
Location: God Bless America
Contact:

Learning resources for a new programmer

by Komodo » Post

Hi all,

I started getting into Minetest a few years ago when I began a journey to dump as much proprietary software from my user-environment as possible. I ended up running GNU+Linux and playing a lot on Rubenwardy's CTF server to help ween me off what I was used to. After a year or so, I began trying to host my own server and started modding MTG, then it grew into a standalone in-development game, now its starting to grow into a larger mission to create something with more appeal to a more general audience, MeseCraft (www.mesecraft.com).

However, I'm quite the development novice. Minetest modding has been my only real practical development experience. I took C++ in college with a focus on applying it to business solutions (I have an M.B.A. and a degree in Information Systems and Security). I find that programming with a goal in mind has been a great motivator to help me learn more about coding and Lua. I've really enjoyed learning more about git and other fundamentals.

However, I lack the experience and foundations that a lot of you have here. I want to improve my skills. Can anyone suggest ways for me to improve my skills and education a bit? I feel like taking up some reading or projects at some point to become better at programming. Maybe some basic blender skills too. I am technically savvy. I have a double major in Information technology degrees and have worked in that field for some years. But I just lack development knowledge. I'm curious what you guys would recommend to me. Thank you.

tl;dr What are some good resources for a newbie to learn programming more to help my Minetest and Lua skills.
🌎 Website | 🌲 MeseCraft Game | 📰 News | 🖌️ ContentDB


User avatar
Komodo
Member
Posts: 163
Joined: Tue Jan 11, 2022 13:33
GitHub: MeseCraft
In-game: Komodo
Location: God Bless America
Contact:

Re: Learning resources for a new programmer

by Komodo » Post

Thanks. I already had that one bookmarked.
🌎 Website | 🌲 MeseCraft Game | 📰 News | 🖌️ ContentDB

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Learning resources for a new programmer

by Blockhead » Post

There are a few routes to go really and I can't say what's best for you. What I can definitely say though is that the process of learning programming feels like one big battle against fuzziness of various concepts into making things clear and concrete enough to be able to express them in adequate detail for a computer to understand. Anyway here are some various thoughts about what I feel is important to learning programming.

Consider taking more higher education subjects specifically in programming. These have assignments catered to the difficulty level of the programming in the course. As a postgraduate with an IT background you might be able to get into one with a prerequisite or two which is throwing yourself into the deep end in a good way. Apart from assignments the other major benefit is being able to interact with lecturers and especially tutors and lab assistants*. You will get the most out of these people though if you come to their classes properly prepared with questions to ask. Though if you did well in your degree you probably know to interact with the teaching staff, unless you were either a whizz-bang introverted wonder student (unlikely unless the course is too easy), or didn't have enough of an inquiring mind.

Learn how to read code written by other people. Learn how to understand what's going on and how to tear stuff apart. And definitely never be afraid to start opening source code, texture files, model files and just generally pulling stuff apart. I love hex editors! I feel that just knowing that everything is a sequence of bytes breaks the mysticism of stuff. I always think people should know low-level language concepts like C, but it does take a lot of exposure and experience to understand how to get from there to a high-level language, so maybe that's just an opinion. Lua is dynamically typed but at the same kind of low level just be being rudimentary.

Learn to love the docs and other primary sources, and learn to tinker: I really never gelled with programming tutorials. The mostly exist in two flavours: So basic you can skip most of it when learn a second programming language, and so specific to a language, framework and use case that you only need them if you get stuck at work. It takes a lot of effort to pivot from the copy-paste stage to feeling confident to program on your own. So what do I recommend instead of tutorials? Programming Language manuals and API docs. Learning how to use these as reference material frees you of over-dependence on search engines. It's mostly just Ctrl+F and prior knowledge :P

Learn how to debug without a search engine: Look, when you get stuck there's sites like StackOverflow or the problem section on these forums. These are great when you just don't know what's wrong. But when there's no immediate answer from searching around, the fastest way to solve it isn't going to be to wait for someone who may not even be in your timezone to answer the question. Asking questions that are too basic and/or too often will also get on people's nerves (some people are not very nice sadly, in particular some programmers have delusions of grandeur). Actually for basic questions I would probably recommend the Minetest IRC channel, they seem friendly enough. To really debug, you need to learn how to read error messages, and use tools like debug statements. Sometimes I might wish for a real Minetest debugger but you know what? worldedit's //lua, the qa_block mod and others are my really good friends.

Can't stress this enough - learn computer science concepts of: number theory, graph theory, computability, complexity. These are the fundamentals which transcend specific languages. There's a lot of university courses that cover these kinds of things and you probably don't feel like going back for a whole new degree. The internet can definitely help!
From the other end: while you need to be learning fundamentals, you need to be learning higher level design patterns. Actually, pretty much none of the mod code I've read or written strictly conforms to Object Oriented concepts, and in some cases is pretty poorly structured. The result is spaghetti architectures. Imagine a bowl of spaghetti. You pull one strand and most of the rest of the spaghetti moves. Just to name dump a few concepts here I will say: callback functions, closures (those two are everywhere in Minetest); coupling, cohesion, Gang of Four patterns, unit testing.

*(computer lab practicals-exercises classes, language may vary per country and institution)
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Komodo
Member
Posts: 163
Joined: Tue Jan 11, 2022 13:33
GitHub: MeseCraft
In-game: Komodo
Location: God Bless America
Contact:

Re: Learning resources for a new programmer

by Komodo » Post

Blockhead, thank you for the really flushed out and in-depth response. I'm not going back to university for anything. But I've been considering taking some programming classes at my local community college. I'm currently studying for some computer networking and security certifications though and won't be able to take up classes in programming for awhile.

I like pouring through source and files. I've been modding for nearly two to three years now. Most of what I know so far has come from reading other people's work and playing with it. I love doing this stuff. But once in awhile though it's just too advanced for me to wrap my head around it though. It's humbling and frustrating.

I just bookmarked the Lua documentation as well. I'll give it a read soon too. I haven't used any debug statements for mods, but usually reference my console/server log output to get an idea of what is going on with errors and warnings.

Computer science concepts is probably also one of the areas an academic education would help me here, but as I've said already, I'm unwilling to return to university to learn this. Are there any recommended books I can get started on to help me get the fundamentals of compsci?

Thanks for the great response.
🌎 Website | 🌲 MeseCraft Game | 📰 News | 🖌️ ContentDB

User avatar
MisterE
Member
Posts: 693
Joined: Sun Feb 16, 2020 21:06
GitHub: MisterE123
IRC: MisterE
In-game: MisterE

Re: Learning resources for a new programmer

by MisterE » Post

Here are some tips ive picked up:

Study Zughy's modding style. It is a great style that keeps code clean and readable.
https://gitlab.com/zughy-friends-minetest/arena_lib

Theres a good example.

The basics are:
1) use standard variable names:
Ex:
player for the player objectreference
p_name for the player name
pl_name for the player name in a loop or where p_name is already taken

2) define all your functions at the top of the file, then write the actual functions at the bottom of the file (except for apis)

ex:

Code: Select all

--top
function mymod.move_player(p_name) end
function mymod.chat_prefix(str,p_name) end

-- middle

<use the functions>

-- end

<actually write the functions>

function mymod.move_player(p_name) 
    local player = minetest.get_player_by_name(p_name)
    if not player then return end
    player:set_pos(vector.new(0,0,0))
end

function mymod.chat_prefix(str,p_name) 
    return "[Rank"..mymod.ranks[p_name].."] "..str
end
that helps you think about what functions you will need when writing the code and it helps you get to the important parts of the code first when reading the code

----


Always nil check variables that could be nil. Pass p_name in functions whenever it makes sense, and get the player and nilcheck for player existence when you do.

When searching an area for objects, check that the object is not a player if you intend to do entity operations on it, and also check that the entity name is correct

Code: Select all

for _,obj in pairs(minetest.get_objects_inside_radius(pos,3)
    local ent = obj:get_luaentity()
    if not ent then return end
    if ent.name ~= "mymod:ent" then return end
    obj:remove()
end
another coding tip: use whitespace everywhere so you can read the code
another: document the purpose of functions, and their inputs and outputs, in-code using comments above the function definition. That will make it easier to use the function when you return a week later and have forgotten what the function does exactly. It will also make documentation easier when the mod is finished.
another: use global variables (in an api table for the mod) for anything that other modders might want to change later from other mods. Use globals for functions so that other mods can overwrite the functions with new functionality, use globals for settings so other mods can tweak your mod. This has proven extremely useful, for example when modifying the nether (as I did for yourland... on yourland the nether is a layer on the top of the world with bedrock underneath._

ThorfinnS
Member
Posts: 311
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Learning resources for a new programmer

by ThorfinnS » Post

You already said you like reading others' code. That's the best idea. The trick is figuring out whose code to read.

Many of the authors of the highly ranked mods write good code. There are exceptions both directions -- some very good mods with poor coding and some poorly ranked mods with good coding. One thing you might find helpful is to focus on mods that have had frequent content updates. This usually means the coder wrote it so it is easy to maintain and extend, both highly desirable qualities.

I'm not going to name names, for obvious reasons, but as a starting point, go to either released mods or WIP mods forum and scan through for threads with a long history and lots of pages, looking for a couple things specifically -- frequent content updates and rapid bug fixes. If there's regular content additions, that's a good sign. It probably means it's coded so as to be easily maintained. Either that or it's largely in-line coded with lots of copy-paste duplication. If there's a lot of bug fixes, that might be a good thing if they are fixed promptly. In my experience, rapid bug fixes tend to be either because of good coding practice or prima donna programmers, and a quick glance at the code can usually distinguish betwixt.

There are some sleepers you will miss that way. There are quite a few that were released bug-free and of limited scope that will necessarily be short threads. I don't know of any way to pick those out if you don't already know what you are looking for.

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Learning resources for a new programmer

by Blockhead » Post

Komodo wrote:
Tue Jan 18, 2022 13:17
Blockhead, thank you for the really flushed out and in-depth response. I'm not going back to university for anything. But I've been considering taking some programming classes at my local community college. I'm currently studying for some computer networking and security certifications though and won't be able to take up classes in programming for awhile.
You're welcome. I get not wanting to go back; it takes serious time, effort, money. As long as you're happy in community college, and most importantly you find someone with enthusiasm and more than shallow knowledge to talk to, it should be good*
Komodo wrote:
Tue Jan 18, 2022 13:17
I like pouring through source and files. I've been modding for nearly two to three years now. Most of what I know so far has come from reading other people's work and playing with it. I love doing this stuff. But once in awhile though it's just too advanced for me to wrap my head around it though. It's humbling and frustrating.
A few things could be happening there. First, you might not be able to recognise what's happening because there are 0 comments and you don't know the algorithm. Common algorithms can go uncommented by some people who just know them really well. And a smart programmer isn't necessarily one who actually follows good practice with variable naming. That's why as I said its good to learn computer science and mathematics concepts. I also forgot to mention linear algebra is really useful for anything to do with 3D space including Minetest (and I wish I had studied it better).

Another thing that could be happening is that the code works fine but it's structured poorly and it gets too hard to see the right trees in the forest, so to speak. I say: don't be afraid to talk to mod authors directly. In many cases you can play with them on a Minetest server or find them on IRC/Discord. In Minetest it's almost all open source, so people have a good culture of discussing the internals of what they do and not hiding it like proprietary modding/game dev.
Komodo wrote:
Tue Jan 18, 2022 13:17
I just bookmarked the Lua documentation as well. I'll give it a read soon too. I haven't used any debug statements for mods, but usually reference my console/server log output to get an idea of what is going on with errors and warnings.
I like to keep copies of really important stuff on my hard drive but it's up to you. You can boomark a file:/// URL just as well as an http:// one. Also on Linux a lot of programming languages and even libraries can have documentation as part of the man system (C, Perl, Tcl/Tk do this) or a *-doc package that installs the documentation in some format like HTML, PDF and often even examples.

The logging in Minetest is a good way to monitor stuff whether you're running a server or debugging. Get used to launching Minetest on the command line and setting a higher/lower debug level if you want to make best use of that. minetest --help should give help on any platform and on Linux if it's installed through the package manager there's also man minetest.
Komodo wrote:
Tue Jan 18, 2022 13:17
Computer science concepts is probably also one of the areas an academic education would help me here, but as I've said already, I'm unwilling to return to university to learn this. Are there any recommended books I can get started on to help me get the fundamentals of compsci?
Well-written textbooks are a great way to learn for sure. I'm probably the wrong guy to ask for recommendations though. You might try looking into OpenCourseWare or similar. Also, look at what subjects are in a Computer Science or Software Engineering type degree and what textbooks they would have. You can also pretty easily find online course notes or even online textbooks written by the Professors/Lecturers from some Universities. It's a mixed bag - some are only on University internal networks, others are on the open web.

As a general rule I would say a 3rd party textbook on a specific programming language isn't really that useful compared to say, the language docs + equivalent of The Java Tutorial, Programming in Lua etc. A textbook that covers algorithms and data structures can be of great help though. A book on algorithms will also helpfully contain an explanation of computational complexity. Such a book is probably also structured better than meandering reading through Wikipedia's different pages on various algorithms and data structures.

For what it's worth, the Algorithms subject I took at University prescribed Introduction to the design and analysis of algorithms (Anany Levitin 2007). Another important subject covered Logic, Proofs, Graph Theory, Set Theory (I will grant some of these topics could be considered more useful to academic computer science than practical programming, but if nothing else they teach you how to structure your thought). Some people recommend some of the bestsellers like The Wizard Book (SICP) and they're probably right, I haven't read it. So far as I can tell SICP is also a very academic way to learn to program, but that's for the best I think.

Don't get overwhelmed. The way I see it, the more you get exposed to the language of computer science, and the more you study its various pieces, the more you'll feel comfortable fitting each piece into a whole. The order one university will do subjects in a software degree varies from another university as well, so don't stress about a 'right' order to learn things in toooo much. And like you said, motivation to learn comes from wanting to do something with it. Through effort, you accumulate the skills so that the next problem is one you might have already solved before.

*(the system is a bit different over in Australia, so I don't know what community college entails compared to a university; the closest thing is probably TAFE. University fees are also quite a bit lower for Australian citizens compared to USA).
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

ThorfinnS
Member
Posts: 311
Joined: Mon Feb 25, 2019 22:05
GitHub: ThorfinnS

Re: Learning resources for a new programmer

by ThorfinnS » Post

Blockhead wrote:
Wed Jan 19, 2022 12:10
A few things could be happening there...
Another possibility is magic. You can sit and stare at [instant_ores] for a long time and not get it. The author's comment is something about it shouldn't work. Don't know about that, but it is not intuitive.

Komodo, it depends on where you want to go with your coding. Like I counsel the teens I work with, don't bite off something too ambitious. You will just get frustrated. Start with something small, get confidence there. I'm old school, as in card decks, so have a lot of formal knowledge of algorithms, but unless you are doing work on the engine, you probably are not going to need any of that. You are coding (scripting, really) in Lua, not C, so most of the algorithms you might want are already there.

Pick some idea you have in mind, grab a couple mods that did something similar, and see how they did it. That's not cheating or anything. Pull up the minetest docs and see other ways of using the same functions. Quite often there's a slicker way to do something, but it was implemented in a later version of the engine code.

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests