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
2
votes
0 answers

WPF chart component: Code structure and MVVM pattern

I'm coding a WPF component which displays a chart looking like a Pareto chart. It's working properly but I feel that it's pretty much crap, here is why: It's using SO MANY containers, for a simple chart there's probably about fifty containers…
nkoniishvt
  • 2,442
  • 1
  • 14
  • 29
2
votes
1 answer

Best practice: Where should re-usable queries be placed?

Short I have re-usable SQLAlchemy queries in a Flask application, but I do not know where it's best to place them. Longer When reading basic tutorials, it becomes very clear how to create basic SQLAlchemy models, such as this one representing a blog…
Ernir
  • 333
  • 1
  • 8
  • 17
2
votes
2 answers

What method should be included in the class

I'm confused what type of methods should be included in the class and what type of methods should be write in a service class? This is my scenario: I'm writing a music store app, and my models designed as below public class Album { private…
James
  • 2,570
  • 7
  • 34
  • 57
2
votes
1 answer

Stop SQL*Plus Complaining About Whitespace

In SQL*Plus, if you execute the following using @: create table someTable ( someID number, somethingElse varchar2(50), somethingRelated number ); ...it will complain with something like: SP2-0734: unknown command…
Xophmeister
  • 8,884
  • 4
  • 44
  • 87
2
votes
2 answers

Getter, Function or just set it on constructor?

I can't find a good performant and legibility way to write some computed inside a class. Imagine the following class and all ways to get the FinalPrice: public class Order { public Order(Product[] products) { Items = products; option 1:…
Bart Calixto
  • 19,210
  • 11
  • 78
  • 114
2
votes
1 answer

Separate files or one file for classes/methods

I am writing a game in Python that has many classes and methods, and I want to know if it is advantageous to store the classes in the main python .py file or store each category of classes in separate files, then import them. This would help with…
Pip
  • 4,387
  • 4
  • 23
  • 31
1
vote
0 answers

Structure Policy for Django / Python Libraries

Question Summary Hi Folks, This is a kind of opinion question, I've built a Django library for my company and I keep swithering and changing my mind on how to structure it. Possible strategies I've come up with are below: Method 1 - Individual…
MajorFailz
  • 83
  • 1
  • 7
1
vote
2 answers

What is wrong in this c# code for simple RestApi?

I received feedback: "code test is not at the expected level there's a lack of understanding of async, HTTP clients, and just software development patterns in general. Poor structure and testing" The simple test and solution are on GitHub…
Sasa Jovanovic
  • 324
  • 2
  • 14
1
vote
0 answers

Visual Studio 2022 - Object browser or Class view for TypeScript?

I'm new to TypeScript and starting development in React/TypeScript in Visual Studio 2022. Is there any tool or extension that could be used to visually browse the structure of TypeScript project or used libraries .d.ts files that would help me to…
1
vote
2 answers

Is there an algorithm, to find values ​of a polynomial with big integers, quickly without loops?

For example, if I want to find 1085912312763120759250776993188102125849391224162 = a^9+b^9+c^9+d the code needs to brings a=3456 b=78525 c=217423 d=215478 I do not need specific values, only that they comply with the fact that a, b and c have 6…
1
vote
1 answer

Creating a timed loop inside Discord Bot script to reload web page (web scraper bot)

I'm currently designing a discord bot that scrapes a web page that is constantly updating for patches related to a PBE server. I have the bot running through Heroku successfully right now. The issue I'm running into is I want to create an…
triplecute
  • 35
  • 9
1
vote
1 answer

Eliminating .then() blocks for a better code structure in JavaScript

For better structure of my script I want to eliminate .then() blocks. I.E. turn callAsyncFunction().then( (result) => { console.log("done"); callAnotherAsyncFunction().then( (result2) => { console.log("also done"); //…
1
vote
2 answers

How do I correctly reference to code in a different project in C#?

In short: I have a console application with a static Dictionaries, which work fine in the project they were written in. How do I reference to this project correctly, so that I can do the same from a different project? I get an error every time I try…
Alex Janse
  • 43
  • 6
1
vote
1 answer

set new value for array's value using destructure

i got two noob questions about destructure an array: 1st question: when destructuring an object, I can define a new value or a new key or both. On array, can I add a new value without add a new key? const obj = {a: undefined, b:2}; const {a = 3, b}…
nishi
  • 512
  • 1
  • 4
  • 19
1
vote
1 answer

Is Javascript LBYL or EAFP?

There are two programming approaches: EAFP (Easier to Ask Forgiveness than Permission) and LBYL (Look Before You Leap). First approach presumes doing something that can cause an exception, then handling this exception and second approach presumes…
Vlad Havriuk
  • 1,291
  • 17
  • 29