-1

In quite a few object oriented languages, especially the ones without free standing functions, it's now best practice to have one class per file, with the file name being the same as the class name. E.g. MyClass.cs storing class MyClass - this kind of makes the concept of a file pointless.

Is it known what the reasons were for modern languages like java and c# keeping files as opposed to other solutions such as e.g. a database per project?

closed as unclear what you're asking by gnat, Thomas Owens Nov 7 '16 at 19:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

migrated from cs.stackexchange.com Nov 7 '16 at 19:21

This question came from our site for students, researchers and practitioners of computer science.

  • 2
    Files are very flexible. For example, you can use whatever revision control system you want, you can edit source code with whatever editor, and so on. – Yuval Filmus Nov 7 '16 at 17:26
  • 1
    In my own opinion, there is no deep "foundational" reason under this. It's a mere convention born out of practical simplicity, convenience, pragmatics and little else. I can see no science which influenced this decision. Even from a pure engineering point of view, this convention does not seem to be important. It merely helps the compiler to locate the source code without the programmer having to pass the whole of it to the compiler, or having to write interface/header files. – chi Nov 7 '16 at 18:05
  • 1
    1) This has nothing to do with computer science. 2) The reasons against databases are kind of obvious. – Raphael Nov 7 '16 at 19:21
  • 1
    1) In Java you can have several classes in the same source file. 2) How does having a class per file make the concept of a file pointless. 3) Is it only modern languages that keep source code in files? Didn't a lot of old languages also use files to store source code? – Tulains Córdova Nov 7 '16 at 19:27
  • 1
    @Servy Obviously I disagree. :) The syntax, allowed set of characters, and presentation of the language as text are as much related to language design than the notion that a project links multiple source files into one program. – Peter Nov 7 '16 at 19:30
5

Source code files have many advantages over source code databases. Just off the top of my head:

1) Easier to work with. You can open a text file in an IDE of your choice, or any text editor. A database would require an editor with a special interface. 2) Easier to share. It's a lot easier to send someone a single file containing a small snipped of code if that small snippet of code is contained in a single file in the first place. 3) Easier to version-control. Version control is designed for text, which means that text files can be versioned as-is by off-the-shelf version control software. Trying to version database-based code would be a mess!

Keep in mind the "minus 100 points" principle: every language feature takes a lot of work to create and implement, so the question isn't "why doesn't a language have feature X," but rather "is feature X useful enough to make it worthwhile to overcome the barriers to implementing it?" In the case of a feature like this, given that it would require a revamp of our entire coding infrastructure in order to support it, the barriers are higher than usual!

  • 1
    OP also insinuates that using files to store source code is something only "modern languages" do. – Tulains Córdova Nov 7 '16 at 19:30
  • "Is it known what the reasons were for modern languages like java and c# keeping files as opposed to other solutions such as e.g. a database per project?" – Tulains Córdova Nov 7 '16 at 19:35
  • 2
    the only reason for opening MyClass.cs is to view and/or edit the class MyClass -- Which is precisely the reason that each class goes into its own file, by convention. – Robert Harvey Nov 7 '16 at 20:20
  • 3
    Probably stretching definitions a little bit here, but I wanted to add that every file system is a database and every file in it is a table/entry. The concept of a 1D table of characters is a concept that has proven itself over the last hundreds of years. – null Nov 7 '16 at 20:58
  • 3
    @Peter: Because any system that gets in the way of version control, sharing, and arbitrary selection of editors is not programmer-friendly. Those things are far more fundamental than whatever benefits a "code database" might bring. – Mason Wheeler Nov 7 '16 at 21:44

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