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

PHP application structure

I started making a website, and quickly i found out that my code is a mess. It's been a while since I've been programming in PHP, and since then I learned OOP. Now while making an application in C# or java is pretty easy from this point of view, PHP…
Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57
4
votes
4 answers

Java - Getter/Setter, behavior and Interfaces

I have a question, a little bit theoretical: Assume, I have the following classes : interface ReportInterface { void execute(); } class Report implements ReportInterface { private final Repository rep; Report(Repository ref){ …
Dr1231
  • 43
  • 3
4
votes
2 answers

Why use bin/www and not index.js?

The express-generator tool creates a file called bin/www and uses it as the application's main entry-point. I believe I've seen a couple of other modules do this as well, but the vast majority simply use index.js. What is the rationale behind this?…
4
votes
1 answer

Google CodeStyle for Eclipse formatter shows version warning

Style xml is taken from: https://code.google.com/p/google-styleguide/source/browse/trunk/eclipse-java-google-style.xml In Eclipse Luna (Version 4.4.1) go to: Window Preferences Java CodeStyle Formatter Import the eclipse-java-google-style.xml But…
heaphach
  • 1,492
  • 1
  • 20
  • 44
4
votes
1 answer

Javascript: test regex and assign to variable if it matches in one line

To test if a regex matches and assign it to a variable if it does, or assign it to some default value if it doesn't, I am currently doing the following: var test = someString.match(/some_regex/gi); var result = (test) ? test[0] : 'default_value'; I…
YemSalat
  • 19,986
  • 13
  • 44
  • 51
4
votes
1 answer

Looking for instructions on how to structure a single page application

We are a team of developers that have been doing web application programming for a few years. We are now starting over with a new project and we are aiming at making it a single page application. For the front end we are using angular. We are…
Ludwig Magnusson
  • 13,964
  • 10
  • 38
  • 53
3
votes
5 answers

MVC Putting an action in the most appropriate correct controller

I was just wondering what the best practice approach is for deciding where to create an action/view in certain situations. If User hasMany Video where is the best place to create the action/view to show user videos? So within the Users account page…
Leo
  • 1,521
  • 12
  • 18
3
votes
1 answer

How to structure APIs when using Retrofit

I am using Retrofit in an Android project, and wanted to know how people structure their APIs in Retrofit. So I have some APIs which have same base URL, now do I place all of them in a single interface? Or I place them depending on use case? Like…
3
votes
1 answer

Git and shared python library

This might be a novice question, so please excuse. We have a small python development team and our repo is organized as indicated below. We have a custom library that is shared across multiple scripts (wrappers) and then libraries specific to each…
3
votes
2 answers

What are the advantages of function calls without mixed variables?

I know PHP is a very error tolerant language and I guess that is why you can have mixed variables for function calls like: /** * @param mixed $bar **/ function foo($bar) { // Do something with $bar, but check it's type! } Is there a…
Jurik
  • 3,244
  • 1
  • 31
  • 52
3
votes
2 answers

How to parse actual code like stackoverflow/intellisense/etc?

I was wondering how stackoverflow parses all sorts of different code and identifies keywords, special characters, whitespace formatting, etc. It does this for most code I believe, and I've noticed it's even sophisticated enough to understand the…
stupidkid
  • 410
  • 1
  • 6
  • 17
3
votes
2 answers

PHPMD says violating Single Responsibility Principle for argument having boolean default value

These two PHP class methods violates Single Responsibility Principle (SRP) according to the phpmd rule booleanargumentflag. How should they be written to avoid this? If the solution is to remove the default value "= true", then how is this improving…
Mikael Roos
  • 285
  • 3
  • 15
3
votes
6 answers

Good practice to explicitly declare variables without 'much' use in favor of readability?

So, this is yet another 'good' programming practice question. I did search around a bit, but something like this is often hard to define in just a few words. To the question: from a professional perspective, is it better programming practice to…
sherrellbc
  • 4,650
  • 9
  • 48
  • 77
3
votes
4 answers

c# Strategy Pattern per user

I have a very simple scenario. My site's user can be either a monthly membership or an annual membership public class User { public string UserName { get; set; } public MembershipType MembershipType { get; set; } } public enum…
Crudler
  • 2,194
  • 3
  • 30
  • 57
3
votes
1 answer

Ruby syntax, nested modules or classes

I am new to Ruby but have been looking through some source code. I came across the kind of structures shown below in some source code (names of modules, classes not the real ones) module ModuleOne class MyClass module CommonModule # code…
Davet
  • 334
  • 1
  • 3
  • 15
1 2
3
13 14