3 Coding Habits you should start NOW to become a 6-figure software engineer

Phil Choi walks through three habits that separate higher-paid engineers from the rest: debugging carefully, refactoring code, and documenting with JSDoc. He shows a JavaScript function tested with Jest and explains how to use AI tools responsibly without letting them replace thinking.
Chapters
I see all these people using Copilot and using AI to write code. But if something breaks at your company, are you going to be able to debug it? Can you refactor it? No, probably not, because you didn't actually write the code. It all starts with forming good habits and you need to start these things from the beginning of your career. All of these things I'm about to show you, these are the things we have to do at work. So in this video we are going to show you with a simple function, how to write edge cases, how to test these cases, and how to go a step further and write documentation using jsdoc. My name is Phil, I became a senior developer after the age of 30. If this video becomes of use to you, please like share and comment on time. You use ChatGPT shamelessly. We've all done it and it's actually good to do it. But do you understand it? I read all my comments and would love to read your takes on this matter. Also, if you want to join a great coding community where we help each other level up, join my free discord and let's level up together. Today we're going to write like a simple function. I opened up a directory with the readme and I set up the project with NPM project. So I will update it into like, I think there's a repository called in the left field repository called Contents. I will push this code there. Just a simple function, edge cases, simple project to test and get documentation. NPM install minus D, capital D, Jest and jsdoc. So that's going to save it as a dev dependency. You can do minus capital D or minus minus save dev. I think minus capital D is a little bit shorter. And the packages we'll use is JEST and R JEST and jsdoc. So as you can see, I already installed JEST and JSDOC as dev dependencies. All you would need to do is just run this function here. I already did it, so I'll just do it one more time. Install D, Jest, JSDoc and I'll show you guys how to run this stuff. This is going to put stuff inside of your project, a whole bunch of node modules and stuff. But we're gonna have to look at this bin jsdoc file later on. So the first thing we'll do is. Actually a lot of people have been asking me what theme I'm using. The theme I'm using is called Arbiter. I'll have a video about like choosing themes and stuff Anyways, but it's just this extension here. Or maybe I'll do a video on JS extensions, but our Biter by Wonder Panda only has like 3800 downloads. It's very lightweight, I think one Dark Pro and things like that are very heavy. And this one's pretty lightweight. And it separates the colors from like your parameters pretty well. And that's why I like it. Anyways, so we're going to start writing a function. Let's call it some js. So very simply, if I write a function function, sum A and I'll pass in two arguments, A and B, and I'll return A plus B, right? So it's a very short function. It just sums two numbers. There we go. So now if I were to run this, s equals sum1 and 1 and I console.log s node sum js and s should equal 2, right? 1 plus 1 equals 2. So it's a simple function. If I were to write a test here, I could do sum test js, right? Now I can write test sum should add two numbers together. And then I call back here and then I expect sum of one and one and I expect that to be two. Right? Actually, one more thing I'll have to do like this module dot export. Now I am using common js. I think recently people use like module. So that's like the important export statement. So I wanted to use module. I just put module here. For our purposes today, let's use require statements. So now I have a test here. So now I can run NPM run test. And I made that function here. So test NPM run test is going to run jest. So if I run NPM run test, I failed the test. That is because in my sum test I did not require it. So const sum equals require at dot slash sum now and run my test cases. NPM run test. And now it's going to say one passed. I had one test and it passed, right? What if I passed in like I expected sum to equal one plus one to be three, then it would fail, right? Say one failed. Yeah, I expected three, but I received two. Okay, so now this is great and all there's a lot of edge cases here, right? Like what if one of the parameters is not like passed, right? So what if I do like test, both arguments should be present, right? And then I say function. And then what if I put like expect and then I. If I did sum on the just one, it should to throw. Both arguments should be passed at this point, if I run the Test it's going to fail one, right? Because it's not. We don't handle this yet. So function did not throw. So expected substring. Both arguments should be passed. Let's try to handle that. So now at this point if A is undefined or B is undefined, throw new error. We should pass both of them, right? We ran both of our functions, so right now B is not being passed. So that's a false value and that's going to throw. Both arguments should be passed, right? Now what if. Let's go test. Both arguments should be numbers. Expect some hello goodbye to throw, both arguments should be numbers. So now if I run this code, one failed, right? The hello goodbye function. So function did not throw throw an error here at this point, maybe if type of a doesn't equal number or type of B doesn't equal number, throw a new error. Both arguments should be numbers, right? So now if I run my test test suite. So one file, one test suite and then the there's three tests. So they all pass now. So that's cool. Like you can add more expects here like sum 50, 50 to be 100 I should pass 2 now everything passed. Awesome, awesome. So I know like sum could be a very simple function, but also like I think you have to like write the edge cases in case like someone doesn't pass. So like this is pretty foolproof now, right? I could run like sum on sum on like s equals sum on like null and 2 and if I ran node sum js, it should throw the right error, right? Both arguments should be passed, right? I guess it was passed, but it was null because the false value. But both arguments should be passed and be valid. But anyways, that's kind of like how you'd make this code like very foolproof. So that should be fine. And then now you have to write the documentation for it, right? So now you wrote some tests, now you can write some documentation. So how you write those JavaScript documentation is you press/star star and you press enter above the function and it'll give you like the parameters and then what it should return. So A should be a number and B should be a number. So number to be passed and added to B number to be passed and added to A. Okay, so that's a little bit of an explanation of what those parameters are and it returns a number and returns sum of A and B. That's what happens. There's like a bunch of little things you can do like borrows async if it's an async function. Then you can put like at definition as I like to put at description. And you can put takes two numbers and add step and then under there you can put like at example and then you can put like some one, one. Anyone that reads this code, they can kind of understand it. But now you probably need to give it to like give it to someone you're not going. And sometimes they don't want to clone the whole code base or something. So maybe at this time you could do, you could run this program called jsdoc. It saved me a lot of time at my job and I mean there's ways you can write in markdown like yourself. Like, I mean I think JSDOC does a good job of it. So the way you'd run that is I think inside of your dot slash node modules there's a dot bin file. So that's your binary files, I think so dot bin and then there's a JS doc file in there and then you point it at the file that you want the documentation for. So some js. So now there's an out folder and that gave me a index HTML. And then if I run that, I go live and I bring that here, I show you my sum function. It's all the documentation, what I wrote, right? It's sum and then A and B. And then it returns a number, takes two numbers and adds them up and takes number to be passed and added to B. Number added to A and then an example of how it's going to be used and it returns sum of A and B and the type is a number. So that's all people really need to know. And then it could, it would show you how the code looks inside of here as well. So JSD's really useful, very powerful. I think recently for TypeScript there's something called TS Doc. So I would definitely, you know, take advantage of all the tools there are to be like, like use and like help your team. So yeah, it's all very useful stuff. At the end of the day, ChatGPT is like a calculator we should use, but only when we know how to do the problem solving on our own. We should come up with the edge cases, we should learn how to do testing and we should be able to document our processes properly. Just remember, if I can do, can do it too. Boating saves lives.
More from Phil

day in the life of a software engineer | 5 hour productivity | building my dev agency 🔥

day in the life of a software engineer | 3 hour productivity | coding my 6-figure community startup

day in the life of a software engineer | 5 hour productivity | coding our sns startup app LFG

day in the life of a software engineer | 5 hour productivity | creating apps that makes big money






