2

I am working on an AngularJS app.

According to a lot of articles in the Web, every file on the project can not have more than 100 / 150 lines of code.

Then, here is where my concern comes up: if I am concatenating/minifying my code, at the end all of the code will be in one very big single file.

So in that case, the rule(good practice) of the 100 / 150 lines of code still applies in this case ?

3
  • I don't think 100/150 lines of code is a good measure of code complexity, in general. As long as the code is clearly written and well structured, lines of code is not a big issue. Commented May 18, 2015 at 21:16
  • where are you reading this? Commented May 18, 2015 at 21:17
  • 100/150 is for readability so that you can understand and modify the code easily, one big file is for running it on computer so that your app doesn't need to make 100s of http calls to server to download each file. Commented May 18, 2015 at 22:51

2 Answers 2

1

Kylek is right on about small files being for developers, and big files being for machines. More specifically, if you're interested, read about synchronous http calls and web loading speed. Basically, every separate external resource you have load on the page (a css file, or a javascript file) requires overhead on top of the actual content download, so for maximum speed, you want both a small number of files (accomplished by concatenation) and a small content size (accomplished by minification).

Of course, as a developer, you still don't want to have to worry about this while writing and maintaining code. Check out grunt, specifically uglify and cssmin, which can keep monolithic minified files up to date for you while you work on your source. Regarding angularjs in particular, make sure you're using dependency annotation or minification will break your code.

Sign up to request clarification or add additional context in comments.

Comments

1

Keep files small is not a performance good practice but a way to keep things organized for developers and to find quickly what you are looking for, it's not for machines but for humans.

No human will have to develop minified files, so no coding rules apply to minified files. A contrario, minify and concat JS, CSS etc. make your pages load faster. It's a performance good practice.

By the way, do not follow a rule because some one tell you to. Be sure the rule match your case, your project, your team, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.