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
8
votes
4 answers

Writing style to prevent string concatenation in a list of strings

Suppose I have a list/tuple of strings, COLOURS = [ "White", "Black", "Red" "Green", "Blue" ] for c in COLOURS: # rest of the code Sometimes I forget placing a comma after each entry in the list ("Red" in the above…
Shiva
  • 2,627
  • 21
  • 33
8
votes
3 answers

How to correctly achieve test isolation with a stateful Python module?

The project I'm working on is a business logic software wrapped up as a Python package. The idea is that various script or application will import it, initialize it, then use it. It currently has a top level init() method that does the…
Luke404
  • 10,282
  • 3
  • 25
  • 31
7
votes
2 answers

module_load_include() vs require_once

I was wondering when you need to use module_load_include() or require_once to include files which are located within your module.
Frederic
  • 85
  • 1
  • 3
7
votes
3 answers

What is an acceptable way to format a long method call in Java?

Is it good style to write: objectName.methodWithManyParameters(someLongParameter1, someLongParameter2, someLongParameter3, someLongParameter4, someLongParameter5); (which is obviously far to long for one line)…
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
7
votes
2 answers

Should I document the self-explanatory private methods? (Java)

I like properly documented code and it is no-brainer for me to have properly documented public methods describing the contract and same applies for private or package internal methods to explain the code internals / implementation. However I am not…
ps-aux
  • 11,627
  • 25
  • 81
  • 128
7
votes
3 answers

.NET interview, code structure and the design

I have been given the below .NET question in an interview. I don’t know why I got low marks. Unfortunately I did not get a feedback. Question: The file hockey.csv contains the results from the Hockey Premier League. The columns ‘For’ and ‘Against’…
j_lewis
  • 81
  • 5
6
votes
2 answers

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

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 =…
mfaani
  • 33,269
  • 19
  • 164
  • 293
6
votes
3 answers

if-else or early return

Sometimes I like to use early return statements to prevent nesting if statement, which I find makes for less readable code. I am wondering if there is any objective or overwhelming general consensus as two which of the following patterns is better…
Scorb
  • 1,654
  • 13
  • 70
  • 144
6
votes
5 answers

javascript / jquery code organisation

I would like to get some advice on structuring my javascript code and jquery functions. I like to use JQuery for dom event handling and ajax etc. I have written what seems like poor code in the past where my entire js file consists of a bunch of…
aeq
  • 10,377
  • 15
  • 45
  • 46
6
votes
4 answers

Clean design for centralized navigation?

Context Single page / ajax web app Basic code structure LocationManager (responsible for updating the browser hash and switching the application location to a different tile) Page/Tile Flow Basic Info > Household Info > Vehicle Info > Purchase…
antonpug
  • 13,724
  • 28
  • 88
  • 129
6
votes
3 answers

How to organize Python source code files?

I am developing a Python App Engine app, where I want to split the content of a source code file Models.py into separate files for each model, but I want to put it all in a folder called Models. The problem is that when I do that, my app can't find…
6
votes
9 answers

Why use short-circuit code?

Related Questions: Benefits of using short-circuit evaluation, Why would a language NOT use Short-circuit evaluation?, Can someone explain this line of code please? (Logic & Assignment operators) There are questions about the benefits of a language…
Tim Lytle
  • 17,549
  • 10
  • 60
  • 91
5
votes
4 answers

How do I make destructors protected for a whole class hierarchy in a maintainable way?

I would like to make sure no one is able to delete any objects from my class hierarchy other then by using a provided Destroy method. The rationale is that any object from this hierarchy needs to take a special write mutex before it starts to…
RnR
  • 2,096
  • 1
  • 15
  • 23
4
votes
1 answer

How to automatically arrange the code structure?

I have observed that components has a uniform, neat and well arrange code structure. was it automatically arranged or manual? is there a way to make it automatic? like Code Completion in Delphi? I am using Delphi 7, 2009, 2010 XE
XBasic3000
  • 3,418
  • 5
  • 46
  • 91
4
votes
2 answers

How to use a local Swift Package which provides two libraries?

I have a local swift package Foo which provides two different libraries Foo and FooB. Now I would like to use them in another local package Bar. I am only able to get the whole package by path declaration. Is there a way to name/specify which…
1
2
3
13 14