21

I've had a look into CSS setups for a couple of projects that other people developed and I can understand most of what's going on.

The programmers have, however, created some files whose names start with the underscore (for example: _variables.scss). I have seen files named like this in both of the projects.

I can't figure out what this convention represents. Is there a special reason why the people are naming the files this way?

6
  • Why not ask them? I usually see underscore files as a way of notating that it's a ruby partial or ember partial....but I haven't seen it with scss files Jun 14, 2015 at 5:56
  • I think I just found out the reason... i think because those files are partials in sass
    – MariaZ
    Jun 14, 2015 at 6:04
  • 4
    From SASS Basics: "You can create partial Sass files that contain little snippets of CSS that you can include in other Sass files. This is a great way to modularize your CSS and help keep things easier to maintain. A partial is simply a Sass file named with a leading underscore. You might name it something like _partial.scss. The underscore lets Sass know that the file is only a partial file and that it should not be generated into a CSS file. Sass partials are used with the @import directive."
    – paulsm4
    Jun 14, 2015 at 6:07
  • OWw ow... So when I compile this code the _variables.scss will not be compiled and not _variable.css will be there isnt it?! oww I underestand! Thanks!
    – MariaZ
    Jun 14, 2015 at 6:15
  • 1
    @cimmanon This question comes first in DuckDuckGo, actually... before the Sass Basics page ;) Aug 22, 2015 at 11:28

3 Answers 3

22

The only reason I can find to use underscore before the name of the partial is what's described in the Sass docs here:

The underscore lets Sass know that the file is only a partial file and that it should not be generated into a CSS file.

Any SASS files not beginning with an underscore will be rendered on their own, which will fail if they are using variables or mixins defined elsewhere.

In the end I have concluded that the underscore is just used to clarify that it is a partial file. We can also use a partial file without using an underscore as prefix.

1

Sometimes that naming convention is used for templates or template part files, you could find this being used in MVC frameworks.

In other places this might mean that this variable or file is private and can only be accessed by the server or the running program. It all depends on the language you're programming really, but this is simply a naming convention.

1

It's just a naming convention. When you want to define a name for an interface you define it with (_interface). This is just for compatibility issues, In some cases a program may include classes and interfaces And in order to distinguish between the two, you use _ for interfaces. This is just one example as you can use it in the BLL layer when working with databases and so on.

It is an emphasis for other developer to notice the variables and objects.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.