code-organization

What is the benefit of nesting functions (in general/in Swift)

耗尽温柔 提交于 2019-11-26 23:11:57
问题 I'm just learning some Swift and I've come across the section that talks about nesting functions: Functions can be nested. Nested functions have access to variables that were declared in the outer function. You can use nested functions to organize the code in a function that is long or complex. From here So if the purported benefit is to "organize the code", why not just have the nested function independently, outside of the outer function? That, to me, seems more organized. The only benefit

How to organize large R programs?

我的未来我决定 提交于 2019-11-26 21:13:08
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. Treat ( like {? Put things like )} on 1 or 2 lines? Basically, what are your rules of thumb for organizing

Are there tools that help organizing #includes?

一世执手 提交于 2019-11-26 20:25:11
问题 Are there any tools that help organizing the #include s that belong at the top of a .c or .h file? I was just wondering because I am reorganizing my code, moving various small function definitions/declarations from one long file into different smaller files. Now each of the smaller files needs a subset of the #include s that were at the top of the long file. It's just annoying and error-prone to figure out all #includes by hand. Often the code compiles even though not all #include s are there

How to organize F# source of large project (>300 classes) in Visual Studio?

谁说胖子不能爱 提交于 2019-11-26 19:52:16
问题 In C# you can put files in folders corresponding to their namespaces and view them in the Solution explorer. In F# it seems I have to put everything in plain specifically ordered list for compilation. When I get to scale of ~300 of classes it gets a bit confusing and disorganized and I start to envy C# and think that probably it is the price for type inference. Are there better options than splitting to several assemblies? Judging by F# compiler source its the route they have taken but I have

Where do the Python unit tests go?

佐手、 提交于 2019-11-26 19:16:15
If you're writing a library, or an app, where do the unit test files go? It's nice to separate the test files from the main app code, but it's awkward to put them into a "tests" subdirectory inside of the app root directory, because it makes it harder to import the modules that you'll be testing. Is there a best practice here? user6868 For a file module.py , the unit test should normally be called test_module.py , following Pythonic naming conventions. There are several commonly accepted places to put test_module.py : In the same directory as module.py . In ../tests/test_module.py (at the same

How do I deal with many levels of indentation?

廉价感情. 提交于 2019-11-26 19:10:29
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 will render those two names out of context. I would have to send in these two variables everytime I use a where

Domain Driven Design - how the layers should be organized?

放肆的年华 提交于 2019-11-26 18:58:23
问题 I'm very much new to software development. I think layered architecture is a great way to reduce the complexities that arise in the process of object oriented software development and, not to mention, to keep your code organized. I'm interested to learn about Domain Driven Design approach and I've run into some problems to get myself introduced to it (of course, beginner level ones). Here it is - I want to build an application to save person related data in database and display person details

Why is each public class in a separate file?

有些话、适合烂在心里 提交于 2019-11-26 17:31:19
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?). According to the Java Language Specification, Third Edition : This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java

Where do the Python unit tests go?

限于喜欢 提交于 2019-11-26 12:16:33
问题 If you\'re writing a library, or an app, where do the unit test files go? It\'s nice to separate the test files from the main app code, but it\'s awkward to put them into a \"tests\" subdirectory inside of the app root directory, because it makes it harder to import the modules that you\'ll be testing. Is there a best practice here? 回答1: For a file module.py , the unit test should normally be called test_module.py , following Pythonic naming conventions. There are several commonly accepted

Including one C source file in another?

淺唱寂寞╮ 提交于 2019-11-26 10:16:40
Is it OK (or even recommended/good practice) to #include .c file in another .c file? What happens when they are included in a project file? 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 solution will probably be layered, modular and decoupled