[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 327
Thread images: 30

File: Algorithms.jpg (48KB, 424x500px) Image search: [Google]
Algorithms.jpg
48KB, 424x500px
Old thread: >>58647282

What are you working on /g/?
>>
File: 1367321161210.jpg (34KB, 304x288px) Image search: [Google]
1367321161210.jpg
34KB, 304x288px
I'm making a game!
>>
My boring ass CSP exam.
>>
>>58651785
Good luck frogposter!
>>
Inductive programming really is the best thing ever.
>>
>>58651785
Me too anon.
>>
>>58651785
Stupid fucking frogposter I hope you fail

I KNOW you'll fail

I fucking hate you

die
>>
>>58651763
Is the book any good? any links for the a pdf?
>>
File: 1477570612660.png (339KB, 1000x800px) Image search: [Google]
1477570612660.png
339KB, 1000x800px
>>58651827
why tho
>>
File: 1478190532507.jpg (69KB, 699x485px) Image search: [Google]
1478190532507.jpg
69KB, 699x485px
>>58651872
Cuz he likes gay traps
>>
This week is the one-year anniversary of when I started taking coding classes at my college. I'm a CS major now and I feel like I've finally grasped enough fundamentals to start going my own and doing my own projects.

At this point I have been trying to learn as much low-level programming with C as possible because I like it the most; I might end up becoming a systems engineer.

For fun over winter break, I made a pretty simple cache simulator. It's not incredible but I'm proud of it, seeing as how I am still a beginner to CS.

Can anyone recommend cool projects involving C that perhaps involve hardware or the operating system? I'd like to get some kind of personal project in to even have a chance at an internship.
>>
>>58651880
>traps
>gay
>>
After five months of unemployment I finally have another job...

now all I fear is pure terror because I could be fired at any moment for even the slightest slip-up or sign of disinterest

ohgodohgodohgodohgod
>>
project idea: Dynamic frog-post generator
>>
Work shit with Go and JS.

I decided I'm going to relearn C and Python. Is K&R still the standard for C? What's the new meme for Python?
>>
>>58651910
>k&r
nothing changed
>python
if you need a book to learn python kys
>>
File: 1479834768659.png (148KB, 1764x1746px) Image search: [Google]
1479834768659.png
148KB, 1764x1746px
>>58651907
I'm on it.
>>
>>58651934
godspeed lad
>>
File: frog legs.jpg (18KB, 250x250px) Image search: [Google]
frog legs.jpg
18KB, 250x250px
>>58651872
>>58651880
I bet you can't even program

Post some code
>>
>>58651943
>you'll cowards don't even program
ftfy
>>
File: 1476603443980.jpg (82KB, 960x843px) Image search: [Google]
1476603443980.jpg
82KB, 960x843px
>>58651943
Can you?
>>
>>58651943
im:io

prgrm
{
whspr("h-hello")
}


>>
I'm am learning how to use the subprocess module and a little about multi-threading in python3. I am at a point now where I can run a child process (like a test program in python or play a video with mpv) and capture both stdout and stderr (a lot of examples I have seen only capture stdout and redirect stderr).

https://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python
http://stefaanlippens.net/python-asynchronous-subprocess-pipe-reading/

The above examples are what I used as a reference. Now I have something that works!

http://pastebin.com/TySRgxye

My question is with the following part of the code:
    while tout.is_alive() or terr.is_alive():
while not queue_out.empty():
line = queue_out.get()
text = '*{}'.format(line.decode('utf-8'))
print(text, end='', flush=True)

while not queue_err.empty():
line = queue_err.get()
text = '+{}'.format(line.decode('utf-8'))
print(text, end='', flush=True)

# is a small sleep() needed here?
# time.sleep(.1)

If I run the program as is, my cpu usage jumps to ~26%. If I uncomment the sleep command my cpu usage is almost nothing.

Why does the sleep command result in lower cpu usage?
>>
>>58651763
I'm working on a really large project in C++ and it has a really huge inheritance tree. It has all the usual problems that inheritance brings... So I'm looking into the "composition over inheritance" design pattern. Any /g/entlemen familiar with this? I've read all the articles I could find in Google and watched all the YouTube videos. I get it, I guess, but everything out there describes the idea at such an oversimplified level that it's not really coming together for me when I try to convert this massive class hierarchy into a bunch of components. Any better sources of information?
>>
>>58652049
Please, stop coding.
>>
File: javascript.png (5KB, 148x107px) Image search: [Google]
javascript.png
5KB, 148x107px
>>
>>58652035
guess: breaks up cpu usage spikes so they don't register as one big spike
>>
>>58652049
If A inherits from B, instead give A a field storing a B.
>>
>>58651982
what language?!
>>
>>58652117
HTML
>>
>>58652121
not programming
>>
>>58652117
A concept one I've been working on sporadically.
>>
>>58652129
Kill yourself then.
>>
>>58652035
without the sleep your program is frantically checking if tout, terr, queue_out, queue_err are empty or not. the sleep 1 lets your computer rest every time. with the sleep, your program probably checks these about 10000 times a second (or however fast your cpu can go), with the sleep, your program only checks 10 times a second.
>>
>>58652137
gibs now
>>
>>58652116
Yep, that's the summary of everything I've seen so far. That doesn't quite cover it in practice, unfortunately.

>>58652080
Please, start coding before coming to programming threads.
>>
>>58652198
>That doesn't quite cover it in practice, unfortunately.
What the fuck is it missing?
>>
>>58652190
Not much to show 2bh.
>>
>>58652198
>Please, start coding before coming to programming threads.
You're talking to a master. So shut up little code monkey.
>>
Hi guys. I have a question. I'm writing a very low-level but fast byte code interpreter and I'm wondering if anybody has some good PDFs on typed assembly languages? If it helps my VM is using Elf as the container format.
>>
>>58652204
Well, if you've ever tried actually implementing something large with composition, you'll know that it shifts everything from compile-time (inheritance), to run-time. Anything that can move has a "moveable" object and anything that can be drawn has a "visible" object and so on... and you end up with a thousand allocations every time you create something. Performance sucks. And your code becomes very bloated with conditionals being checked on every single object "If this object has a 'moveable' then move it" etc... It's kind of impractical when you try to do something real, as opposed to everyone's examples with three classes "car," "boat," and "plane."
>>
>>58652269
Sounds like the fault of your garbage language where everything is behind a reference and on the heap out of your control.
>>
>>58652269
>>58652280
And null references, etc.
>>
>>58652165
Ok, that makes sense. Thanks.
>>
>>58652280
What kind of "control" are you talking about? In C++ you create things with "new" and you get a pointer and then you delete them with that same pointer. What else do you want the language to allow you to do with them?
>>
>>58652269
>allocations increase
no, the only extra allocations you need are single extra pointer to the composite object
>And your code becomes very bloated with conditionals being checked on every single object "If this object has a 'moveable' then move it"
your interfaces shouldnt be changing, so what's the problem here? dont tell me you're adding isMovable() methods....
>>
>dpt
>almost every post is a random insult or explanation of how I am so great and you are a shit-tard

Why are smug wannabe "programmers" literally the worst people ever?
>>
>>58651871
It isnt, the plain algorithm version is the most up to date and best organized, is java but is very readable java for algorithms. If you know any C derivative it'll be good for you. Tho I feel sedgewick is a bit too hand wavy at some points.
>>
Should I wait until my project actually has some functionality before uploading it to github or is it okay to upload it when all i've done so far is interface design?
>>
>>58652320
In C++ you'd just make the components fields without doing anything else to them. No pointers.
>>
Learning Racket
(define (sum-me values)
(if (empty? values)
0
(+ (first values) (sum-me(rest values)))))
>>
>>58652269
sounds like you're not relying on IoC (and/orSRP and noticeably DIP).

rather you seem to be passing around concrete implementations that do too much and aren't really thinking about the relationships of your objects (is-a vs has-a)

the extra overhead is basically the vtable and 1 extra indirection, but pimpl and crtp can alleviate that
>>
File: 979839298814263815.png (2MB, 941x790px) Image search: [Google]
979839298814263815.png
2MB, 941x790px
>>58652330
The entire 4chan is like this, but as a programmer I do agree that programmers are one of the most obnoxious and arrogant creatures on earth.
>>
>>58652376
you've never met the netsec wannabe hackers..
>>
>>58652354
pls reply desu
wat do u guys do
>>
>>58652396
Never wait to do something that you can do now.
>>
>>58652354
wait until your project becomes usable
>>
>>58652324
I might be misunderstanding, but where do your object's "moveable" and "drawable" and "whatever-able" objects come from if you don't allocate them? Any component-based code I've seen so far allocates these in the constructor of the owner.

No, there aren't necessarily "isMovable()" methods, but in a fully component-based system, you have to check somehow. I just use if/else checks. Even in the simple examples like "car" "boat" and "plane," your main loop is going to have to say "If this object is 'flyable'..." and the car will return false and the plane will return true and so on.

With inheritance, you just say plane->fly() and that's it, no check. You can't call boat->fly() because boat doesn't have that method.
>>
>>58652412
>Never wait to do something that you can do now.

>>58652415
>wait until your project becomes usable

reeeeeeeeeeeee
>>
>>58652396
it doesn't matter, just do work off the master branch and merge (working) changes over. if you expect people to use it then you should also use tags.

but github is just for social/collaborative coding.. so those don't really require a specific set of functionality in a project to work. you could use github for the issue tracker, wiki, and other project management tools which'd help improve feature implementations -- so sooner the better in that regard.

also
>using that cuck service github after trump got elected
>>
>>58652368
And with using cond
(define (sum-me-cond values)
(cond [(empty? values) (0)]
[(+ (first values) (sum-me(rest values)))]))

Is it common practice to use '[' and ']' in the tests?
>>
>>58652438
>using that cuck service github after trump got elected

kek
>>
>>58652420
Using composition instead of inheritance doesn't mean you have to go for a dynamic component-based design.
>>
>>58652455
s/tests/branches
>>
>>58651923
>if you need a book to learn python kys

t. someone who has never written anything of worth.
>>
File: 62021249726.jpg (29KB, 353x350px) Image search: [Google]
62021249726.jpg
29KB, 353x350px
>>58652540
>yfw
>>
>>58652540
how would you know fucksnot
>>
>>58652492
YES, I'm so glad someone mentioned this... I want to believe you're right, but there isn't ONE example of doing it statically, seriously. Every article and every lecture do it dynamically.

I can kind of vaguely imagine a static component system, but the details of it are difficult.

Yea, of course, you can have a class A and a class B and B can be a static member of A. But how do you build a component-based system around this? I would love to read an example of this. Honestly this would be the best of both worlds. I was just trying to make this work.
>>
>>58652585
http://boreal.aggydaggy.com/programming/2016/05/26/entity-safari.html
I'm glad you asked.
>>
>>58652585
how are you doing static binding / (or, probably what you mean) static allocation in your hierarchical system?

are you sure you aren't dynamically allocating those subclasses at runtime?
>>
>>58651763
That book is shit.
>>
>>58652420
it sounds like you are changing the interface of your objects. dont do that.
>>
>>58652671
It's C++, that's just the way it works. When you allocate a subclass, you get all the superclasses at the same time. Their constructors get called individually, etc... but the compiler lumps them all into one block of memory and it's just one allocation.

Maybe dynamic vs static is always a big deal, but it definitely can be. If you're allocating thousands of objects, and each of those has to dynamically allocate its components, performance is ruined. Memory allocation is a very expensive operation.
>>
>>58652720
There's no way around it. In a class hierarchy, you have

entity -> vehicle -> flying_vehicle -> plane -> fighter_jet

In a component-based system you only have "entity." The entity either has a "wings" object or it doesn't. Completely different interfaces.
>>
>>58651785
I'm starting with a text adventure, don't want to bit more than I can chew.
>>
>>58652597
Reading this now. Looks like a really good start. At first glance, it looks like the magic bullet is how he's storing everything in groups, like "StandingChars" ... Very clean.

Thanks for this, I think it's exactly what I want. I will read it carefully and find out.
>>
>>58652824
>In a component-based system you only have "entity." The entity either has a "wings" object or it doesn't. Completely different interfaces.
That's not true. With composition you could still have all those different types and you simply change inheritance to adding a field of the previously inherited type.
>>
>days in months are indexed from 1
>months in year are indexed from 0
whoever made java.util.Calendar should gas himself
>>
What are entity component systems like in languages with row polymorphism?
>>
Should I start with SICP?
>>
>>58652574
because there's a lot more to python than "hello world" you retard
>>
>>58652945
Dynamic composition based organizations don't use subtyping at all.
>>
File: 52809746341.png (658KB, 587x535px) Image search: [Google]
52809746341.png
658KB, 587x535px
>mfw I have +10k lines of uncommented code to comment
>>
>>58651763
I'm reading that book in it's 1990 edition, I think it's the first one.

Should I read the later ones instead?
Because the code examples reek of K&R and it's distracting as hell.
I get more mileage reading the detailed descriptions.

On that same note, what uses are there for binary search trees other than syntax parsing?
>>
>>58651881
In college I wrote a program for a class to calculate how quickly the processor can do an ADD operation. So a for loop of variable++, divide it out. Then we went on to making it multithreaded. You can expand from there and make your own hardware monitor.
>>
>>58652824
composition over inheritance =/= component-based system. You will still have the same exact types and interfaces, but you go around it differently.

You have a fighter_jet. The fighter jet currently inherits from plane. Instead of inheriting, you just give it an instance of plane and delegate all calls, for example

Plane { 
flying_vehicle flying_vehicle
void fly() {
// whatever
}

void_exist() {
flying_vehicle->exist()
}
}

fighter_jet {
plane plane;
void fly {
plane->fly()
}
void exist() {
plane->exist()
}
void shoot() {
//whatever
}
}

So you still have the same types and the same interface, you're just not using inheritance.
>>
>>58652982
Reminder that bad code requires a lot of comments. I like to comment too, but only if i'm explaining some logic that is not obviously in the code.
>>
>new to programming
>have to take a MATLAB class at uni
>had to create a programme that takes 3 numbers, then averages the two largest numbers
>use vector operations
>demonstrator comes along and says it's better to do it in loops
>MATLAB documentation says vector operations are faster

What am I missing here?
>>
>>58653036
mention it and ask him what and why and stop being such a lil bitch
>>
>>58653036
>It works tho
>>
File: 1450064898563.jpg (66KB, 526x400px) Image search: [Google]
1450064898563.jpg
66KB, 526x400px
>>58653052
>mfw that's my reasoning and I submitted the programme anyway
>>
>>58653036
>What am I missing here?
He's wrong.
>>
>>58652832
A lot of good game programmers started with a text adventure, good choice.

The main thing to focus on at the stage where you are now is separating your code and data. You're going to want to start out by writing it like this:
print("you are in a room. you can go east or west.");

getkey(k);

if (k == 'w')
print("you went west. now you are in a dark room.";
else
print("you went east. now you are outside.";


That's really bad and you'll learn why very quickly if you go down that road. Store the game's map as some kind of simple database, even just a plain text file is fine. Read in the database and then have your game's main loop look more like this:

while (!game_over)
{
print_current_room();
get_player_input();
move_to_new_room();
game_over = check_if_died();
}
>>
>>58653036
>loop for this
literal autism
>>
>>58653036
>unitards in charge of writing good code
>>
>>58653033
I also have to write its documentation. The problem is that I didn't even write the fucking code. Some guys did some HR project or some bullshit at work and they "don't like documenting", and it falls to me to do this pajeet's job.
>>
>>58653033
reminder that uncommented code isnt actually readable
>>
>>58652999
That's an abuse of composition, though.

You're going from saying "a fighter_jet is a plane" to "a fighter_jet has a plane" and "a plane has a flying vehicle."

It misses the point of using components at all.
>>
>>58653141
Code isn't taxonomy, and it doesn't miss the point of composition. You can use composition more than once, for example, and there's no ambiguity.
>>
File: e9031bec9d.png (9KB, 682x247px) Image search: [Google]
e9031bec9d.png
9KB, 682x247px
>>58653094
Holy fucking shit, that's sounds like a nightmare.
>>58653106
Sometimes is better to no comment at all, because it's dumb and redundant.
For example: >pic related
Both functions do pretty much the same, but the opposite, one is clear enough to guess what it does, and the other one needs comments since it makes other extra operations.
>>
>>58653193
Well, I think the second should be called Reset or StopAndReset or something. If it's just called Stop, you can't expect that it's also going to reset the values. Though that blurb about the event is retarded no matter how you look at it, that's an implementation detail.
>>
>>58653193
leaking implementation details in the public documentation is the wrong way to do it.
(a comment for this would be good, but all that impl info in xmldoc is wrong)

literally violating encapsulation
>>
Can someone define a "parameter" for me in one sentence that a child could understand?

Early Java learner here.
>>
>>58651763
Should I learn web back end with Java or C#/.NET? Also, where do I start?
>>
>>58653267
you know functions? like f(x) = x + 2. here, x is a parameter to the function f.
>>
>>58653267

name is the parameter passed in
greet("bob")
--> hello bob

function greet(name) {
print("hello " + name);
}
>>
>>58653267
a thing you give a thing to do a thing
>>
>>58653067
Thanks for the tip, anon.
>>
>>58653299
Like how I gave your mom the D to do the sex
>>
>>58653299
>>58653298
>>58653288

What's the difference between that and an argument?
>>
>>58653319
exactly, your d was the parameter, good job anon.
>>
>>58653267
Parameters are the things functions request. Arguments are the things you give to functions to fulfill their requests.

(technically they aren't requesting anything, but easier to read that way for a child)

func foo(a, b) { }
// a and b are parameters

foo(1, 2)
// 1 and 2 are arguments
>>
>>58653238
>>58653243
Yeah, both of you are right about that, gonna change it.
>>
>>58653332
same thing really
(co)routines use arguments
subroutines use parameters
>>
>>58653332
an argument argues how that thing does its thing.
>>
File: 1482907384969.png (327KB, 1048x594px) Image search: [Google]
1482907384969.png
327KB, 1048x594px
>>58653332
>What's the difference between that and an argument?
>>
>>58653332
A parameter is a property of the function, an argument is an actual thing you pass for a parameter.
>>
>>58651763

if you want to add, lets say, 5 to a number via a function. You would pass the number to the function so you can add 5 to it. The number you want to add 5 to would be the parameter. Example:

function addNumbers(int x) {
x += 5;
return x;
}
>>
>>58653036
As a student you might not always what is coming next.
Most problems can be solved in multiple ways.
Maybe the plan is to teach you one way to solve problems and then you are given exercises where you can solve it using that method and later you have to solve problems in another way.

I had an intro course to C where we were given a task each week.
Next week we were given a way to solve that task, but in a different way than we did.
We then used the improved method to solve the next task, and then we were given a better way to solve it.
This was to build up the knowledge of how to solve problems, how to document it and how to use documentation as a way to plan how to write applications.

Now when you have passed the course and you reflect on it, think about these situations.
Was it a bad instructor?
Was the assignments bad?
Or was there a plan that made you think in a different way so it improved your learning?
If the course was bad and you didn't learn anything at all, make suggestions to the people in charge.
I have done this a lot throughout my education and the courses have improved for the next students.
Some courses did major changes and some things were small enough to be corrected while I was taking the course.
>>
>>58653279
What do you mean by "web back end"?

Literally the backend of what the website GUI asks for, or like data integrations outside of the website application pushing to the database?

Either way, ASP.NET (C#) is used more than Java for actual web development, but you might want to go get some memes from >>>/g/wdg
>>
>>58653382
Thanks for the advice anon.
>>
>>58651763
A program that inputs two lists and uses Welch's T-Test to determine if there is a statistically significant difference between them.

It was tedious as hell putting the t-table into the program.
>>
lpszClassName: "F\0o\0o\0\0\0".as_ptr() as winapi::LPCWSTR

Fuck the police.
>>
>>58653547
asp.net isn't used more than java for webdev, anon..
>>
>>58653193
I've always heard "comment the why, not the how." Your snippet is a great example.

A useful comment is something like "// Must reset the counter here because Start() assumes that it is already zero and does not reset it."
>>
>>58653547

stop telling people to use M$' shitty layered language and frameworks
>>
>>58653619
oh boy here we go
Also, use PHP
>>
>>58653645
There is no good comments. But there is good documentation encoded in comments. Do you see the difference?
>>
File: anal beads.png (73KB, 1179x617px) Image search: [Google]
anal beads.png
73KB, 1179x617px
>>58653619
Yes, it is.

Spring is the most popular Java webdev framework, if I recall correctly.

Are you confusing Java with Javascript?
>>
>Networking professor has been bashing the OSI model into our head for the past three classes
Help
>>
How can I accept a variation of yes or no (YES, yes, Yes, Y, y, No, no, N, n, NO) without making a mess with if statements? I am doing this in C#
>>
Unironically installed Gentoo.
>>
>>58653771
Make a list of them and check containment?
>>
>>58653036
>the real answer.
Lets say your new input is 40 vars not 3.
Your code is obsolete.
that dumbass who knows how loops work. can still crunch the numbers.
>>
>>58653683
no, I'm saying that Spring and Wicket and Play and JBoss and Vaadim and Faces have a larger marketshare than ASP.NET (MVC and classic).

(marketshare in terms of requests per day)
>>
What equipment do I need to become a master? I already have:
* HHKB with purple artisan cable
* 3 monitors
* knee socks
>>
>>58653798
Was hoping for something more elegant
>>
File: anal beads.png (57KB, 1169x563px) Image search: [Google]
anal beads.png
57KB, 1169x563px
>>58653619
Compared to all web frameworks

PHP still runs the internet, and ASP.NET has a massive chunk of non-PHP marketshare.

I'm not saying ASP.NET is inherently good. Just saying that it's easily more common that Java for website development, and massively popular overall.

>>58653805
That is simply incorrect. ASP.NET still has the lion's share of the top 10,000 websites measured by traffic.
>>
>>58653773
i3, right?
>>
File: anal beads.png (58KB, 1175x565px) Image search: [Google]
anal beads.png
58KB, 1175x565px
>>58653805
>>58653834
Top 10K for comparison
>>
>>58653826
https://ultimatehackingkeyboard.com/
>>
>>58653832
How is that not elegant?
Just lower intput then check if it's in {'n', 'y', 'no', 'yes'}
>>
>>58652165
Just a followup, I added some variables to count the main loop and the two sub loops.
With cmd0 and sleep() commented out
----------------------------------------
cntr_main : 3323993
cntr_out : 7
cntr_err : 6
total : 3324006
----------------------------------------

With cmd0 and sleep(0.1)
----------------------------------------
cntr_main : 111
cntr_out : 6
cntr_err : 6
total : 123
----------------------------------------

With cmd0 and sleep(1.0)
----------------------------------------
cntr_main : 12
cntr_out : 6
cntr_err : 6
total : 24
----------------------------------------

It is *obvious* now that the while loop is performing less checks with the sleep() statement. This code is a piece of a larger home project I am working on, I guess I'm just fatigued from tracking down all my bugs and other issues. But it makes sense now.
>>
File: minedotjaypeg.png (202KB, 1440x876px) Image search: [Google]
minedotjaypeg.png
202KB, 1440x876px
writing my new game guiz! Im not sure my core algorithm (the whole gameplay mechanic) will be fast enough...
>>
how do you program when you have a headache?
>>
>>58653915
Take some pain killers, drink a nice big glass of water and find somewhere quiet to work.
>>
>>58653915
get some fresh air
drink more water
>>
>>58653911
There I thought C++ had the worst syntax aesthetics-wise.
>>
>>58651763
So I'm learning c++ classes and need some feedback
//Marriage.hpp
#pragma once
#include "Person.hpp"

class Marriage {
public:
Marriage(Person, Person, int);
~Marriage();
void addChild(Person);
Person getChild();
private:
Person *child;
Person parent1;
Person parent2;
int year;
};


//Marriage.cpp
#include "Marriage.hpp"

Marriage::Marriage(Person parent1, Person parent2, int year): parent1(parent1),
parent2(parent2),
year(year)
{

}

Marriage::~Marriage()
{
delete this->child;
}

void Marriage::addChild(Person newChild)
{
this->child = new Person(newChild);
}

Person Marriage::getChild()
{
return *this->child;
}


Can someone point out all the shit practices I'm doing here? By the way the Person class is just a container for name, birthyear and gender. Nothing special.
>>
>>58653945
i know it's more verbose than i realized... but this problem is a bit awkward whatever language
>>
>>58653911
>rust
nice mem
>>
>>58653771
Uppercase the input and check against YES, Y, NO, N
>>
>>58653957
>Marriage(Person, Person, int);
Wow, that's so progressive of you anon.
>>
>>58653957
Use smart pointers, 'this->' is unnecessary. Why is child a pointer, but parents aren't?
>>
>>58653957
>Can someone point out all the shit practices I'm doing here?
You wrote it in C++.
>>
>>58653957
You're not following the rule of 0/3/5. Also there's no good reason to have anything there private.
>>
>>58653981
>Why is child a pointer, but parents aren't?
Because you can have a marriage without children. This was the solution I came up with and I was hoping someone would spot it. What's the correct way of handling it? The compilers screams murder if I leave it empty as a normal class instead of a pointer.
>>
>>58653957
if (parent1.sex== parent2.sex) // throw a sanctity of marriage exception
>>
>>58653995
fresh meme friend
>>
>>58654008
>rule of 0/3/5
What the fuck is that?
>>
>>58653957
Why does c++ look like such a piece of shit.
Literally Visual Garbage - The Language.
>>
>>58653957
invariant
{
parent1->gender != parent2->gender;
}
>>
>>58654030
result of trying to graft OOP onto elegant C
>>
>>58654027
http://en.cppreference.com/w/cpp/language/rule_of_three
>>
>>58654027
http://lmgtfy.com/?iie=1&q=rule+of+0+3+5
>>
>>58654020
Are you implying that C++ isn't the massive meme here?
>>
I never use private.
I should probably start someday.
>>58654039
>elegant C
//display the list
void printList() {
struct node *ptr = head;
printf("\n[ ");

//start from the beginning
if(head != NULL) {
while(ptr->next != ptr) {
printf("(%d,%d) ",ptr->key,ptr->data);
ptr = ptr->next;
}
}

printf(" ]");
}
>>
>>58654075
Looks ok to me.
>>
>>58654040
>>58654050
Ho they gave a name for that evidence. My gosh it's like design patterns. Some people want to teach me how to walk.
>>
>>58654075
>>elegant C
What is your code snippet even trying to prove?
That you suck at programming?
>>
>>58654091
What?
>>
>>58654075
>camelCase not snake_case
>no space between if/while and condition, arguments
apart from that it looks nice
>>
>>58654101
That rule is trivial. It doesn't deserve a name.
>>
File: ubuntu-certified.png (16KB, 200x232px) Image search: [Google]
ubuntu-certified.png
16KB, 200x232px
can anyone on 4chan even write code.... this is embarrassing
>>
>>58654112
Well it makes it a hell of a lot easier to tell >>58653957 that he's not following it. I could say "you're not following proper RAII copy/move semantics" but that's harder for her to look up.
>>
>>58654129
Yes
>>
>it's C so it's okay

Wonder what would have happened if I had replaced printf with cout
>>
>>58654129

alert("ayy lmao");
>>
>>58653957
Consider this:
marriage.addChild(new Person("Adam"));

Adam will get unneccesarly created again. Just replace the body of Marriage::addChild() with
this->child = newChild;


Also, consider what happens when two kids are born.
    auto *mr = new Marriage(new Person("Bob"), new Person("Anna"), 2017);
mr->addChild(new Person("Collie"));
mr->addChild(new Person("Dan");;


I'd make a field
std::vector<Person *> children;
instead of
Person *child;


Also, look at smart pointers.
>>
>>58654147
can you maybe progress past your first programming class before you try to bait?
>>
>>58654147
There are some problems with that snippet.
However, it proves absolutely nothing, except that the poster is shit at programming.
>>
>>58654019
>>58654032
Putting unnecessary validation on user data is how you write bad software, ignoring the complete obviousness of marriage equality.
>>
iostreams is shite
>>
>>58654182
>unnecessary
Depends on the state and country.
>>
>>58654182
i think they were just making a joke anon.
>>
>>58654221
elaborate
>>
>>58654182
We're having a giggle m8
>>
>>58654019
>>58654032
>>>/pol/
>>
>>58654230
You don't want all those virtual calls.
>>
File: 1368858641879.jpg (76KB, 349x356px) Image search: [Google]
1368858641879.jpg
76KB, 349x356px
Best syntax award goes to...
>>
>>58654153
also you should throw an exception if they're the same sex
>>
>>58654254
Haskell!
>>
>>58651785
Everybody is, and yours will go by unnoticed just as well.
>>
>>58654254
1. any lisp
2. haskell
>>
>>58654254
lisp obvs
>>
>>58652943
you don't have more than one january in a year
>>
>>58654254
sh
>>
>>58654254
Intel assembly
>>
>>58654238
Nah
>>
>>58654182
Are you next going to say that checking their ages or if they're already married or related is "unnecessary validation"?
>>
>>58654232
>>58654227
>>58654225
The point still stands, adding checks when they're not needed makes your code more complex. Although no one has suggested the most obvious check, you can't marry yourself.
>>
>>58654277
>>58654274
lisp has no syntax lol
>>
>>58654153
>
Adam will get unneccesarly created again. Just replace the body of Marriage::addChild() with 
this->child = newChild;

I got it working by changing the argument into an pointer but now I can't do
marriage.addChild(Person("Frank"));

for example.
Could you explain the specifics of it?
>>
>>58654320
no syntax is best syntax
>>
>>58654254
Swift, obviously. C like, but with pattern matching, trailing closures and property behaviours.
>>
>>58654255
If it makes you feel any better I have this in the Person class:
std::string Person::getGender() {
switch(gender){
case MALE:
return "Male";
case FEMALE:
return "Female";
default:
return "Mental illness";
}
}


But that shit has nothing to do with programming now does it.
>>
>>58654309
>>58654315
No but the number of checks you add increase the complexity of the code and the amount of information you need to collect.
>>
>>58654343
These kinds of sanity checks can help stop fraud
The less faulty data your program can accept, the better
>>
>>58654343
you just need 1 bool
>male
>other

You can't go wrong.
>>
File: 1484717593180.png (182KB, 866x635px) Image search: [Google]
1484717593180.png
182KB, 866x635px
Worst syntax award goes to...
>>
>>58654388
C++
>>
>>58654388
Obviously C++
>>
File: happy.jpg (289KB, 1180x783px) Image search: [Google]
happy.jpg
289KB, 1180x783px
>>58654309
What's the problem?
>>
>>58654315
Asserts/enforce are nice though.
unit testing also has its place.
>>
>>58654396
>>58654401
I love c++ but goddamn if the syntax isn't aids...
>>
every couple weeks i get so anxious i feel like my heads gonna pop
>>
>>58654388
ocaml
rust
c++
>>
>>58654409
>I love c++
You're sick. Get help.
>>
>>58654388
>>58654396
>>58654401
it's java you nerds, you know the language that ironically set out to be the c++,++ and ended up being worse.
>>
>>58654425
Hahaha, no, no it isn't.
Java might be worse than C++ but it's syntax isn't nearly as awful.
>>
Hey /dpt/
what the fuck happen at line 28?
#include <iostream>

class test {

public:
test () {
std::cerr << "test::test ()" << std::endl;
}
test (const test &) {
std::cerr << "test::test (const test &)" << std::endl;
}
~test () {
std::cerr << "test::~test ()" << std::endl;
}
test &operator = (const test &) {
std::cerr << "test::operator = (const test &)" << std::endl;
return *this;
}

};

test gimme () {
test t;
return t;
}

int main () {
test t (gimme ());
return 0;
}
>>
>>58654425
I know Java is shit and all, but syntax wise, it's not an insult on the eyes.
>>
>>58654425
Java is verbose as fuck but consistent.
C++ is verbose and inconsistent.
There's at least 5 ways to do anything.
>>
>>58654425
this
>System.out.print
>public static void
>functionThatAddsTwoNumberTogether()
>>
>>58654437
RVO.
>>
>>58654442
>>58654444
public class HelloWorld {

public static void main(String[] args) {
terminal window.
System.out.println("Hello, World");
}

}


#include <iostream>

void main()
{
std::cout<<"Hello World";
}

even from hello world it's easily apparent.
>>
>>58654452
My finger are sore thinking about typing this shit again
>>
>>58654477
Oh OK. But doesn't it violates the C++ standard?
>>
>>58654491
Can you at least get past the first chapter of your book before trying to bait?

You're embarrassing yourself.
>>
>>58654452
It's still better than
std::cout << static_cast<std::chrono::milliseconds>(mynamespace::myfunction()) << std::endl;


>>58654491
For starters, you fucked up both of the code snippets.
>terminal window
>void main
Also, take a look at more complicated pieces of code.
>>
>>58654503
No, it will become THE standard in C++17.
>>
>>58654246
Virtual calls is not why streams are shit.
It's the syntax.
>>
im falling in love with reactive programming :( cyclejs in particular :(
>>
>>58654507
>>58654518
i literally just forgot to de-comment the rest and have void in muscle memory, what comparison do you want though?
>>
>>58654518
namespace aliases are a thing
>>
>>58654571
Do you even know what the void does?
>>
>>58653911
Man, I thought I was the only one memeing enough to start programming a game in Rust.
>>
Any good course/pdf/book on writing modern C ?
>>
>>58654522
It's the virtual calls, virtual inheritance, and mixing locales with I/O, the syntax is meh.
>>
>>58654581
return type
it's valid in D, which is where my mind is now.
>>
File: peepee.jpg (55KB, 500x473px) Image search: [Google]
peepee.jpg
55KB, 500x473px
Going to be sending out some resumes to cs jobs. Do I need to put my birth name on there? If I don't though it's going to be weird when they call my old managers asking about a girl with my last name...
>>
>>58654617
http://icube-icps.unistra.fr/index.php/File:ModernC.pdf
>>
>>58654617
>C
>Modern
>>
>>58654647
>Rule A: C and C++ are different, don’t mix them and don’t mix them up.
Good. An author who seems to know what he's talking about.

>>58654669
The latest C standard was in 2011, and they are currently working on the next one, which is expected around 2021/2022.
How is that not modern?
>>
>>58654669
>still backwards compatible with 70s era C
>>
>>58651763

I want to create a program that reads TeX and basically creates an equation type/object from it. it will only support simplish algebra so it won't be hard. From there I might make it able to find solutions to diophantine equations.

I've learned from my past mistake of writing a PNG file reader in Python. Precision protocol shit is no fun in a scripting language. Plus the PNG file format has a library called libPNG which is really the only thing you should ever use to read a PNG file.

Does TeX have a version of LibPNG to do what am about to do?
>>
>>58654669
It's still used and taught everywhere.
embrace it C will never die
>>
>>58654730
Java is still used and taught everywhere
embrace it java will never die
>>
>>58654627
Literally none of those are a problem when IO itself is expensive.

streams and printf have been benchmarked plenty of times and they perform the same.
>>
>>58654745
That doesn't counter my point.
Also, C has been around much longer than Java
>>
>>58654627
Also, virtual calls and inheritance is cheap. At least way cheaper than you seem to think.
>>
>>58654802
C isn't modern though.
You can staple on modern features, but that won't make the language modern.
>>
>>58654806
Eh, maybe you're right, I still don't like the hierarchy behind them.
>>
>>58654819
So C++ isn't modern either.
>>
>>58654723
If all you want is parse relatively simple mathematical statements, writing a parser for that isn't particularly hard, depends on what you want to recognize though
>>
>>58654819
If a considerable number of people are using it ot make modern programs than it's a modern language. Being modern has nothing to do with features
>>
>>58654647
Thanks!
>>
Whether your IO is stream oriented or not, format strings are the gods of formatted printing.

std::ostream really needs to overload operator() to provide a printf-like interface.
>>
What exactly makes a language modern?
>>
>>58654854

Tex is extremely simple especially for basic algebra so it wouldn't be that hard
>>
>>58654853
exactly.
>>58654855
What's a "modern" program exactly?

Because making a "modern" program with C90 is very possible and still done. That doesn't actually make the program or c itself, modern.

I honestly don't understand why this is even an argument.
>>
>>58654882
no pointers and garbage collection
extra modern = oop and pattern matching
>>
>>58654907
>no pointers
why?
>>
>>58654902
A modern program is one that was made recently.

modern: relating to the present or recent times as opposed to the remote past.
>>
>>58654882
No OOP, consistent features, based on actual PLT research
>>
>>58654882
>>58654919
>>
>>58654907
>no pointers and garbage collection
So by your stupid definition, Rust isn't modern.
Also, there is absolutely no way for a kernel to be written in a modern language.
>>
>>58654641
I don't but I'm not trans...
>>
Do you guys ever actually program or do you just shitpost about languages all day.
>>
>>58654937
Kernels are so 1980s
>>
>>58653067
This is great advice
>>
>>58654899
why do you need tex tho? do you also use it for displaying the input?
>>
File: 1475359427227.jpg (84KB, 559x763px) Image search: [Google]
1475359427227.jpg
84KB, 559x763px
>>58654641
Nigger what the fuck are you talking about?
Are you a fucking apache attack helicopter is that it? Then just say so.
Your question is such that you either gotta reveal you're a trapshit or don't ask the question, can't have both famalam.
Literally just tell them you're m2f or w/e so they will not be surprised when your old employer refers to you as the burly man you are.
Just be glad you don't live in glorious 13th century Italy where you'd have been burned at the stake or at the very least castrated for your rickety ass namby pamby girlboy heresy xD no offense.
>>
how do static fields behave exactly? does every instance of an object contain a reference to that field?
>>
I'm about to download Python and start following some online programming guides
>>
>>58655139
It's like a global
>>
>>58655159
stay away from zed shaw
>>
>>58655139
In C++, yes.
It is a single member accessible from anywhere that class is in scope
>>
>>58655139
>does every instance of an object contain a reference to that field?
no
>>
>>58655180
a static field only has one instance it's not duplicated/referenced in each object instance
>>
>>58655211
Yeah, that's what I meant
>>
>>58655211
i know that, but do objects themselves take up more memory, because they contain a reference to a static field?
>>
>>58655265
no
>>
>>58655011

because then I could use a tex renderer to edit the equation
>>
>>58654641
Yeah, you need to tell at least their HR people so they can figure out the references. You can probably ask them to not tell your possible future manager and cow-orkers, at least with a big employer; after all, it shouldn't be relevant to if you're good at your job.
>>
>>58654554
Beб-paзpaбoткa - cкyчнoe дeлo.
>>
>>58654723
>Precision protocol shit is no fun in a scripting language
What does this mean?
>>
>>58655356
It means all REAL libraries are made for strongly typed structured languages and not pybaby gayshit.
>>
>>58655296
https://people.eecs.berkeley.edu/~fateman/papers/parsing_tex.pdf
might be an interesting read.
I don't think there's a tex parser like your looking for, since tex is made to express how something should look on a paper and not for unambiguously describe formulas.
Another approach might be using your own syntax and converting to tex for displaying
>>
>>58655403

mildly interesting but it looks like they are trying to convert scans of math books back to tex code
>>
>>58655139
You don't need to instantiate an object to have access to a static property.
>>
>>58655139
No. You can think of the class itself as being an object that contains the field.
>>
>>58655589
yeah but in 2 they describe some of the difficulties of parsing tex expressions, like sin x sin y might be sin(x*sin(y)) or sin(x)*sin(y)
>>
>>58655296
It seems easier to represent it in some unambigious form then only convert to tex for displaying.
>>
File: WhatTheFuck.png (19KB, 1452x165px) Image search: [Google]
WhatTheFuck.png
19KB, 1452x165px
>tfw Visual Studio 2017 enforces naming conventions.

Holy shit.
>>
>>58651763
How many of you program drunk?
>>
>>58655785
Not often enough desu
>>
text editor
>>
>>58655762
VS is a meme
>>
>>58652455
Using [ ] for cond cases is standard
>>
>>58655785
>try to program drunk
>start watching anime instead

I just lose the willpower to do something productive drunk. Now programming stoned...
>>
>>58655785
I'm a programming god when I'm drunk. And I'm always drunk
>>
>>58655762
>pajeet
>you must update language
>will you
>>A) add features and functionality to improve development and capability
>or
>>B) make it more enterprise compliant
>>
>>58655785
I'm sober mainly.
>>
File: 2017-01-25 18_44_47.png (2KB, 232x56px) Image search: [Google]
2017-01-25 18_44_47.png
2KB, 232x56px
OpenGL / C++ / SDL

me again. Why does the font on the left (generated using SDL + SDL_TTF only) look so much less blurry than the other (generated using SDL+ SDL_TTF + generate an OpenGL texture from the surface pixels)?
>>
>>58655880
GL is probably applying some AA to it.
>>
Have you read your SCIP today?
>>
>>58655762
Fucking fire, mate!
Finally!
>>
>>58656044
SICP, actually.
>>
>>58655907
can that be disabled?
>>
>>58656044
I don't have time to spend on meme books.
>>
File: 547871118614391.jpg (100KB, 821x695px) Image search: [Google]
547871118614391.jpg
100KB, 821x695px
>>58655762
Nice
>>
New thread:

>>58656123
>>
How the fuck does git work with multiple people working on the same project? Say I'm working on feature a and someone is working on feature b and they are their own branches from a develop branch. A gets merged into dev branch, and a little while later b is pushed as well. Now if they both happened to have modified the same thing, what happens here? Do I just have to choose one version of the modified file, basically breaking one feature or the other?
>>
File: scip.jpg (41KB, 387x499px) Image search: [Google]
scip.jpg
41KB, 387x499px
>>58656078
No, I spelled it correctly.
>>
>>58656044
Yeah, actually
>>
>>58656202
Care to share that .pdf? I got the contents in some html files.
>>
>>58656261
https://sicpebook.files.wordpress.com/2011/06/sicp.pdf
>>
>>58656294
ty senpai
>>
>>58655785
I am my most productive programming about one and a third beers into the evening.
>>
>>58655880
I'd venture to guess it's a rounding error. While SDL asks for absolute pixel positions OpenGL measures locations on the screen on the reals,[-1 , +1]. Since the mapping isn't direct the edges of your font might be falling on fractions of pixels, so when OpenGL goes to rasterize a pixel it's placing it on the n.3th location of the bitmap rather than the nth and that causes it to blend

As for a solution, I unno.
>>
>>58655762
noce
>>
>>58655880
the texture is probably being read with GL_LINEAR texture filtering. use GL_NEAREST and position the sprite so it aligns with the pixels on the screen
>>
>>58657308
you can still use GL_LINEAR as long as it's scaled 1:1 and properly aligned
>>
WHO /FORTRAN/ HERE
>>
>>58654254
Java
>>
>>58658314
this
Thread posts: 327
Thread images: 30


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.