code-organization

C++ Header order [closed]

混江龙づ霸主 提交于 2019-11-26 07:21:15
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . What order should headers be declared in a header / cpp file? Obviously those that are required by subsequent headers should be earlier and class specific headers should be in cpp scope not header scope, but is there a set order convention / best practice? 回答1: In a header

How to organize large R programs?

纵饮孤独 提交于 2019-11-26 06:51:15
问题 When I undertake an R project of any complexity, my scripts quickly get long and confusing. What are some practices I can adopt so that my code will always be a pleasure to work with? I\'m thinking about things like Placement of functions in source files When to break something out to another source file What should be in the master file Using functions as organizational units (whether this is worthwhile given that R makes it hard to access global state) Indentation / line break practices.

How do I deal with many levels of indentation?

泪湿孤枕 提交于 2019-11-26 06:08:43
问题 I am writing a script that has a very logically complicated loop: main = do inFH <- openFile \"...\" ReadMode outFH <- openFile \"...\" WriteMode forM myList $ \\ item -> ... if ... then ... else do ... case ... of Nothing -> ... Just x -> do ... ... The code soon flies to the right, so I was thinking breaking it into pieces, using for example where clauses. The problem is, many of these ... contain reading/writing statements to the two handles inFH and outFH , and using a where statement

Why is each public class in a separate file?

痞子三分冷 提交于 2019-11-26 06:06:09
问题 I recently started learning Java and found it very strange that every Java class must be declared in a separate file. I am a C# programmer and C# doesn\'t enforce any such restriction. Why does Java do this? Were there any design consideration? Edit (based on few answers): Why is Java not removing this restriction now in the age of IDEs? This will not break any existing code (or will it?). 回答1: According to the Java Language Specification, Third Edition: This restriction implies that there

Including one C source file in another?

懵懂的女人 提交于 2019-11-26 03:27:48
问题 Is it OK (or even recommended/good practice) to #include a .c file in another .c file? 回答1: Used properly, this can be a useful technique. Say you have a complex, performance critical subsystem with a fairly small public interface and a lot of non-reusable implementation code. The code runs to several thousand lines, a hundred or so private functions and quite a bit of private data. If you work with non-trivial embedded systems, you probably deal with this situation frequently enough. Your

Should &#39;using&#39; directives be inside or outside the namespace?

柔情痞子 提交于 2019-11-25 22:22:48
问题 I have been running StyleCop over some C# code, and it keeps reporting that my using directives should be inside the namespace. Is there a technical reason for putting the using directives inside instead of outside the namespace? 回答1: There is actually a (subtle) difference between the two. Imagine you have the following code in File1.cs: // File1.cs using System; namespace Outer.Inner { class Foo { static void Bar() { double d = Math.PI; } } } Now imagine that someone adds another file