Questions tagged [code-structure]

Code Structure regards the way that code is written to allow it to be best read, maintained and organized for efficiency. Decisions such as when classes should be used, and which patterns would be most efficient for a task.

This is a cross-language discipline that allows code to be read and maintained easier. In some areas, such as simple web design, this may relate simply to best practices, such as creating your CSS using a separate file, and then organising this in a way that makes the most sense (starting with a browser reset, then the structure, and then into areas such as fonts).

In more complex languages, however, this also involves the use of patterns to be most efficient, and removing duplicated code and overall making your application appear much simpler.

204 questions
798
votes
16 answers

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

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…
mmcdole
  • 91,488
  • 60
  • 186
  • 222
79
votes
4 answers

How to deal with Pylint's "too-many-instance-attributes" message?

I have just tried to lint some code with Pylint, and the last remaining error is R0902: too-many-instance-attributes (8/7) I understand the rationale behind limiting the number of instance attributes, but seven seems a bit low. I also realise that…
78
votes
4 answers

When should one prefer Kotlin extension functions?

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…
hotkey
  • 140,743
  • 39
  • 371
  • 326
44
votes
10 answers

How should I visualize the structure of my code?

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…
Roman
  • 124,451
  • 167
  • 349
  • 456
23
votes
3 answers

How do I automatically sort methods by header?

It is good style to sort methods in header files in the same order as in the .cpp file, but often this order gets crude during development. How can I reorder the methods in the cpp file to the order given in the header file?
Gerrit
  • 641
  • 1
  • 5
  • 19
22
votes
2 answers

React Native: How to split a file up into multiple files and import them?

I am writing my first app in react native and my js file is getting pretty big. What is the proper way to split the file up. If i have something like var MyClass = React.createClass({ ... }) Can I save it at myclass.js and include in by some…
19
votes
1 answer

documenting side-effects of javascript methods

I'm trying to improve the documentation of my javascript code, and am following the JSDoc guidelines https://jsdoc.app/. I can't find how to document an intentional side-effect. For example the following method: /** * @description * Paints the…
mastaBlasta
  • 5,700
  • 1
  • 24
  • 26
18
votes
5 answers

Erlang source code guide

I am interested in delving into Erlang's C source code and try to understand what is going on under the hood. Where can I find info on the design and structure of the code?
GabiMe
  • 18,105
  • 28
  • 76
  • 113
17
votes
3 answers

Declaring main function/entry point in Julia

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…
Arets Paeglis
  • 3,856
  • 4
  • 35
  • 44
15
votes
9 answers

Cleaning up a large, legacy Java project

I've been assigned to do some work on a huge Java project, and the influence of several iterations of developers is obvious. There is no standard coding style, formatting, naming conventions or class structure. It's a good day when I come across a…
Andy
  • 2,764
  • 6
  • 24
  • 33
12
votes
3 answers

merge multiple annotations with parameters

I have a problem with using multiple annotations that all say more or less the same thing but to different frameworks and I would like to group them all into one custom annotation. Currently it looks like this: @Column(name =…
munHunger
  • 2,572
  • 5
  • 34
  • 63
12
votes
2 answers

What is a good code structure for api-independent vertex processing?

Currently working on a 3D media engine using C# and I have come across a little conundrum. I have my rending loop figured out, I got a great plug-in architecture and content management system and even a material pipeline all planned out. Then engine…
zackery.fix
  • 1,786
  • 2
  • 11
  • 20
12
votes
4 answers

jQuery/JavaScript: Detecting scroll direction - code structure issue

I need to detect the direction in that a user scrolls - "up" or "down". Based on the code found in this answer: How can I determine the direction of a jQuery scroll event? I tried to wrap it in a function so it's a bit more differentiated - but…
Sven
  • 12,997
  • 27
  • 90
  • 148
11
votes
1 answer

Idiomatic approach for structuring Clojure source code

I'm interested in how people structure their Clojure source code. Being used to Java, I'm pretty familiar with the paradigm of one class per source code file, bundling all the data and method definitions with appropriate comments and annotations…
mikera
  • 105,238
  • 25
  • 256
  • 415
10
votes
4 answers

Should I define functions inside or outside of main()?

After reading the following, I think I understand the value of wrapping even the simplest of scripts in a main() function. Should I use a main() method in a simple Python script? Why use def main()? Should I define all my functions inside or…
chishaku
  • 4,577
  • 3
  • 25
  • 33
1
2 3
13 14