• Breaking News

    Sunday, March 22, 2020

    Coding practices/ patterns for better code quality Ask Programming

    Coding practices/ patterns for better code quality Ask Programming


    Coding practices/ patterns for better code quality

    Posted: 22 Mar 2020 08:43 AM PDT

    Hi Everyone, I have 2 years of experience but I have realised that I don't follow good coding/ programming practices, So I am trying to start from basics and learn all good practices/ patterns, I our organisation many people don't follow even the simple things like SOLID principles, naming conventions etc , But i want to learn those things , So can someone list down resources like Books, Articles, Topics, Thanks.

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

    Forming a Small Group to Learn C Together

    Posted: 22 Mar 2020 06:37 PM PDT

    Hello Redditors,

    I am Casey, a 27 year old male interested in learning about computers and programming. I have already read my way through Code: The Hidden Language of Computer Hardware and Software and I am now trying to learn programming.

    My goal is to form a group of six people to learn with that can dedicate an average of 1 hour per day to study C (the ANSI version). I understand some days people will be to busy, and by no means will this be enforce in any harsh fashion. I believe forming a group will help me stay motivated to learn and be of value if I face any problems that feel like a wall. If you could benefit from the same, please consider joining me in this small group study.

    My plan is to go through the book: The C Programming Language Second Edition for ANSI C. The book is 8 chapters long and those chapters consist of 189 pages. I picked it because it's highly recommended, relatively short and was in part written by one of the creators of C. It looks to be about 20 dollars on Amazon to buy used (at the time of writing this).

    Communication will mostly be held through the text chat system of discord. There is a section for each chapter and people can post their solutions/problems for each chapter. There are also general chat rooms if people want to get to know each other. The server also includes 1 on 1 voice chat rooms for helping each other out as needed. While I would prefer the use of the text chat rooms so we can all look at and benefit from them, I also understand just talking it out over chat is simpler.

    I will be using the gcc command to compile on Fedora (linux), but you are welcome to compile however you like. If you need help learning to compile, I can help you. The book will not cover that. There are many online guides too.

    Send me a message through Reddit introducing yourself and why you want to learn C to join. I will send you the discord link.

    Should I get more than 6 people who want to join, I will mention this group is full in an edit at the top.

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

    resources/books on unit testing/mock testing and TDD ?

    Posted: 22 Mar 2020 10:00 PM PDT

    Hello , i am a self taught programmer working for a startup (java,spring boot) . However with no formal training I never learned about unit tests/ mock testing....I have seen quite a few tutorials on them but these are quite simplistic and rudimentary.

    I would like to find more resources on complicated unit tests like those used in enterprise development and mock tesing with real world examples.

    Any resources will be handy . Books specifically on unit/mock tests/TDD will also be quite helpful

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

    How are algorithms written before being put into code, and how do you define what the algorithm is within the code itself?

    Posted: 22 Mar 2020 05:49 PM PDT

    Ok, weird question, but look at it like this..
    I am rather average when it comes to mathematics, i understand the basics and get how formulas work, and i know how to implement this kind of thing into code itself.

    however, i don't think i have actually written an algorithm.

    I have done a few small courses on how to use different kinds of mathematical equations, physics equations etc within programming, but yeah, i guess i've never written my own algorithm and i think it would be nice to start trying it lol.

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

    Given a set of points on a plane, how do I find the points that are within of a given distance?

    Posted: 22 Mar 2020 08:51 PM PDT

    I'm asked to list all the points that are within the given distance for each of the points, and it has to be programmed in C++.

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

    Windows API - How do I get the state of SetThreadExecutionState without setting anything?

    Posted: 22 Mar 2020 06:08 PM PDT

    Regarding the Windows API (Win 10, if it matters), I see that for the SetThreadExecutionState function, the return value is the previous thread execution state.

    However, how do I get the current state without changing it?

     

    Edit: To clarify, if this is not global in nature, then I want to know if any application has set this (i.e. requested suspension of the screensaver).

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

    Computer Algebra System (symbolic algebra)/Yacas

    Posted: 22 Mar 2020 05:41 PM PDT

    Hey guys!

    I am very new to R and programming in general, so I ask your pardon for my disturbance.

    I was just seeking to do a very simple thing in R and that is to create variables,solve somewhat simple equations using these variables and other objects and after create a data table with all with these result. Searching for a symbolic algebra package, I first installed a package called SymPy and did something similar to this:

    A <- 10 B <- 35 C <- Var("C")

    But after this I was unable to solve a equation like "A=B+C" for C, so I sought for this other package called Yacas, which featured the Solve function, which apparently could solve problems of these types, so I typed the function and got...

    solve(B+C-A, C) Error in solve.Sym(B + C - A, C) : missing(b) is not TRUE

    I know I am fairly new to programming and R and probably should be learning the basics, but I kinda need to learn how to do these basic symbolic algebra now, so could anyone help me?

    Also, for the number of variables I am planning to create and use in my data sets I've found very tiresome to type "n <- Var("n")". Are there faster, more efficient and better ways to do it? Am I on the wrong programming language? Thanks in advance and I wish you a great night!

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

    Help with my programming path

    Posted: 22 Mar 2020 05:05 PM PDT

    So, I have been programming for like 10 years or something, somewhat on and off, so I am far from a newb but I am also far from the skill level of most programmers with 10 years of experience. That being said, I want to start a project. Something I can dedicate a lot of time into, but I have a problem. I cannot decide what I want to do because I have too many interests in too many different areas.

    On the one hand, I want to do something in the field of game development, make my own little game etc etc, I have done it before and LOVE the feeling of making games. However on the other hand, I want to do something like reverse engineering/hacking etc etc, because I have always loved breaking things apart and seeing how they run on the inside. But also, on a hypothetical third hand, I love the field of artificial intelligence and would love to do something in that field, too, because it is relatively so new and such an exciting field right to be in right now.

    You may be thinking 'well why don't you just somehow merge the three and get the best of all the worlds?', I have thought long and hard about this and is just something that I don't think I would be able to do, or maybe my creativity simply will not allow that.

    My mind runs in very vicious circles. I will start programming something, let's say a game, and then a couple of hours in I will see something on Twitter about someone finding a new jailbreak for iOS and then all I want to do is that, and I will be completely turned off from making that game that I had so lovingly started mere hours ago.

    Please, help. I wonder if anyone else has had this strange and very annoying phenomenon happen to them, and if you have, how did you get over it?

    Thanks.

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

    What is something you wish you'd known before starting to collaborate with other developers on a project?

    Posted: 22 Mar 2020 01:04 PM PDT

    It's going to be my first time working with another developer on a project! I've heard git merges are a pain...

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

    How to use BFS to check if a graph is 3 colorable?

    Posted: 22 Mar 2020 08:21 AM PDT

    My attempt:

    Since BFS will output BFS_TREE and a tree is bipartite, therefore it'll be 2 colorable( 1 color for odd levels and 1 color for even levels). The slant edges in BFS_TREE will not create a problem, since it's b/w two levels and adjacent levels have different color anyway. Cross edges will force more colors. Further, I shouldn't have something of the type( A-B cross edge, B_C cross edge and A-C cross edge, essentially a C4) because that will make the graph 4 colorable. But then I realized, you don't necessarily need a C4 for 4 colorability. Furthermore, if there are cross edges in a level, then for the next level I cannot follow the initial coloring scheme(1 color for odd levels and 1 color for even levels) and therefore, slant edges become relevant again.

    Now, i'm lost. Don't know what to do.

    submitted by /u/t_h-e-other-one
    [link] [comments]

    I am trying to clone my own github repository and pass all of its contents to another repository. How to properly do that

    Posted: 22 Mar 2020 11:35 AM PDT

    I have a github repository with a project I have been working on for a while now, full with silly commits that I don't want anybody else to see. I am now going to give access to the code to someone else, and thought I could clone my own repository and then push everything to a new repository in which one cannot see the all of the commits, but only the files as they are now.

    I have cloned the repo with git clone and have them in a folder in my machie, OK

    I initialized a new repo with ''git init''

    Then followed as is on github

    I have created another repo and tried to follow github guidelines

    …or push an existing repository from the command line

    git remote add origin https://github.com/username/new-repo-name.git

    git push -u origin master

    I followed the guidelines like this:

    git remote add origin https://github.com/username/new-repo-name.git git push -u origin master GOT: error: src refspec master does not match any. error: failed to push some refs to THEN TRIED: git push -u https://github.com/username/new-repo-name.git master GOT: same error as above THEN TRIED: git add . GOT: warning: adding embedded git repository: easy-site- hint: You've added another git repository inside your current repository. hint: Clones of the outer repository will not contain the contents of hint: the embedded repository and will not know how to obtain it. 

    What am I doing wrong? Can I fix this following what I have been doing or should I take a whole different approach to create a new repo and hide my commits?

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

    Problem with this auto gmail messages sender /w JavaScript

    Posted: 22 Mar 2020 02:22 PM PDT

    I will gift a reddit Gold-award to the first one to help me fix it, but make sure that no one has already solved it because I posted it in both javascript and askprogramming

    Here is a part of my code which sends some emails through gmail :

    for(i=0;i<l;i++){//click the new mailvar down = new MouseEvent('mousedown');var up = new MouseEvent('mouseup');var elem = document.getElementsByClassName("T-I-KE")[0];elem.dispatchEvent(down);elem.dispatchEvent(up);

    //get idvar toId = document.getElementsByClassName('vO')[0].id;//todocument.getElementById(toId).value = mail[i];// Subjectvar z = document.getElementsByClassName('aoT')[0];z.value = title;// Messagevar m = document.getElementsByClassName('Am Al editable LW-avf tS-tW')[0];m.innerHTML = body;

    //sendvar c = document.getElementsByClassName('T-I J-J5-Ji aoO v7 T-I-atl L3')[0];c.click();}

    The problem occurs here:

    elem.dispatchEvent(down);elem.dispatchEvent(up);

    //get idvar toId = document.getElementsByClassName('vO')[0].id;

    When I execute the mouse down and mouse up, it takes about two seconds for the pop up window to open, and a couple more seconds for it to generate it's unique id. So it returns an error. I thought about many solutions to this error including async/await, functions, timeouts, and spent a lot of hours trying to figure it out. But for some reason there is always one problem which ruins the code.

    Problems that you may think would work but wouldn't:

    • Creating a pause after the down&up, this won't work as the pause executes before the window opens.
    • placing the rest of the code (after the down and up) in a function with a timeout, this will not work as the whole code is inside a for loop. Therefore the program will keep running the down&up code many times before the getId will even run once.

    I know that it looks basic but for some reason I keep running into stupid errors, would love to get your support.

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

    It is flutter worth?

    Posted: 22 Mar 2020 02:15 PM PDT

    Hi im new and i am at the starting point of learning a programming language. It is flutter (dart language) a worth study, or i should avoid it and start study another (what)? I will mostly do Apps and Games (unity)

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

    Help understanding Single Responsibility Principle

    Posted: 22 Mar 2020 01:45 PM PDT

    I want to create a plugin for the GIS software my team of analysts are using. I would like there to be a button that the analyst can click that will load all required vector files for a project into the viewer. So the button would need to do the following:

    1. Check which vector files are currently loaded

    2. Determine what vector files NEED to be loaded (based on a database)

    3. Set some visualization settings for the new vectors

    4. Load the vectors into the viewer

    Now, I would normally write a function that would look like something like this in Python:

    def load_vectors_to_viewer(project): # A first sub-function would retrieve all existing vectors current_vectors = find_current_vectors(project) # A second sub-function would look into a database and figure out # which ones need to be added new_vectors = find_new_vectors(project, current_vectors) # A third sub-function would figure out how to visualize them visual_settings = find_visual_settings(project, new_vectors) # A final function would actually then load everything load_vectors(project, new_vectors, visual_settings) 

    I guess I just don't entirely understand how to make this follow the Single Responsibility Principle. This function would clearly be hard to test. But any user-facing tool like this would necessarily need to perform a lot of distinct tasks.

    Thanks!

    submitted by /u/po-laris
    [link] [comments]

    Error attempting to access database and pull from table. (Java w/SQLite)

    Posted: 22 Mar 2020 12:34 PM PDT

    Hi, so I have an sqlite database file which holds two tables: (Albums and Artists). Now, I have a method which is meant to return a list of Strings from after getting the data from the "Artists" table. But, when calling the method I am getting an error: "org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (no such table: Artists)". The table does exist so, I'm not sure the issue entirely.

    Could it be that the database file is not being connected to properly?

    The db file is contained within the projects folder so, would the dbUrl provided be appropriate?

    Before I was having an issue with a driver which said: no suitable driver found when attempting to have it automatically get the driver through the dbUrl so, I added the jdbc jar file to the libraries in my project and that seems to of fixed that issue.

    Code: https://www.codepile.net/pile/zMx3GXDB

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

    How can I run a computationally intense simulation in Python (via Jupyter notebooks) without crashing the program?

    Posted: 22 Mar 2020 08:10 AM PDT

    Basically I'm trying to run a relatively simple simulation in Python (via Jupyter notebooks) that is literally just a list (albeit with billions of items) that randomly picks an item in the list, changes it, and repeats a few hundred times.

    The program works 100% fine with smaller lists (up to 10,000 items), but if I go much higher the program will slowly try to execute and then Jupyter notebooks will crash after about two minutes.

    I know that it is definitely possible to run computationally intensive programs this way, as I've created neural networks for image classification using JN in the past. It took several hours to train, but the program never crashed.

    I have two questions:

    - Is there a way to tell Jupyter notebooks that I'm okay with the program taking a long time to execute (I can wait hours if necessary), and it shouldn't preemptively crash or

    - Should I bite the bullet and run a VM on AWS?

    Please help.

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

    Trying to spice up my python code

    Posted: 22 Mar 2020 11:22 AM PDT

    Looking for a new way to implement my python codes

    Currently I use sublime text editor. Recently I have been dabbling with MATLAB and I find their IDE very useful. I like the whole idea of using the command window as a shell in MATLAB, where I can create variables and run MATLAB code on those variable to test functions out etc, then just clc it all away. I want to incorporate this functionality into Sublime; in the least I want something in Sublime that lets me print out a variable in the script I am writing and display its content in the command window.

    Now I know this is 100% possible, I am just having a hard time using the correct syntax in my google searches to find what I am looking for. I recently worked with a flask server through Sublime, and never got around to messing with the environment I code in. I figured I would come here for input before tinkering, any thoughts?

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

    Prime numbers consecutives - Python

    Posted: 22 Mar 2020 10:45 AM PDT

    Hi guys,

    I have some difficulties with a college work. I need to make a program that reads a number and checks if it's a combination of prime numbers.

    Example: 2020 = 17 ^ 2 + 19 ^ 2 + 23 ^ 2 + 29 ^ 2

    The prime numbers should be consecutives. It's my code:

    n = int(input("n: ")) num = 2 cont = 0 for div in range(1, num + 1): if num % div == 0: cont = cont + 1 num = num + 1 if cont == 2: nprimo = True else: nprimo = False p = 0 while p < n and nprimo: n = (num ** 2) + ((num + 1) ** 2) + ((num + 2) ** 2) + ((num + 3) ** 2) 

    I think part that cheks the prime is correct. Does anyone have any ideas?

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

    How to go about creating a browser extension for google chrome

    Posted: 22 Mar 2020 10:07 AM PDT

    For example like Nord VPN offere you secure browsing on the web only but adding the extension to chrome. I'm just curious how something like this can be developed.

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

    Newbie question about Visual Studio WPF .cs and xaml.cs

    Posted: 22 Mar 2020 08:39 AM PDT

    How do I connect the .cs to .xaml.cs in wpf? Some programs adding .cs in wpf and connecting it to .xaml.cs together like flies.exe and I don't know how did they connect it.

    Thank you in advance.

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

    finding second best MST

    Posted: 22 Mar 2020 08:38 AM PDT

    MY ATTEMPT:

    1. Construct MST.
    2. int second_best_cost= infinity;
    3. For all missing edges, find which cycle they belong to, and replace it with the 2nd max edge in that cycle. Calculate cost. Update second_best_cost if it's larger than current cost.
    4. return second_best_cost

    Is there a better way of finding second best MST?

    submitted by /u/t_h-e-other-one
    [link] [comments]

    Finding the longest cycle in a graph.

    Posted: 22 Mar 2020 08:27 AM PDT

    MY ATTEMPT:

    Pseudocode:

    Int max = -infinity;

    Run BFS to get BFS_tree. Put all missing edges into a set S.

    For every edge e(u,v) in set S,

    check if G-e contains a path b/w (u,v).

    If yes, using BFS find spath b/w u and v.

    Length of cycle = spath +1;

    Update max if current cycle length is larger.

    Return max;

    Analysis:

    (Edges) O(m-n+1) x O(m+n) ( using BFS to find spath)

    = O(m^2) = O(n^4)

    Is this a greedy algorithm? It seems incremental design to me.

    Does there exist a greedy algorithm for this problem?

    Can I do it in less than O(n^4) time?

    submitted by /u/t_h-e-other-one
    [link] [comments]

    (Java) Can't remove element from List/ArrayList, always gives NullPointerException or ConcurrentModificationException.

    Posted: 22 Mar 2020 06:31 AM PDT

    I have an ArrayList that has some elements that should be removed, or not even added in the first place, but it always throws on of the two exceptions mentioned in the title.

    So I have the following arraylist:

    List<String> doc = new ArrayList<String>();

    I add elements to it like this (this is all working so far, println prints every single element perfectly):

     BufferedReader reader; reader = new BufferedReader(new StringReader(extractor.getText())); String line = reader.readLine(); while (line != null) { line = reader.readLine(); doc.add(line); } reader.close(); 

    But I have some repeating elements that I want to remove, these all contain ".lap".

    So I try to remove it in a for-each loop:

     for (String s : doc) { if (s.contains(".lap")) { doc.remove(s); } } 

    Which give me a ConcurrentModificationException.

    I looked into it and on StackOverflow they said an Iterator should be used, so I did the following:

     Iterator<String> i = doc.iterator(); while (i.hasNext()) { String s = i.next(); if (s.contains(".lap")) { i.remove(); } } 

    This one throws a NullPointerException.

    So I tried not removing elements, but skipping them all together when reading from the input, so I modified the first block of code like this:

     String line = reader.readLine(); while (line != null) { line = reader.readLine(); if (!line.contains(".lap")) { doc.add(line); } } reader.close(); 

    This one also throws a NullPointerException.

    So how should I remove (or not even add in the first place) some specific lines/elements in an ArrayList? I even looked for an answer on the 2nd Google page and still nothing.

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

    No comments:

    Post a Comment