Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
2answers
575 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 ...
0
votes
1answer
74 views

Logic circuit simulation: homebrew or third party solution?

Software I'm working on requires simulation of logic circuits, both combination and sequential. Now the simulation doesn't need to be too detailed, in fact it could be detrimental to the function of ...
67
votes
16answers
15k 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”...
0
votes
2answers
144 views

Do i need 2 tables to book entity?

I am developing a website to store books info such (title, book_no, author, edition, container...). I have two types of insert insert series of books (Eg: harry porter series: chapter 1, 2,3...) ...
1
vote
1answer
182 views

Passing 0's (literals) to a constructor

I have a function that creates a new object by passing to it's constructor integer ids primarily with values of 0. This function is called when saving a newly created record (not an edit). public ...
3
votes
2answers
1k views

Understanding LSB and MSB

In reference to one interface control document, I found difficulty in understanding this concept. There is one parameter having LSB of 0.0625 and MSB of 2048 that should be transmitted from one piece ...
2
votes
3answers
363 views

Is there a way to have four possible outcomes without repeating the two conditions? [duplicate]

In a generic sense, my question goes something like this: if (p) { if (q) { a(); } else { b(); } } else { if (q) { c(); } else { d(); } } ...
7
votes
3answers
1k 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 ...
0
votes
3answers
289 views

For which built-in C++ type is the law of excluded middle violated?

Apparently, for some built-in type of C++, the following does not hold: a==b || a!=b Which type/value is it? The question is originally from this video: https://www.youtube.com/watch?v=etZgaSjzqlU&...
1
vote
2answers
2k views

share method logic along classes without inheriting from abstract class

In some languages (e.g. C#) a class can only ever have 1 base class which seems like a problem for what I'm trying to do. I will give you an example of what i'm trying to do, hopefully this will make ...
0
votes
1answer
690 views

How to translate business requirements/logic into code?

I'm new to programming and I'm trying to develop a template of questions I can apply to business rules that will help me extract what's needed to begin coding. Do programmers have a set of ...
-2
votes
3answers
121 views

What's a good way to extract what's needed programatically from business logic? [closed]

I'm new to programming and I've discovered something that causes me confusion and frustration: Translating business logic into actual code. I'm trying to develop a set of questions I can ask myself ...
1
vote
1answer
267 views

Finding the minimum transaction

Given a list of transactions like: A -> 10 to B B -> 10 to C The naive way to settle the transaction would be: C owes 10 to B B owes 10 to A But the same transaction could be settled by: C ...
0
votes
2answers
371 views

Parallel vs Simple Assignment question

I'm quite new to Python and learning it on Lynda.com, which does not seem to have any way to ask questions about lesson content. In a video about while loops there is this code: a, b = 0, 1 while b &...
0
votes
1answer
87 views

Where do we need to include non business logic validations in Service Layer

Currently um working in an application and it has the following hierarchy WEB API2 Controllers (hilds the end points) Business Logic Layer (Dedicated for business logic handling ) Data Access Layer ...
2
votes
1answer
1k views

Sudoku Solver BackTracking vs Simulated Annealing

Before you read any further, assume you know what sudoku game and how to go about solving it. So I have created a sudoku solver with brute-force: The algorithm goes as calculate(through an simple ...
47
votes
6answers
5k 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, ...
1
vote
0answers
631 views

Best way to structure a complicated web-based quiz [closed]

I have a web project that requires I build a quiz and am having some difficulty working out how to efficiently code it. I'd like to create some sort of json template system so that the quizzes can be ...
2
votes
2answers
345 views

Upgrade and downgrade customers subscription

I have been stuck at a requirement for way too long too handle it :(. Our company is having increased number of customers who wants to upgrade or downgrade their subscription. For now, the ...
3
votes
2answers
198 views

Refactoring wordy conditional tests [duplicate]

My first attempt at this question was too theoretical, so I've rewritten it with actual code. See the edit history if you care. Supposing this logic, "suffering" from the arrow anti-pattern: /** * ...
5
votes
1answer
1k views

Good way to program an orchestration / processflow

I'm programming a process in which clients will be separated in 3 different groups, and for every group a different action will be performed. My question concerns the process of deciding which client ...
-4
votes
2answers
654 views

How can I Identify which condition satisfied the if statement? [closed]

Suppose, I am using a if statement as such: if(A || B || C || D) { echo "Hurrah! if is satisfied!"; echo "But! How can I know which was true of the 4 (A,B,C,D)"; } Is there any way I can ...
0
votes
1answer
720 views

Creating algorithms [closed]

I am a relatively new programmer. I can pick up languages and learn syntax at a speed that I consider good, but I can't figure out how to solve problems logically using algorithms very well. I know ...
1
vote
1answer
79 views

Efficient ordering of objects online

I have a list with objects stored in a database. These objects are shown in a list and the user can drag and drop them to order them in a specific way. I want that specific order to be stored. How ...
0
votes
1answer
652 views

How to display an inward spiral matrix

Suppose I have the following matrix with values 1-25 as input to my program. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 The inward spiral should give me the output 13 ...
37
votes
13answers
8k 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 =...
1
vote
2answers
1k views

Given a number X, how do I find from an array of numbers, a unique combination that adds up to X and has the lowest sum of squares?

Given the number 15 and the array [1, 2, 3, 4, 5, 6] Possible combinations (sum=15) would be: [1, 2, 3, 4, 5] [2, 3, 4, 6] [1, 3, 5, 6] [4, 5, 6] Their respective sum of squares would be: 55, 65, 71 ...
1
vote
3answers
449 views

Are functional languages a kind of program derivation?

Program derivation is defined as the derivation of a program from it's specifications. Usually this specification language is some form of propositional logic, but from what I understand, it need not ...
3
votes
1answer
686 views

How to guarantee invariants / Inner logic in setter methods

According to DDD-principles I use factory-methods to create consistent objects and to ensure that the objects are in the right state. Now I'm in doubt about inner logic of setter methods. I'm tied up ...
1
vote
2answers
1k views

Making server logic independent of client interaction

I'm trying to make a realtime multiplayer web-game in node.js with express framework and socket.io library. But I can't seem to make my server-side logic independent of client interactions. I want ...
3
votes
2answers
963 views

Implementing bussiness logic with a large number of business rules and processes

We are currently working on a project that heavily relies on a database. Among many tables the main focus is on table "data" which is linked to another table "data_type" as many-to-one, which is then ...
5
votes
3answers
5k 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 ...
0
votes
1answer
720 views

Is there any reason zero should still equal false in a new programming language? [duplicate]

I understand that 0 is false because math established that a long time ago and C established it in the programming world, as talked about here. However, other than following established conventions, ...
5
votes
4answers
1k views

Finding an object on an infinite line

Question: There is an infinite line. You are standing at a particular point you can either move 1 step forward or 1 step backward. You have to search for an object in that infinite line. Your object ...
10
votes
2answers
13k 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 ...
0
votes
1answer
791 views

Good Data Structure book to improve programming logic for children [closed]

My cousin (Age 10) who studies in Standard 5. He wants to learn programming and programming logic. Which book or resources should I refer? Is there any Good Data Structure book to improve ...
-1
votes
2answers
525 views

Is it reasonable to use Javascript MVC Frameworks for closed source paid web applications? [closed]

I am wondering if it is reasonable to write closed source, paid web apps in Javascript (JS MVC Frameworks like AngularJS, Backbone, Knockout, ...)? I'm concerned because in this type of frameworks you ...
2
votes
2answers
515 views

How to unit test code which is intended to have different results on different platforms

I noticed some duplicate code in a codebase I am working on that appended a filename to a directory path, so I decided to refactor it into its own method. The application I am working on is not well ...
3
votes
1answer
67k views

Flow Chart - While Loops process

I'm having difficulties understanding whether or not this is the right process to use for a flow chart which illustrates the processes involved in an algorithm. For this, assume the following: A 1D ...
3
votes
1answer
367 views

Best Traversing Strategy / Logic Help Needed

Background: Here is the scenario, imagine I have a little Robot. I give this robot a Map, and I want him to traverse the map, after doing so, I want the Robot to tell me the shortest possible path on ...
7
votes
1answer
656 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. ...
-2
votes
3answers
316 views

Should I use AND or should I use OR [closed]

An order can be in the "status" of Completed, Corrected or some other status. I saw some code that is checking it like this, the purpose is to disable some stuff when the status is in Completed or ...
5
votes
3answers
1k views

Is saying “if ( $a != null && $a == 5)” the same as “if ($a == 5)”

First off, sorry if this is answered somewhere else. I did a brief search, but wasn't sure how to ask in search terms. I'm looking at some code and came across lot's of statements like this: if ( ($...
10
votes
7answers
3k 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. "...
0
votes
4answers
8k views

How to improve my loop logic in programming? [closed]

I know how to do simple loops but I don't know what's going on when many loops are working together. For example: for (var i=0; i <= 9; i++){ document.write(i); for (var m=0; m <= 9; m+...
-11
votes
8answers
675 views

Why aren't postfix and primary expressions symmetrical?

Every primary expression is a postfix expression but a postfix expression is not primary expression. But in mathematics, equality seems to be symmetrical. That is: If A is B, then B is A Why isn'...
0
votes
5answers
291 views

ternary or something similar for choosing function?

I posted this question on stackoverflow and it got a poor reception. In reality, the problems I'm facing are minor and any workaround can be considered impractical. However, I believe it might be of ...
5
votes
8answers
2k 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 ...
34
votes
15answers
33k 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 ...
20
votes
7answers
6k 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 -----...