• Breaking News

    Friday, February 21, 2020

    What is 'beautiful code'? learn programming

    What is 'beautiful code'? learn programming


    What is 'beautiful code'?

    Posted: 20 Feb 2020 08:08 AM PST

    Is it compact? Is it about executing a 200-line program with 15 lines of code? Is it understandable? What is it like in your opinion?

    I try to make my code easy to read, but often end up making it "my controlled chaos".

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

    A quick motivation to commit often

    Posted: 20 Feb 2020 08:06 AM PST

    This is my story on how making consistent commits really saved me.

    I built out a developer portfolio about 2-3 months ago, and I thought to myself, "Should I really bother making lots of commits and branching off features? I'm the only one working on this and it's gonna be a pretty short project with very little future maintenance." But, as per the internet's suggestion, I (begrudgingly) did it.

    Of course, during development I ran into bugs, as we all do. After fixing the bug, I'd make a commit. I got the site to a state I was happy with and left it there.

    Two months after (AKA now), I'm working on a different site using (more or less) the same tech stack. And guess what? I ran into a very weird and obscure bug. The internet had little advice on it, because as I found out the issue was related to two technologies clashing with each other. It was also a bug that only showed up in the build version, which made debugging a looooot slower. So, I was in a bit of a pickle.

    Or, I would have been, if I hadn't encountered and solved this exact same bug two months ago on my dev portfolio. Of course, 60 days and thousands of lines of code later I couldn't remember what I did. "Crap", I thought to myself, "I don't remember how I fixed this". But then, a lightbulb went off. A lightbulb going by the name of "git commit -m".

    So, I went to my github repo of the previous project, opened the commits page, and searched it for "strange bug" (I specifically remember labelling the commit something like that because the bug was so odd). I found it, and since I was committing consistently for every feature I made or bug I fixed, the only thing in that commit was that bug fix. This made it super easy to see exactly what I needed to do. I applied it to my current project and, in a very short amount of time and no debugging, the issue was gone.

    So that's how making consistent commits with good messages attached (well, memorable messages anyways) saved me from debugging the same weird, obscure issue twice.

    ASIDE:

    If people want to know what the bug was, it was an issue where having a Framer Motion AnimatePresence component as a direct child of a Gatsby layout component completely breaks the layout, but only on build. It took me a while to figure that one out lol.

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

    Whats a unique/cool data structures that arent part of standard knowledge?

    Posted: 20 Feb 2020 06:07 PM PST

    Im interviewing around and trying to learn all the things. I figured a neat little way to find some practical data structures to learn next would be things that other people have encountered recently.

    For example, I learned about suffix trees recently. Some use cases are max substring searching and word completions.

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

    On the virtues and vexations of commenting code

    Posted: 21 Feb 2020 12:42 AM PST

    I think there's a lot of different opinions when it comes to commenting code. A few of the common adages that I've read are as follows...

    • If you write self-documenting code, you don't need comments
    • You should comment on why your code does something, not how/what it does
    • You should not make "the sky is blue" comments; i.e. don't comment that a loop is iterating over a buffer if that's obvious what it does
    • Comments get crufty; if you have a lot of comments, you have to update them along with the code or they won't really represent what's happening

    Some of these I agree with less more than with others. For example, when it comes to the "self-documenting code" idea, that seems rather lofty, especially if you're a novice. You can try to use the most descriptive function and variables names you can, but some operations just aren't really that obvious to a novice. If you're handing over your code to a senior code reviewer, they may look at you commenting that you're iterating over a buffer and think, "Well duh." On the other hand, if you're a new programmer, and you're documenting for your future self, you might benefit greatly from that little reminder rather than looking at it and thinking, "What the f*** is this for?" People often talk about WTFs-per-minute but a novice programmer is obviously going to have more of those moments than a senior code reviewer.

    I also take issue with the idea of not commenting on what/how your code does something for similar reasons. I think it flies in the face of the idea that "good code should be self documenting", but frankly we're not compilers/interpreters. As a human being, it's a lot easier to read a comment that says something like, "This verifies the integrity of a checksum," than to see a block of routines to read the contents of a file into a buffer, generate a hash on that buffer, and compare that hash to the checksum the file was signed with. It's once again one of those things that comes down to who the comments are for: Your future self, or a senior developer who's reviewing your code? Not to mention, that as a novice programmer, if you're reading the comments for a project, you can learn a lot by comments that say HOW a program works. That leads me to a position where as a novice, I love code that's commented with how it works; but if I were a senior developer that was just trying to review someone's code, I could see how I'd be annoyed by it.

    Which brings me to address the cruftiness of comments... Sometimes as a novice developer, you write a lot of comments so "future you" can easily digest what's happening in the program. But the problem is as "present you" gets better than "past you" at programming, you need these superfluous comments less and less, and you're likely to be improving and modifying the code they pertain to. It then creates an extra maintenance overhead on yourself if you have an abundance of comments because you must update them accordingly with updates to the code, and at a certain point the annoyance of this outweighs their usefulness. It can be kind of useful as a learner to comment on common conventions with, "This is how this works," but as time goes on and those conventions become more familiar and second-nature, they become "the sky is blue" comments and you feel like they're not needed. But then, wait... What if you want your code to be accessible by other novices? Do you want to add the burden of extra maintenance on yourself so that others may learn? That might sound altruistic, but if you're working in a group setting with many contributors, it might behoove you more to have these kind of instructional commentaries for your less experienced cohorts than it would serve you to remove them.

    Anyway, I'm about two old-fashioneds into removing crufty comments from my project and was thinking about all this, and thought it might make for a good discussion. If not, git blame alcohol

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

    Is there any study group for beginners in Inland Empire?

    Posted: 21 Feb 2020 12:26 AM PST

    Looking for getting help or maybe study together for each others.

    I've been taking class from Youtube CS50, it would be nice if you are willing to start I can help as well.

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

    I finally have opportunity to make my dream come true and learn web programing!

    Posted: 21 Feb 2020 12:09 AM PST

    Hello everyone!

    I will try to make it short.

    So i am working as SEO in my company. I have told my boss in past that i have always wanted to learn web programming and today he told me that he wants me to build a company website. He told me that it will be beneficial for both. He will get website and i will start learning web programming. He told me that there is no rush, because they already have website, but it's just old and he wants me to make something new which meets new standards.

    Requirements are not crazy i guess. He needs me to build simple informative website. He is a patent attorney, so i should build website with listed services, company's history, group members (with photos) and a news slide. Integrating Linkedin, google maps and facebook page will be also nice. That's it.

    Guys, i just don't know where to start from and what will be the best way to build a new website.

    Any kind of help from you will be highly appreciated!

    I am really excited to finally start learn web programming and who knows, maybe i will become full time developer in the future!

    Thank you all in advance!

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

    need help [PHP]

    Posted: 20 Feb 2020 09:36 PM PST

    hello guys,

    so i create web-based reservation system and show room plans of the hotel include the information (room number, price, room type, etc)

    here is the code:

     <?php for ($i = 11; $i > 6; $i--){ $ubah = 0; $ubah = $ubah + $i; $nkamar = "A".sprintf("s", $ubah); $sql = mysqli_query($conn,"select * from kamar where nokamar = '$nkamar'"); $data = mysqli_fetch_array($sql); if ($data['kkamar']=="kosong") { echo "<td>"; echo "<input type='hidden' name='nokamar' value='$nkamar'>"; echo $data['nokamar']; echo "</br>"; echo $data['jkamar']; echo "</br>"; echo $data['kkamar']; echo "</br>"; echo number_format($data['hkamar']); echo "</br>"; echo '<button class="btn btn-info" name="reservasi">Reservasi Sekarang!</button>'; echo "</td>"; } else{ echo "<td>"; echo $data['nokamar']; echo "</br>"; echo $data['jkamar']; echo "</br>"; echo $data['kkamar']; echo "</br>"; echo number_format($data['hkamar']); echo "</br>"; } } ?> 

    and here is the results:

    https://i.imgur.com/zZUTfbN.jpg

    when a user clicked a button, the system will get the room number

    question is, how to get room number?

    example: when user click a7 room number, system will get the a7 room number to submit

    thanks

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

    What does this code actually do?

    Posted: 20 Feb 2020 10:45 PM PST

    include<stdio.h>

    int main() { unsigned char a = 1, b = 2; printf("a<<1 = %d \n", a<<1); printf("b<<1 = %d \n", b<<1); return 0; } 
    submitted by /u/ChayanDas19
    [link] [comments]

    How to solve programming optimization problems e.g. Google Hashcode?

    Posted: 20 Feb 2020 01:57 PM PST

    Hi, What resources do you think are useful and what to study to get better at solving optimization problems like google hashcode and codejam? What is your approach? Which materials should one study to solve the problems effectively? Thank you in advance :)

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

    Looking for Specific Tech Blogs (not directly linked with tutorials)

    Posted: 21 Feb 2020 12:59 AM PST

    I was hoping anyone can help me discover tech blogs which generally talk about people's experiences, problems and solutions they came up with. I want to avoid blogs that talk of tutorials or making your life easy with so and so libraries. Most blogs are just flooded with this kind of stuff, mostly web development and libraries. And whenever I search the keyword software development end up on a page talking about webd and how to implement something. I know almost all of the industry is moving towards cloud based SaaS, I am pretty annoyed that because of this I can't find blogs worth looking it. Here are some blog posts, I admire and I am looking for something similar:

    1. https://colah.github.io - I love the complete blog
    2. https://eng.uber.com/managing-data-workflows-at-scale/
    3. http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html
    4. https://www.wired.com/2017/03/russian-hacker-spy-botnet/

    Also any subreddit for discovering such blogs will help too.

    TIA

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

    [Excel] Formula to look for match between range in row and range in column, display first match

    Posted: 21 Feb 2020 12:43 AM PST

    I have a row:

    [formula here] The Quick Brown Fox Jumped Over The Fence

    And a column on another worksheet:

    23436
    Happy
    Quick
    Orange
    Marmalade

    The formula should do the following:

    1. Take the nearest non-empty cell on the right from it (first "The", then "Quick", then "Brown", etc)
    2. Compare taken value to every value inside the column, if no match found - try with next cell from the step 1
    3. If match found - display it as result inside the formula's cell.

    So in the example above it would be:

    1. Formula takes "The"
    2. Compares it to "23436" - no match, "Happy" - no match, <...>, Marmalade - no match.
    3. Formula takes "Quick"
    4. Compares it to "23436" - no match, "Happy" - no match, "Quick" - match found
    5. Display "Quick" inside the formula cell.

    Thanks in advance for all the help!

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

    Does learning bootstrap make it less necessary to internalize much of CSS?

    Posted: 21 Feb 2020 12:22 AM PST

    I've been learning CSS and HTML on freecodecamp, and I'm about to start JavaScript.

    As I created super basic webpages for the projects required at the end of this first section, I was given a link to a "sample" webpage that ours should loosely resemble. I really liked the way the sample page looked and I made a post on this subreddit asking how to go about mimicking the style.

    Several responses I got gave me a "best they could with CSS" sort of response, and several people said " wait until you learn bootstrap, it makes all of this a lot easier to style."

    I'm not gonna lie, so far, CSS seems like my least favorite part about programming. I'm learning it and i know many of the basics already, but I'm just wondering. Will bootstrap or any other coding language or software make CSS less necessary?

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

    Deleting all occurrences of a specific value in a single linked list (java)

    Posted: 20 Feb 2020 05:33 PM PST

    Hi! I have a project for my data structures and algorithms class that I need to finish by tonight, and this algorithm is the last part I need to finish. Basically, what the title says, I need to delete all occurrences of the value 0 in my linked list.

    This is the code I'm using so far:

    private static void eliminateZeroes(Node head) { Node temp = head, prev = null; while (temp != null && temp.data == 0) //if zero is in the front { head = temp.next; // move head to next node temp = head; } while (temp != null) { while (temp != null && temp.data != 0) { prev = temp; temp = temp.next; } // if 0 was not present in linked list if (temp == null) return; // unlink the node from linked list prev.next = temp.next; temp = prev.next; } } This is my Node class: public static class Node { int data; Node next; public Node(int data, Node next) { this.data = data; this.next = next; } } 

    However, my inputs and outputs are not reflecting on how I would trace it.

    when I input a list of 0 --> 0 ---> 0---> 0 ---> null; I expect it to return null but instead, it just returns the zero list, or when my input is a list like 0 ---> 0 ---> 5 ---> 0 ---> null it returns a list like 5 ---> 0 ---> null. Any help would be greatly appreciated, I just don't know what's going wrong and I really need help to fix it.

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

    How would you describe a "solid foundational knowledge" of SQL or python?

    Posted: 20 Feb 2020 05:17 PM PST

    Also, does SQL go well with python? Are they related/complimentary ?

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

    [Python][Fortran] What is a good format to store data from python so it can be read by Fortran?

    Posted: 20 Feb 2020 11:07 PM PST

    I am using Python to retrieve data from Google Firebase but I then want to process that data and display it (as a table) with Fortran. My initial idea was to write it to text file line by line with python and then code a way to parse the text file with Fortran.

    But is there a better way or recommended data structure for Fortran?

    Example Data,

    Date Total Time Amount
    2020-01-12 34 750
    2020-02-11 54 1200
    submitted by /u/Fhy40
    [link] [comments]

    Need help with this Lab assignment, I got stuck with just simple stuffs.

    Posted: 20 Feb 2020 11:03 PM PST

    Hello guys, so basically this is the requirement:

    Create a program that takes in Name, gpa, and scholarship amount from the user. Then print the name, gpa, and scholarship amount back to the user with default settings, then with at least 3 different output settings and see the difference. Then set the output settings back to default

    For the second part, this is what i got

    cout << "123456789012345678901234567890" << endl; // cout << fixed << showpoint << setprecision(2); // cout << left; // cout << setw(10) << name << setw(7) << gpa << setw(8) << scholarship << endl; // cout << setfill('*'); // cout << setw(10) << name << setw(7) << gpa << setw(8) << scholarship << endl; // cout << setw(10) << name << setfill('#') << setw(7) << gpa << setw(8) << scholarship << endl; // cout << setw(10) << setfill('@') << name << setw(7) << setfill('#') << gpa << setw(8) << setfill('^') << scholarship << endl; // cout << right; // cout << setfill(' '); // cout << setw(10) << name << setw(7) << gpa << setw(8) << scholarship << endl; // return 0; // } // 

    So for the first half, as for asking user input and print back to the user: this is what i got but keep running into problem:

    #include <iostream> #include <string> using namespace std; int main() { int name; double GPA; int scholarship; cout << "Please Enter student name: "; cin >> name; cout << endl; cout << "Please enter Student GPA: "; cin >> GPA; cout << endl; cout << "Please enter scholarship amount: "; cin >> scholarship; cout << endl; } 

    Basically it wouldn't let me type in the input for GPA and scholarship. After i type in the student name and it would just show the GPA and scholarship line.

    It's late and I'm having a brain fart and can't figure out what i'm missing right now. Any help would be much much appreciated.

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

    How do i connect my NodeJS backend to my python script ?

    Posted: 20 Feb 2020 11:01 PM PST

    i have a NodeJS backend and i want to verify a file that is being sent to the server using my python script.

    Right now i'm doing it statically to make sure it works but i need to automate it.

    i was thinking of using node to move the file to a location that i point my python script to and just send the file name via a HTTP request.

    Do i need Flask or tornado ? and what do i need on the server side ? is there a better way of doing this ?

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

    So I had an idea for a 2d isometric simulation like game. Where should I start?

    Posted: 20 Feb 2020 10:44 PM PST

    I use a very basic knowledge of python to make scripts at work (a retail it company). I also know postgres and bash.

    I had this idea about a game and i mostly should start from 0. I saw on internet that there is a thing called a game engine thats it supposed to be already pre-scripted for me to use too.

    So, what should I do? Open a py file and begin programming or I can start somewhere easier?

    Thank you

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

    Loop question for Javascript

    Posted: 20 Feb 2020 10:05 PM PST

    let num = 3; for (let i = num; i >= 0; i--) { console.log(num - i); } 

    output : 0, 1 , 2, 3

    However, I assumed the process to be ->

    First loop : num = 3, i = 3

    -> Result : 3 - 3 = 0

    Second loop : num = 3 , i = 2

    -> Result : 3 - 2 = 1

    Third loop : num = 3 , i = 2

    -> Result 3 - 2 = 1

    Because it seems like "num" has a constant value of 3 since there is no "num++" or "num--"

    and 'i' keep reset as 3 because of "let i = num"

    How is the value of "i" keep changing?

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

    I don't know anything about programming but I want to get started. How do I start?

    Posted: 20 Feb 2020 10:04 PM PST

    I want to start programming. I always wanted to do it but never got into it. Recently 8 saw a post about a snake game bot and that inspired me to code a bot .

    I enjoy playing tetris and thought of learning to code so I can make a bot. Where do I get started and how do I make my tetris bit dreams come true?

    (I play tetris on the official website currently. Will any of your suggestions be applicable there or do I need to get another tetris application?)

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

    need help finding a javascript resource

    Posted: 20 Feb 2020 09:58 PM PST

    i saw a resource that had an anime avatar girl and text bubbles and you would mostly just code along, i didn't do it very much

    i remember the very first few things was doing stuff with rectangles

    i've been looking through my history for a while now, i can't seem to find it

    pls help and thnak you

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

    What language should I build this program in?

    Posted: 20 Feb 2020 09:39 PM PST

    To improve my current work center efficiency and branch to branch continuity I want to make a standardized, easy to use but individually customize-able program.

    The basic features of this program would include:
    The program/server would be locally installed on a network drive, I think.
    An Events Log
    Electronic Checklists
    The ability to build checklists in program, without developer assistance
    The ability to export checklists and email them to another branch, who can then import them for use.
    The ability to automatically fill events log entries upon completion of the electronic checklists
    The ability to log users on and off of the events log, as well as track the checklists they have run
    Ability to pull a report on an individual listing # of specific checklists they have completed
    The ability to export electronic checklists to paper copies in the event of system outages
    The ability to have two users simultaneously edit the log and run the checklists
    Users should be created locally on the shared network drive.
    The ability to sign events logs with digital signatures/certificates

    More to it but those are the basic functions I'm looking for. I want the program to be as user friendly as possible, so that once it is implemented, actions and edits can be made by end users instead of requiring training for managers.

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

    How is the result 10 not 6? [Javascript]

    Posted: 20 Feb 2020 09:00 PM PST

    let arr = [1,2,3,4,5]; let total = 0; for (let i = 0; i < arr.length; i++) { total += arr[i]; { if (i > 2) { break; } } console.log(total); total = 0 + 1 -> total 1 total = 1 + 2 -> total 3 total = 3 + 3 -> total 6 

    I think the snippet should end here.

    How is that it continues until "total 6 + 4 -> total 10?"

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

    My program to find the sum of all elements in a matrix(using C) doesnt give the correct output.

    Posted: 20 Feb 2020 08:29 PM PST

    //a program to find the sum of all elements in a matrix using C. #include <stdio.h> void sum (int *, int, int); int main () { int a[100][100], i, j, p, q; printf ("Enter dimension of matrix \n"); scanf ("%d%d", &p, &q); for (i = 0; i < p; i++) { printf ("Enter data for row %d", i + 1); for (j = 0; j < q; j++) { scanf ("%d", &a[i][j]); } } sum (a, p, q); return 0; } void sum (int * p, int s1, int s2) { int sum1 = 0, count = 0; while (count <= s1 * s2) { sum1 += *p; p++; count++; } printf ("\n sum is %d", sum1); } 
    submitted by /u/Noobguitarist
    [link] [comments]

    No comments:

    Post a Comment