Programming Practices are the commonly or not so commonly used practices in development of software. These can include things like Agile Development, Kanban, Coding shortcuts, etc.

learn more… | top users | synonyms

2
votes
4answers
65 views

Keeping a ratio column that's the division between two other columns

I'm about to build a SQL table where I want to store currency orders. That means that I need to store how much I paid for a certain quantity, and the ratio between both quantities. So for example: ...
1
vote
1answer
44 views

Service/component based application in Java

I have a Java project whose architecture is quite component-oriented, and I am wondering if this is a common way to organize code which rules/patterns are used, if there is a name for this coding ...
2
votes
4answers
134 views

Cleanup & Arrange practices during unit testing to avoid dirty databases

I'm coding UnitTest in C# and I settled with this structure: try { // ========== // ARRANGE // ========== // Insert into the database all test data I'll need during the test // ...
0
votes
1answer
96 views

JavaScript & AngularJs Modules Implementation technique and structure

So Im building an app and I'm trying to implement the structure of the app so that its robust and scalable in future. My app is mostly divided into JavaScript Modules (revealing pattern): // ...
41
votes
8answers
4k views

When is it appropriate to make a separate function when there will only ever be a single call to said function? [duplicate]

We are designing coding standards, and are having disagreements as to if it is ever appropriate to break code out into separate functions within a class, when those functions will only ever be called ...
4
votes
4answers
171 views

Best practice for getting last record inserted in DB

Me and a couple of colleagues are having a discussion regarding the following case: In an OrderStatus table we're keeping track of all the statuses an order goes through in time, including ...
1
vote
0answers
65 views

Function to return a string - Which is cleaner? [migrated]

I was having a discussion with my coworker about a function that returns either an empty string, or a string of a css class. The function is passed an object which has an HTTP status code, and then ...
53
votes
8answers
6k views

How can we be certain that the lower components of computer programming like compilers, assemblers, machine instructions, etc. are flawless?

Since we are becoming more and more reliant on computing, including very critical tasks of day-to-day life, I was just wondering how those vital components are tested. More technically, how are the ...
2
votes
0answers
31 views

Should my application call statsd directly or should I call statsd based off logs?

I'm planning on incrementing counters in statsd based of various events within my application. I have logging in place for these events. So, from my viewpoint I have two options: Update the ...
1
vote
3answers
137 views

When a class represents a property that might be invalid, how should the validation be done?

I have a Product class which has among others an attribute Ean13 that encapsulates an EAN13 code. Here is a prototype of the Product class: @Entity @Table(name = "tb_produtos") public class Product ...
57
votes
8answers
5k views

If I need to use a piece of memory throughout the lifespan of my program, is it really necessary to free it right before program termination?

In many books and tutorials, I've heard the practice of memory management stressed and felt that some mysterious and terrible things would happen if I didn't free memory after I'm done using it. I ...
10
votes
3answers
440 views

Is it bad to refer to access array elements via pointer arithmetic instead of the [] operator?

I've just started learning to program in C, and to improve my understanding of pointers and arrays, I tried to refer to the elements of an array without creating any pointer at all: for(k1 = 0; k1 ...
4
votes
1answer
48 views

Signature-changing decorator: properly documenting additional argument

Let's say I have a custom decorator, and I want it to properly handle docstring of decorated function. Problem is: my decorator adds an argument. from functools import wraps def ...
6
votes
1answer
105 views

Is there a standardized practice for ordering attributes in HTML tags?

Thanks for looking. I am working on an AngularJS project and the attributes are numerous in many of my HTML elements: <button type="submit" ng-click="Page.UI.DetailView.ExecuteFunction()" ...
2
votes
1answer
184 views

How to implement a facade correctly

I have read multiple websites on this topic but none of them gave me a 'good' solution for the problem I am having. The problem is described in the following (related) questions: How do I couple the ...
3
votes
3answers
59 views

Handling Value Unit data

We have some data that is strongly bound to each other and we are using it for calculations. Its a value with a unit type and an optional relation. E.g. 1500 meter above sea level. The unit type ...
5
votes
6answers
538 views

Is it an overkill to write unit tests for a small code base? [duplicate]

I am the sole maintainer of a code base of about 2000 lines of code. It's not big, but over time the code became so unmaintainable my boss agreed to give me time to rewrite it from scratch. Since the ...
1
vote
1answer
99 views

Extensible way to create bash program

I have a bash script that should be extensible with additional functions with as little change to the script as possible. The basic function is as follows. It loops through a list of files to check. ...
42
votes
6answers
9k views

Is it better to check `c >= '0'` or `c >= 48`?

After a discussion with some my colleagues, I've a 'philosophical' question about how treat the char data type in Java, following the best practices. Suppose a simple scenario (obviously this is only ...
1
vote
1answer
102 views

What does `Resolving` mean in programing? [closed]

I see many places where the word Resolve is used, in Dependency Injection (resolve an implementation to an interface), Package Manager (ex: Resolve packages dependencies), Web (ex: Resolve a ...
-3
votes
1answer
77 views

Manage lock of a software feature [closed]

I've wrote a standalone java SE software which executes, for example, the features A, B and C. Now, i want to that, if a lock is enabled (and this lock is a command sent remotely by my backend), the ...
3
votes
2answers
185 views

Should I use my own public API for my web interface?

I am designing an API with django and its rest framework (and I am already not sure if it worth the hassle to version it or not). I totally know the iOS and Android apps will call the API, get a ...
2
votes
3answers
140 views

Is it considered a bad coding practice to write methods/properties that support (only) testing? [duplicate]

When I write (unit) tests I always try to avoid for example microsoft fakes because then the edit&continue feature no longer works. However this often requires refactoring... and sometimes methods ...
1
vote
2answers
92 views

Unit Testing: Structured vs Unstructured Programming [closed]

Is it possible to write effective unit tests for unstructured code? I was reading through the various answers to this question. It explains the implications of unit testing procedural and OOP code, ...
1
vote
1answer
94 views

Reducing the arity of functions [closed]

I have discovered that reducing the arity of functions in my code to zero or one improves their non-functional characteristics significantly, such as testability, maintainability and their ...
1
vote
3answers
263 views

Use of electronics in programming [closed]

Does a programmer need to have a deep understanding of digital electronics. Theoretical v/s practical. As what they teach us at college is pretty basic? If yes, then do all kinds of programmers ...
0
votes
0answers
46 views

Is marking members as static against object-orientated programming? [duplicate]

Me and my co-workers are having a bit of a discussion about one of the code analysis issues thrown by visual studio: CA1822 Mark members as static The 'this' parameter (or 'Me' in Visual Basic) of ...
0
votes
0answers
42 views

If I set a default value in my table do I need to indicate it when calling the insert function in my system?

For example, I have this (see below) table. The default value for status field is disconnected. Then in my code I have a function like this MySQL_Query = "INSERT INTO `teller_info` " _ ...
9
votes
6answers
1k views

Does context (like as an argument in a function) allow for numbers in code that aren't magic numbers? [duplicate]

I've been reading many of the articles and such about magic numbers, i.e. wikipedia article programmers.stackexchange.com article It seemed like no one has considered context as a means of making ...
1
vote
2answers
173 views

Do nested conditionals have a significant performance impact? [duplicate]

This is a question that lives in my mind from a long time. Does the use of multiple nested conditional statements impact the performance of a taken code? So far I know that programmers have created a ...
1
vote
2answers
81 views

Throwing exceptions in application configuration providers

Simple question: What is the best/common practice regarding to throwing errors for application configuration providers? Given is a simple key/value-based configuration source: class Configuration ...
1
vote
4answers
341 views

What's the alternative to DRY code when it requires too many parameters?

What is the best strategy for maintaining easy to follow code when keeping things DRY means you have to pass a lot of parameters to shared functions? In my specific case, I have a grails based app, ...
157
votes
14answers
27k views

Why are the sizes of programs so large?

If we look at the vintage program Netscape Navigator or an early version of Microsoft Word, those programs were less than 50 MB in size. Now when I install google chrome it is 200 MB and desktop ...
2
votes
3answers
79 views

Best practise for databinding when a non-data object is included with the data

I'm using .NET with Windows Forms, but I believe there may be similar concerns with other toolkits. Suppose we have a list of objects of a certain type. Using an example to make the following easier ...
1
vote
7answers
269 views

Throwing an exception when a method does not complete or implement a work around? [duplicate]

I have been studying this subject quite a bit, and I am unsure of what's the best way. I still have a lot to go trough (books, blogs, stack exchange, etc), but I simply can't find a consensus. ...
0
votes
3answers
185 views

In the spirit of consistency, is it acceptable to comment everything equally? [closed]

Consistency is something I value (at an OCD perfectionist level to be honest). I can live with not writing any comments and focus on producing good, refactored, readable code -- or, if I must comment, ...
0
votes
1answer
74 views

Should the main functions of a program be in a separate object? [duplicate]

For a class project in Introduction to Object Orientated Programming, we are creating a simple game. This game has two main menus. I was just wondering what the best practice for organizing these ...
16
votes
7answers
1k views

Writing comments for some small code with rather large background [duplicate]

So I had to write some code related to splitting Bezier curves into parts. I read through several references and particularly referred this rather detailed one. The final code outcome is however ...
0
votes
1answer
107 views

Should DTO have validators?

I believe that DTO should be as dummy and easy as possible. However, after hint made by my friend, opportunity to validate data that is set in DTO sounds tempting. Let's have following example: ...
6
votes
3answers
1k views

Is it good to define a variable inside a loop? [closed]

My instructor once told me that I should not define a variable inside a loop, but I honestly still do not understand why. What are the disadvantages of that? Could any body explain that to me?
0
votes
2answers
292 views

How to structure a SaaS application?

The Problem I need to develop a Software-as-a-Service application, that will be used from our clients. The application contains a lot of forms (Company Application) using a step-by-step forms. They ...
2
votes
1answer
167 views

How do you troubleshoot an issue that you simply can't duplicate? [closed]

I have a client that keeps reporting a certain issue that users are experiencing with a public-facing site written in MVC and hosted on Azure. It seems to happen at random, but for the life of me, ...
1
vote
1answer
111 views

When to use absolute path? [closed]

I had given an answer on SO, the question was concerning a problem with a relative path. My answer was to use an absolute path, which I thought seemed simpler. The asker claimed to need a relative ...
6
votes
3answers
519 views

Is using hashes for primary keys a good idea?

The Austrian electronic ID card relies on the so-called sector identifiers. For example a hospital gets to identify a person by getting a sectorId for that person, which is computed roughly as ...
4
votes
1answer
107 views

Makefile for library project to be able to compile the unit tests and the demo program using make

I am new to makefiles and I am developing a (non-executable) library in C++. Additionally to the library I have (executable) unit tests and an (executable) demo program. I would now like to be able ...
1
vote
1answer
82 views

Should I use autoloaders in modules?

Lets say I'm running a PHP app like Magento, PrestaShop. Now these system have their own complex autoloaders to load controllers based on routes, required classes, models, etc. Most of the time as a ...
2
votes
2answers
193 views

Adding centralized logging mechanism to Project (Best Practice)

I want to add a logging mechanism to my project but I am afraid to have logging code spread all over the place. I thus had the idea of having only one class Logger responsible for writing relevant ...
0
votes
0answers
75 views

Why are scriptlets considered bad practice in JSPs when much more popular languages such as PHP seem not have any problem with them? [duplicate]

Why is doing <% if(blahblah) { //do something } %> in a JSP considered to be bad practice when noone who writes PHP seems to have any problem with doing essentially the ...
1
vote
4answers
358 views

Should I Include PHP code in HTML or HTML in PHP?

What is the best practice, to write my PHP code inside my HTML code or HTML inside PHP? PHP inside HMTL: <p class="lead">Welcome to the <?= COMPANY_NAME ?> website.</p> HTML ...
1
vote
1answer
91 views

Git Question: What to do when multiple people working on a project?

I made a project and put it on github, it's basically a small powershell function that is pretty useful in some situations. I've since made some improvements to it to add functionality...but someone ...