• Breaking News

    Thursday, December 2, 2021

    What's the fine balance between optimisation and code complexity? Ask Programming

    What's the fine balance between optimisation and code complexity? Ask Programming


    What's the fine balance between optimisation and code complexity?

    Posted: 02 Dec 2021 01:37 AM PST

    We're making big change in our code base to optimise time and server cost but at point one should stop so that code doesn't gets too complex?

    submitted by /u/CaseinSnorter
    [link] [comments]

    Can someone recommend a good write up or tutorial to convert an express app generated using express app generator to use HTTPS ?

    Posted: 02 Dec 2021 03:35 AM PST

    So when we generate a skeleton express app using express app generator it uses http by default. I know to use https we need certificate so i would be using a self signed certificate. But i can't seem to figure out how to modify the skeleton app to use https module instead of the http module. Can anyone please recommend a good tutorial / writeup to accomplish this. Any help would be greatly appreciated.

    submitted by /u/grave_96
    [link] [comments]

    How does one best organize a large program?

    Posted: 02 Dec 2021 04:35 AM PST

    I'm currently (attempting) to write a card game program in C. The issue I'm having is not the logic per se, but rather the organization of the code base. Let me give you a shallow introduction to what I have so far:

    First of, there are several parts that are needed to run the game in-program. You have the Cards library that handles some structure containing cards, you have the Hand library that handles some abstract hand data structure, you also have two player libraries called Player and Dealer, which store a data structure in their respected files for some Player and Dealer hand data.

    So far so good, so what is the issue? Well, it comes down to how each library works independently as well as dependently between each other. For the record, there is no cyclic dependence currently! The issue comes down to the logic of, not how the program works, but how work is distributed across libraries. For Player and Dealer, each will depend on both Hand and Cards. Furthermore, Hand seems to also be dependent on Cards. And lastly, both Player and Dealer are dependent upon each other. This makes the flow of work throughout the program messy.

    That is, each type of data works on itself within its own library, but each library will have to depend upon one another! There are two options I am exploring:

    1.) Making some meta library, let's call it Game, that will store Cards, Hand, Player, and Dealer data structures in a meta_structure as part of some larger library. Instead of passing libraries between each other, each independent library will work on its own data structure without risking mixing workloads between each library. The down side is that the meat library will be doing a disproportionate amount of work and may not be well-structured code.

    2.) Creating nested libraries. That is, each library will refer to each other without risk of cyclic dependence. This is the simpler method because I can just import each library to each other library. However, this will make reading the programs code much trickier as each library will be working on not only their own data structure, but on other data structures not defined within the native library.

    Maybe I'm over thinking this, but I greatly want to avoid writing spaghetti code, or any bad code at all. Best practice for writing for a large project is paramount.

    How would you approach writing for a large project without writing spaghetti/crap code? What is the best practice for writing large code projects? How about ways to break down the logic of a program and partitioning data/procedures according to best practice (whatever that may be/mean!)

    submitted by /u/huskyShad0w
    [link] [comments]

    Can elliptic curves be proven secure?

    Posted: 02 Dec 2021 04:30 AM PST

    My understanding is that there is a formal proof that an elliptic curve with an addition rule is as secure as the orbit of the generator, which can be calculated.

    Googling secp256r1, lots of people seem worried this might have a backdoor.

    If the proof is correct, then no backdoor could exist surely?

    Is it all just politics?

    submitted by /u/XiPingTing
    [link] [comments]

    Software to find duplicate code sections?

    Posted: 02 Dec 2021 04:07 AM PST

    Is there any software (or VS Code extension) that can scan a folder of source code and highlight the sections of files which are duplicated in other files?

    submitted by /u/mishaxz
    [link] [comments]

    C++ Multithreading "Sleeping Barber" Problem Help

    Posted: 02 Dec 2021 04:04 AM PST

    Hello all,

    I'm a little bit inexperienced when it comes to multi threading in C++ and I've tried to solve the following problem : https://en.wikipedia.org/wiki/Sleeping_barber_problem

    I keep running into issues with my threads getting deadlocked, and my barber thread wont even initialize from the beginning. I'm not quite sure what I've done wrong, I was hoping someone here might be able to give any useful tips, solutions, or insights into what I've done wrong. Thanks!

    // Example program #include <iostream> #include <string> #include <mutex> #include <thread> #include <chrono> #include <atomic> #include <deque> #include <vector> #include <condition_variable> using namespace std; const unsigned int NUM_CHAIRS = 2; const unsigned int NUM_CUSTOMERS = 1; // In a barbershop, customers are coming in and there is only one barber. If the barber is cutting a // customers hair, the customer will wait. There are only a limited amount of chairs for the customer // to wait on. If the chairs are full, then the customer will leave and try again later. struct Barbershop { public: Barbershop(): num_waiting(0){}; condition_variable cv; // Acts like a receptionist atomic<int> num_waiting; // Number of customers waiting on chairs mutex cout_mtx; }; class Barber { public: Barber(Barbershop& shop): mem_shop(shop), hislife(&Barber::work, this){}; void work() { unique_lock<mutex> lk(b_mu); if(mem_shop.num_waiting == 0) { mem_shop.cout_mtx.lock(); cout << "Barber sleeping...\n"; mem_shop.cout_mtx.unlock(); } mem_shop.cv.wait(lk, [this]{return mem_shop.num_waiting > 0;}); // []{return mem_shop.num_waiting} mem_shop.cout_mtx.lock(); cout << "Time to cut some hair!\n"; mem_shop.cout_mtx.unlock(); lk.unlock(); mem_shop.cv.notify_one(); this_thread::sleep_for(chrono::milliseconds(100)); mem_shop.num_waiting--; }; ~Barber() { hislife.join(); } int jn; mutex b_mu; Barbershop& mem_shop; thread hislife; }; class Customer { public: Customer(Barbershop& shop, int name_id): mem_shop(shop), name(name_id), hislife(&Customer::tryGetHaircut, this){}; void tryGetHaircut() { if(mem_shop.num_waiting == NUM_CHAIRS) { mem_shop.cout_mtx.lock(); cout << name <<"'s wait was too long. Leaving!\n"; mem_shop.cout_mtx.unlock(); } else { mem_shop.num_waiting++; std::unique_lock<mutex> lk(c_mu); mem_shop.cv.wait(lk); mem_shop.cout_mtx.lock(); cout << name << " is getting haircut!\n"; mem_shop.cout_mtx.unlock(); } }; ~Customer() { hislife.join(); } mutex c_mu; Barbershop& mem_shop; thread hislife; unsigned int name; }; int main() { Barbershop mybarbershop; Barber dan(); vector<Customer*> customers; customers.reserve(NUM_CUSTOMERS-1); for(unsigned int i=0; i<NUM_CUSTOMERS; i++) { customers.push_back(new Customer(mybarbershop, i+1)); } for(auto s : customers) { delete s; } cout << "Program Finished!\n"; return 0; } 
    submitted by /u/Southern-Whereas4875
    [link] [comments]

    Advice needed - how to create reader app for law acts?

    Posted: 02 Dec 2021 03:47 AM PST

    The idea:

    My idea is to create a reader for law acts. The main problem when reading an act for me is that there are infinte number of references to other part of the act and to other acts. That way you need to have many of them opened at the same time. I would like to have links in place, so whenever I click it a small box will open with the part of document that is being referred to.

    I have in mind desktop app or web app, not a mobile app.

    I treat this as personal project and learning opportunity, but also I see chance to convince people in goverment to adopt such solution. When they see how something works well theybalways are easier to convince.

    Where I am:

    I have some basic programming skills and understanding and for my everyday job I work with databases and data visualisation, so my tools at that moment are SQL, CSS, basic Python. I have never created any kind of App before.

    Question:

    I honestly dont know where to start and would appreciate any advice on how to tackle this problem.

    How to approach this problem? What programming languages would fit the best for this project in your opinion?

    Thank you for any advice!

    submitted by /u/Upper_Physics2898
    [link] [comments]

    No comments:

    Post a Comment