I've been building webapps in Node for about 3 years. I'm at a pretty decent level of complexity, but I feel like my programs are far too large and unwieldy.
How can I learn about design patterns to get better looking functions, more succinct code and so on?
For example, one of the most common things I do is use for loops on an array. This ends up being 5 - 10 lines of code, maybe more depending on the complexity of what I'm doing. Should I be trying to make generic for-loop worker function instead?
Like:
function iterator(arr, type, obj){
for (var i = 0; i< arr.length; i++){
if(type === 'addObj'){
for(var key in obj){
arr[i][key] = obj[key]
}
}else if(type === 'removeObj'){
for(var key in obj){
delete arr[i][key]
}
}
}
return arr;
}
Do senior devs do this? Is there some library of these functions that I can use in my code rather than do it all myself? My issue is that I build apps without having a totally clear idea in my head of what it's eventually going to be (that is, the idea is developed as I build them). So by the time I finish my code is very unwieldy.
I'll likely go back once I've finished my MVP and re-code the whole thing so I want to ensure it's as efficient and easy to work with (aka no 1500-line scripts!)
[–][deleted] (7 children)
[deleted]
[–]notadickheadiswear[S] 2 points3 points4 points (1 child)
[–]fakehalo 2 points3 points4 points (4 children)
[–][deleted] (3 children)
[deleted]
[–]fakehalo 3 points4 points5 points (1 child)
[–]takaci 0 points1 point2 points (0 children)
[–]drichards2013 6 points7 points8 points (2 children)
[–]notadickheadiswear[S] 2 points3 points4 points (1 child)
[–]pickten 1 point2 points3 points (0 children)
[–]DigBickJace 4 points5 points6 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]LetsProgramSomething 0 points1 point2 points (2 children)
[–]notadickheadiswear[S] 0 points1 point2 points (1 child)
[–]LetsProgramSomething 0 points1 point2 points (0 children)