• Breaking News

    Monday, November 19, 2018

    Small lesson of the day: never check two floats for equality! learn programming

    Small lesson of the day: never check two floats for equality! learn programming


    Small lesson of the day: never check two floats for equality!

    Posted: 18 Nov 2018 12:30 PM PST

    Floating point numbers are always subject to round off errors.

    Instead you should check if they're within some small range (like, smallRange = 0.00001) of each other.

    Not good:

    float1 == float2

    Good:

    float1 > (float2 - smallRange) AND float1 < (float2 + smallRange)

    Good:

    abs(float1 - float2) < smallRange

    There are different good methods of comparing floating point numbers, in fact, floating point arithmetic is a subject on it's own. Point is, simple equality comparison of floats is never a good idea.

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

    [Python] Building a dictionary with {} or dict()

    Posted: 18 Nov 2018 08:21 AM PST

    From what I've read, I know that {} is preferred and is much faster; but what's the purpose of dict() then? In what rare scenario should I use it?

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

    How to structure your code when projects get larger and more complex, where to start?

    Posted: 18 Nov 2018 10:30 AM PST

    Hi there,

    A couple of months ago, I started developing a Python application/script meant to be used from the terminal(possibly with a web wrapping later on).

    I didn't think much about structure and what started out relatively simple became quite a mess of a code-base, a weird mix between OOP concepts and some necessary function in between.

    Time has passed and I would love to go back to that project and do a better job in structuring it. I was wondering if you guys would have some helpful resources for a beginner like me or tips in general, how I can do a better job.

    Also I understand that the structure very much depends on the application area. Basically my application reads data from several files , modifies it, depending on the respective type of data item, and writes them to a database.

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

    I never really learned to program - because I never had any problems to solve

    Posted: 18 Nov 2018 11:17 AM PST

    I have had seminars at University in which I learned Python and XML (we even programmed a game with Python - it was so cool!). I have had the oppurtinity to work on a project with others involving CSVs and MongoDB, but haven't coded anything for that. 20 years ago I learned QBasic and VisualBasic because I wanted to. I have purchased several books from Humble Bundle about programming and think I have stacked up a nice library on things.

    However, I never really used any of the knowledge again. The reason is not that I wasn't able to solve problems I encountered. The reason is that I never really had any issues to solve. (also, another reason is that I have AD(H)D and therefore have huge issues to stick to a task for a long time, especially if I encounter stupid problems)

    There are so many things I would be interested in doing, but that I don't really need or that get frustrating pretty fast. For example, two years ago I wanted to get an online chat protocoll - a pretty big one - as a database to perform some things that I have heard of in my courses on computational linguistics. I did not want to do some theoretical work there, but basically wanted to get the data analyzable. In a first step I wanted to parse the whole html file and get a csv out of it, that already differentiated between time, author and text written. I therefore wrote a few lines that would just take the text from the html and write it to a new file. I didn't even get past that, because stupid Windows always aborts such a task if the text is more than 10k lines long. It was so frustrating that after 12 hours of googling and trying different things I just gave up before I even got to code something. I never really undestood why it wouldn't work.

    I then came up with the idea of trying to mod a game. I'm a gamer and I thought this would be pretty useful and I believed that I could really learn a lot from that. Only problem is that I never had any idea what I could mod, because everything is basically already done by others. I have searched for modding ideas for about 1 1/2 years now and I haven't found anything.

    I would also love to pick up C++ because I would like to be able to use Unity and others to get into game programing more deeply. But I don't have any idea what I would like to program.

    I am posting here because I really want to do stuff and broaden my programming knowledge. But all the well meant advice like "program a calculator" or "just watch tutorial XY on YouTube, it's great!" or "try to copy someone else's work to learn something from that" doesn't work at all. I really need a reason to program, but so far never really found one. It's really frustrating like hell.

    Does anyone have any advice or ideas that could help me get things going?

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

    Think programming : What you should know before you start coding!

    Posted: 18 Nov 2018 10:00 AM PST

    Beginners - starting out in programming and coding, it's important to understand why those programming concepts exists. I've tried to explain it in this article, see if this helps!
    https://abscrete.com/think-programming/

    I've just started out this blog, your feedback is important :)

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

    What on earth is going on in this line of C code (pointers)?

    Posted: 18 Nov 2018 10:03 PM PST

    // get sockaddr, IPv4 or IPv6 void *get_in_addr(struct sockaddr *sa) { if (sa->sa_family == AF_INET) { return &(((struct sockaddr_in*)sa)->sin_addr); // <= the line in question } return &(((struct sockaddr_in6*)sa)->sin6_addr); 

    }

    I have not seen this before and though I have tried to parse it I have no clue what is going on. This is a function from Beej's Guide to Network Programming.

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

    Beginner: Looking for a great PHP tutorial for a specific (but very simple) starter project.

    Posted: 18 Nov 2018 09:29 PM PST

    Hey r/learnprogramming,

    I've simplified my project idea into a great starting point for using PHP (I've done lots of research and talked with many of my programming friends to focus on this to start).

    I want to create a simple webpage with several text boxes that connect to an external CSV file? I realize PHP is not needed for this, but it's a good place to start for learning that gets me excited about the actual project I want to build.

    TIA!

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

    Declaration of char and int in a linked list

    Posted: 18 Nov 2018 09:16 PM PST

    I'm trying to make a linked list with MLS teams and all their information. Below is my code and I keep getting the errors mentioned at the bottom of the page. How do I declare these correctly..? I need the team name and nickname in char and the rest in int.

    #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { struct Node { char teamName[16]; // data for team name char nickname[4]; // data for nickname int league; // data for league int conference; // data for conference int win; // data for win int draw; // data for draw int lose; // data for loss struct Node* next; // pointer to address of next node }; struct Node* head = NULL; // list with 11 nodes struct Node* first = NULL; // used with small guidance from geeksforgeeks.org struct Node* second = NULL; struct Node* third = NULL; struct Node* fourth = NULL; struct Node* fifth = NULL; struct Node* sixth = NULL; struct Node* seventh = NULL; struct Node* eighth = NULL; struct Node* ninth = NULL; struct Node* tenth = NULL; struct Node* eleventh = NULL; head = (struct Node*)malloc(sizeof(struct Node)); // allocate 12 nodes in the heap first = (struct Node*)malloc(sizeof(struct Node)); second = (struct Node*)malloc(sizeof(struct Node)); third = (struct Node*)malloc(sizeof(struct Node)); fourth = (struct Node*)malloc(sizeof(struct Node)); fifth = (struct Node*)malloc(sizeof(struct Node)); sixth = (struct Node*)malloc(sizeof(struct Node)); seventh = (struct Node*)malloc(sizeof(struct Node)); eighth = (struct Node*)malloc(sizeof(struct Node)); ninth = (struct Node*)malloc(sizeof(struct Node)); tenth = (struct Node*)malloc(sizeof(struct Node)); eleventh = (struct Node*)malloc(sizeof(struct Node)); head->teamName = "NY_Red_Bulls"; head->nickname = "NY"; head->league = 'MLS'; head->conference = 'Eastern'; head->win = 22; head->draw = 5; head->lose = 7; printList(head); return 0; } Errors: teamrecords.c:44:16: error: array type 'char [16]' is not assignable head->teamName = "NY_Red_Bulls"; ~~~~~~~~~~~~~~ ^ teamrecords.c:45:16: error: array type 'char [4]' is not assignable head->nickname = "NY"; ~~~~~~~~~~~~~~ ^ teamrecords.c:46:16: warning: multi-character character constant [-Wmultichar] head->league = 'MLS'; ^ teamrecords.c:47:20: warning: multi-character character constant [-Wmultichar] head->conference = 'Eastern'; ^ teamrecords.c:47:20: warning: character constant too long for its type teamrecords.c:52:1: warning: implicit declaration of function 'printList' is invalid in C99 [-Wimplicit-function-declaration] printList(head); 
    submitted by /u/beatsbyse
    [link] [comments]

    [Java]How do you dynamically create an object class with an array as the parameter?

    Posted: 18 Nov 2018 06:58 PM PST

    I've been stuck on this for hours and couldn't find a solution online.

    Basically, I have this Locus class. I want it to to be like...

    public class Locus(){

    locus1

    locus2

    locus3

    ...

    //getters and setters

    }

    the number of locus and their names need to be dynamic. Another method returns an array with locus names and I want to create a class dynamically based on the array. How do I do this?

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

    sqlite in cpp script question

    Posted: 19 Nov 2018 12:24 AM PST

    I have created databases and tables inside the terminal where when i .open FILENAME, the db appears in my working directory. I also tried creating a database and table in a cpp script then and running it, i tried opening up the same db in terminal but it just creates a new db file. Why is my file not being opened and saved when i open it in the script?

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

    How to get along with people who have different views on programming?

    Posted: 19 Nov 2018 12:16 AM PST

    I will make it short and sweet since you will get where I am coming from, because this is a pretty common issue.

    How do I get along with colleagues who want to implement a thing in a certain way that will hinder my understanding of the whole development process? What I mean by this is, how to come to a consensus when you have different design choices that you have to put in place.

    I will mention that I am not in any way a software architect, but I want to follow some developer principles that will allow my work to go smoother. However, my now team lead wants to listen to the main software architect, who I think, in my own ignorance probably, wants to implement something far more complicated and harder to maintain than it needs to be for the sake of whatever his goal is.

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

    Time limited deal for learning Python and ML - is this a good deal?

    Posted: 18 Nov 2018 03:09 AM PST

    It's a deal I came across on Techspot that for 'pay what you want' you can get a number of courses on Python and ML.

    with the wide range of quality in these types of courses, I'm wondering if these courses offered are any good, if anyone has any experience with either these exact courses or the instructors involved.

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

    Free Grokking the System Design Interview zip file

    Posted: 18 Nov 2018 11:59 PM PST

    Own custom program - How to approach it?

    Posted: 18 Nov 2018 11:52 PM PST

    Hey guys,

    I have started to be interested into programming to make some stuff at work easier for me.

    I want to create a program which is supposed to be kinda a database with personal information of people. I want it to be able to create lists and tables including certain information from that "database". It should also be able to create information for parents which are premade and only the date has to be changed which will occur on request in a popup when creating those information.

    All of the created lists/tables/information should be able to be printed.

    From the research I did so far I would go the approach of firstly creating the whole user interface for that program in visual basic and then feeding everything with C#.

    Does that sound about right or would you recommend other programming languages or a different approach to that?

    Thanks for your help!

    Regards, Rakinare

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

    I can't find the motivation to start any project, any advice?

    Posted: 18 Nov 2018 12:35 PM PST

    I've been learning web development technologies for the past 6 months.

    I have learned Javascript, Python, Ruby, Golang, PHP. I have learned SQL and NoSQL databases and key-value stores. Also studied the HTTP and WebSockets protocols.

    For health reasons, I am home bound and have got the time to study all this technologies to a degree I feel is more than enough to develop a not so basic web application. Of course, I keep advancing my knowledge every day, by reading articles, reading open source code, doing coding exercises, etc.

    But, I haven't built a single real project. I can't think of a single project idea that would actually be worth anything. Everything I can think of is useless or pointless in some way. I have tried to start any project regardless of usefulness just to practice, for example copying an existing website, but I soon drop it because there really is not point on doing something that already exists even for practice.

    I feel like I'm in battle with myself. This probably sounds like something to discuss with a therapist instead of fellow coders, but I thought that maybe some of you could give any advice on how to get to f*cking work already.

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

    [Java] What is the go to dependency injection framework for Java?

    Posted: 18 Nov 2018 11:50 PM PST

    I have heard about Google Guice and Spring. Guice however was last updated at 2009, and when I tried to download Spring from this site I got a 404. So I don't understand - what is the go to dependency injection framework for java? I use eclipse btw.

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

    What would this print in C/AL?

    Posted: 18 Nov 2018 11:43 PM PST

    MESSAGE('The value of %1 is %2','LoopNo',LoopNo);

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

    Printing pound signs in MIPS?

    Posted: 18 Nov 2018 11:06 PM PST

    I'm working on a project for school and am trying to print out a structure of sorts that happens to include the same symbol used for commenting, the '#'.

    Right now I am unable to compile and check, but is escaping the character enough in MIPS to make the print syscall work as intended?

    EDIT: It's also highlighting the bar (|) in blue as well, is that typical? Should it be escaped?

    submitted by /u/14bux
    [link] [comments]

    Angular - HTTP vs HTTPS Request

    Posted: 18 Nov 2018 11:02 PM PST

    The API provided to me only works with HTTP requests. If I change the url to https:// instead of http://, and make the same exact call, the API will return 404, but if I use http, it works fine (locally). On heroku, I get a cross origin error when I try to use the http:// url.

    I basically need to make an http request from https. I know that this will give me the cross origin error. How do I resolve this WITHOUT simply changing http:// to https://, since this isn't a valid solution.

    Thanks in advance

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

    Java - How to read a file and split two strings together? [JAVA]

    Posted: 18 Nov 2018 08:16 AM PST

    Here is what I mean exactly. I have this text file:

    SMITH FRED 12000.00 MENZIES ROSE 42350.54 JONNSON 8000.50 WATSON JAMES 50000.34 

    I want to go through each line and put both names into a String variable and the double in another. Any help is appreciated as I do not know where to start. Thanks.

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

    autoComplete.js - Pure Vanilla Javascript library

    Posted: 18 Nov 2018 10:40 PM PST

    https://github.com/TarekRaafat/autoComplete.js

    autoComplete.js is an easy-to-use pure vanilla Javascript library that's built for speed, high versatility and seamless integration with wide range of projects & systems.

    Please feel free to try it and let me know your thoughts.

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

    JavaScript - String Swap!

    Posted: 18 Nov 2018 10:32 PM PST

    Sonova...!!

    Posted: 18 Nov 2018 10:16 PM PST

    Feel like a total noob, I'm that old web dev that posted 3 weeks ago, and have been studying new languages. I've been wanting to learn how to make an app, so I've been studying Angular for the past week, following the documentation I assumed Web App is the same as an App, which apparently is like a web site, but displayed in a browser? Jesus, it makes sense now, but a while ago I was thinking why not just call Angular/React Javascript frameworks to make sites like the many ones that existed before?

    Anyway, is it okay if that I only want to make apps, I study React Native/Flutter, and for Web pages, I stick to my old HTML CSS JS? I'm only concerned about the database now, and I don't want to use PHP anymore. What should I use? Is it Node JS, does that work with normal notepad HTML/CSS/JS sites?

    Edit: Wait, it says Angular can be used for any platform, mobile and native, if so what' Flutter for then?

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

    How do you get UT1?

    Posted: 18 Nov 2018 10:14 PM PST

    Most documentations I've seen focuses on UTC, which is easy to get.
    For some, the definition seems recursive:
    dUT1 = UT1 - UTC
    Or, UTC = UT1 + dUT1

    But then I couldn't find more than that.
    What I'm trying to do is to get GMST (given a date, time and position), which for max accuracy, requires the dUT1, otherwise I can use UTC with <0.9 sec difference.

    Does anyone know about this topic here?

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

    No comments:

    Post a Comment