code-structure

When should I use optionals and when should I use non-optionals with default values?

旧巷老猫 提交于 2019-11-29 21:54:29
问题 I know the recommended way in Swift is to use: class Address { var firstLine : String? var secondLine : String? } but sometimes I see other developers write their code this way: class Address { var firstLine : String = "" var secondLine : String = "" } Is this the unrecommended way because whenever you have nil you will just crash and there's no outlet for your to recover. Is that right? Or there are some use cases where using non-optionals with default can be good. If so then where? I saw

Declaring main function/entry point in Julia

南笙酒味 提交于 2019-11-29 09:36:37
Is there a ready or idiomatic way of declaring an entry point in a Julia program (i.e. the equivalent of main in C or the if __name__ == "__main__" construct in Python)? This seems to be an important functionality in order to write larger pieces of structured code that won't be used in interactive mode but I couldn't find any hints as to how this is accomplished in Julia, if at all (a possible escape route could be writing an arbitrary function to serve as main and then calling it once on the top level at the end of the main module but that's not elegant and maybe not even efficient). TIA.

How should I visualize the structure of my code? [closed]

怎甘沉沦 提交于 2019-11-28 03:23:36
I have an application written in Java. In is stored in several files. It uses different classes with different methods. The code is big and complicated. I think it would be easier to understand the code if I have a graphical model of the code (some kind of directed graph). Are there some standard methods for visualization of code. I am thinking about usage of UML (not sure it is a correct choice). Can anybody recommend me something? ADDED: I consider two possibilities: Creating the graph by hands (explicitly). Creating graph in an automatic way. For example to use some tools that read the

Declaring main function/entry point in Julia

醉酒当歌 提交于 2019-11-28 03:10:32
问题 Is there a ready or idiomatic way of declaring an entry point in a Julia program (i.e. the equivalent of main in C or the if __name__ == "__main__" construct in Python)? This seems to be an important functionality in order to write larger pieces of structured code that won't be used in interactive mode but I couldn't find any hints as to how this is accomplished in Julia, if at all (a possible escape route could be writing an arbitrary function to serve as main and then calling it once on the

Why are some functions extremely long? (ideas needed for an academic research!) [closed]

旧城冷巷雨未停 提交于 2019-11-27 15:07:29
问题 I am writing a small academic research project about extremely long functions. Obviously, I am not looking for examples for bad programming, but for examples of 100, 200 and 600 lines long functions which makes sense. I will be investigating the Linux kernel source using a script written for a Master's degree written in the Hebrew University, which measures different parameters like number of lines of code, function complexity (measured by MCC) and other goodies. By the way, It's a neat study

When should one prefer Kotlin extension functions?

Deadly 提交于 2019-11-26 12:39:12
问题 In Kotlin, a function with at least one argument can be defined either as a regular non-member function or as an extension function with one argument being a receiver. As to the scoping, there seems to be no difference: both can be declared inside or outside classes and other functions, and both can or cannot have visibility modifiers equally. Language reference seems not to recommend using regular functions or extension functions for different situations. So, my question is: when do

Order of items in classes: Fields, Properties, Constructors, Methods

谁都会走 提交于 2019-11-26 02:59:15
问题 Is there an official C# guideline for the order of items in terms of class structure? Does it go: Public Fields Private Fields Properties Constructors Methods ? I\'m curious if there is a hard and fast rule about the order of items? I\'m kind of all over the place. I want to stick with a particular standard so I can do it everywhere. The real problem is my more complex properties end up looking a lot like methods and they feel out of place at the top before the constructor. Any tips