Questions tagged [programming-logic]
According to Wikipedia, Logic (from the Ancient Greek: λογική, logike)[1] has two meanings: first, it describes the use of valid reasoning in some activity; second, it names the normative study of reasoning or a branch thereof.[2][3] In the latter sense, it features most prominently in the subjects of philosophy, mathematics, and computer science.
60 questions
66
votes
16
answers
16k
views
How to avoid logical mistakes in code, when TDD didn't help?
I was recently writing a small piece of code which would indicate in a human-friendly way how old an event is. For instance, it could indicate that the event happened “Three weeks ago” or “A month ago”...
56
votes
11
answers
155k
views
How would you refactor nested IF Statements? [duplicate]
I was cruising around the programming blogosphere when I happened upon this post about GOTO's:
http://giuliozambon.blogspot.com/2010/12/programmers-tabu.html
Here the writer talks about how "one ...
54
votes
6
answers
14k
views
Business logic: Database vs code [duplicate]
I'm a student of systems engineering, and all my teachers and friends (that actually work in the area) say that it is better to have as much logic as possible implemented in the database (queries, ...
41
votes
15
answers
51k
views
Arguments for or against using Try/Catch as logical operators [closed]
I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators.
Meaning, "do some code, if that throws this error, do this code, but if that throws this error ...
36
votes
14
answers
9k
views
How to define "or" logically
Recently, I came across a problem that required me to define the logical "OR" operator programmatically, but without using the operator itself.
What I came up with is this:
OR(arg1, arg2)
if arg1 = ...
28
votes
7
answers
22k
views
What do you do to improve your logical programming skills? [duplicate]
Do you think that only the programming pratice will help you to improve your logical programming skill or do you train your brain with puzzle games, trying imagine how universe works, playing ...
21
votes
9
answers
9k
views
How to turn truth table into smallest possible if / else block
How can I take a truth table and turn it into a compacted if block?
For instance, let's say I have this truth table where A and B are conditions and x, y and z are possible actions:
A B | x y z
-----...
15
votes
5
answers
27k
views
When is it appropriate to use a bitwise operator in a conditional expression?
First, some background:
I am an IT teacher-in-training and I'm trying to introduce the boolean operators of java to my 10th grade class. My teacher-mentor looked over a worksheet I prepared and ...
12
votes
3
answers
3k
views
What is the best practice around De Morgan's Law [closed]
We all know De Morgan's Laws
!(a && b) === (!a || !b)
!(a || b) === (!a && !b)
Is there a community consensus around which one of these representations is easier to reason about (and ...
11
votes
2
answers
17k
views
Handling subscriptions, balances and pricing plan changes [closed]
Preamble
My aim is to create reusable code for multiple projects (and also publish it on github) to manage subscriptions. I know about stripe and recurring billing providers, but that's not what this ...
10
votes
7
answers
4k
views
Programming knowledge vs. programming logic
Is there any difference between the two topics? I have seen companies asking for Good Programming knowledge some Good Programming logic.
I have seen this in Job profiles for a developer – for e.g. "...
8
votes
3
answers
10k
views
Ordering if conditions for efficiency and clean code [closed]
This is purely a design question and the example is simple to illustrate what I am asking and there are too many permutations of more complex code to provide examples that would cover the topic. I am ...
7
votes
1
answer
788
views
Is the separation of program logic and presentation layer going too far?
In a Drupal programming guide, I noticed this sentence:
The theme hook receives the total number of votes and the number of votes for just that item, but the template wants to display a percentage. ...
6
votes
2
answers
2k
views
What is the logic in the order of operator precedence? [closed]
Absolutely academic context question-
I found countless articles listing the order of operator precedence in all languages, but what is the logical reasoning behind that specific order?
For clarity ...
5
votes
8
answers
3k
views
How do you decide between putting the code in the database or putting the code in the application? [closed]
For the sake of argument:
Let's assume the application we are building is an amortization schedule.
Let's also assume that the database has a table called tblAmortizationPayments that stores the ...