I'm no old school programmer, so when I look through this code, it looks insane! The first file I opened was 8000 likes of straight imperative C code.
So my question is, how do you manage? How can you read through this code and have any idea whats going on? How do you write terminal applications in C? Where's the documentation for that kind of thing? I'm assuming you must have powerful IDEs help guide you through this code. But I'm still baffled...
I'm just generally curious how you managed to build something like this. It would be great if you tailored your answer towards someone coming from the JavaScript / Python world.
I'm no old school programmer, so when I look through this code, it looks insane! The first file I opened was 8000 likes of straight imperative C code.
It's true that there are a couple of such massive files like wee-command.c or irc-protocol.c which theoretically could be better organized into separate files in some logical way but I wouldn't say it's a show-stopper.
So my question is, how do you manage?
Whenever you're actually working on something you don't need to be looking at all those 8000 lines, you're looking at a single function in that file and using find to get to it. So it doesn't really matter how big the file is because you don't scroll it by hand.
How can you read through this code and have any idea whats going on?
Similarly to my last point, you don't really read through it all because WeeChat has a lot of code. I've done a lot of PRs for it and had to work with a lot of the code but there are certainly parts and files of the entire project which I've never read because I've never needed to. If you're doing something you start from a point in code where you know something happens from, e.g. command gets called or IRC command comes in, and start working from there as opposed to having to know how the command has been read from ncurses input or over the network and parsed, that's most likely irrelevant to what you're trying to do as long as it works.
How do you write terminal applications in C?
I personally haven't written anything big like WeeChat from scratch. The central part about working with the terminal is done by a library called ncurses which provides functions which allow manipulating the entire terminal window character by character, apply colors etc.
Where's the documentation for that kind of thing?
The main outline for WeeChat's codebase is described in the Developer's guide. More detailed descriptions of certain plugin API functions are documented in the Plugin API reference. In addition there are parts of WeeChat which aren't exposed like that and have no separate written documentation but rather simply have descriptive function documentation within the code itself, although they might not always be enough to give a good understanding of how they fit into the whole program.
I'm assuming you must have powerful IDEs help guide you through this code.
It's definitely not true for me, I pretty much use out-of-the-box vim to edit the code and make to build it again. Occasionally I have used gdb to step through some code also from the command line. It's really not that impossible to work like this although I have thought about using a separate IDE I haven't come around to doing it because there's not much to pick from to fit this workflow.
I'm just generally curious how you managed to build something like this.
This is better answered by @flashcode who has coded together pretty much all of WeeChat. Compared to him I've just scratched the surface with some bug fixes and feature additions.
Thanks for the answer @sim642! Thats pretty intense using straight-up vim. You must have some ninja skills. When you find a function and you want to jump to its definition, and then back to where you were, how do you do that in vim? Do you have a macro thats grepping under the hood?
I have to say I'm impressed by how causal this answer was. Sounds like I just need to keep sharpening my skills.
Thats pretty intense using straight-up vim. You must have some ninja skills.
I really don't, it's pretty much just simple find.
When you find a function and you want to jump to its definition, and then back to where you were, how do you do that in vim?
I don't. I just make enough splits to see all the things I need at once because otherwise I'd end up jumping back and forth as opposed to just being able to see everything at once.
Do you have a macro thats grepping under the hood?
When I need to find stuff between files I just run grep -r in a split terminal and that's it.
I guess I could be a lot faster and more effective navigating code with a full-blown IDE but I haven't felt that to be the limiting factor when working. Actually figuring out the way to solve something takes much more time and thinking, especially when it needs to fit everything that already exists, and also seeing if there's functions I can reuse to save time.
Alright then. Well more power to ya!
Most helpful comment
It's true that there are a couple of such massive files like
wee-command.corirc-protocol.cwhich theoretically could be better organized into separate files in some logical way but I wouldn't say it's a show-stopper.Whenever you're actually working on something you don't need to be looking at all those 8000 lines, you're looking at a single function in that file and using find to get to it. So it doesn't really matter how big the file is because you don't scroll it by hand.
Similarly to my last point, you don't really read through it all because WeeChat has a lot of code. I've done a lot of PRs for it and had to work with a lot of the code but there are certainly parts and files of the entire project which I've never read because I've never needed to. If you're doing something you start from a point in code where you know something happens from, e.g. command gets called or IRC command comes in, and start working from there as opposed to having to know how the command has been read from ncurses input or over the network and parsed, that's most likely irrelevant to what you're trying to do as long as it works.
I personally haven't written anything big like WeeChat from scratch. The central part about working with the terminal is done by a library called ncurses which provides functions which allow manipulating the entire terminal window character by character, apply colors etc.
The main outline for WeeChat's codebase is described in the Developer's guide. More detailed descriptions of certain plugin API functions are documented in the Plugin API reference. In addition there are parts of WeeChat which aren't exposed like that and have no separate written documentation but rather simply have descriptive function documentation within the code itself, although they might not always be enough to give a good understanding of how they fit into the whole program.
It's definitely not true for me, I pretty much use out-of-the-box
vimto edit the code andmaketo build it again. Occasionally I have usedgdbto step through some code also from the command line. It's really not that impossible to work like this although I have thought about using a separate IDE I haven't come around to doing it because there's not much to pick from to fit this workflow.This is better answered by @flashcode who has coded together pretty much all of WeeChat. Compared to him I've just scratched the surface with some bug fixes and feature additions.