[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 30
File: yF1VCTm.jpg (89 KB, 1366x768) Image search: [Google]
yF1VCTm.jpg
89 KB, 1366x768
old thread: >>51764094

What are you working on, /g/?
>>
Traps #1 best threads
>>
>>51767823
>>
File: fZQOg8v.gif (2 MB, 400x595) Image search: [Google]
fZQOg8v.gif
2 MB, 400x595
Practicing D
>>
meme
>>
Is it stupid to put "All Rights Reserved" on a repo you put on github?

Because I feel like doing that right now.
>>
reminder that SJWs are trying to get you to like traps
>>
>>51768180
yes
>>
need project idea
something impressive to an engineering company
about a month

give ideas pls
>>
>>51768184
it's the jews
>>
>>51768185
What if it's something trivial like puzzle solutions to advent of code?
>>
>>51768180
just put an actual license
>>
>>51768193
What sort of engineering do they handle?
>>
>>51768193
Operating System
Compiler
Shell
Compression Algorithm
>>
>>51768193
3d rendered physics simulator
>>
Whats an intermediate to advanced programming exercise to do for practice?
>>
>>51768206
The entire company, everything; it's a very large company

>>51768209
OS is too long term, and I'm too inadequate for a compiler at the moment, but otherwise, maybe

>>51768223
hm

>>51768224
projects
>>
I wanted to finish some shit, but I'm so fucking tired and sleepy...
g'night, dpt
>>
>>51768237
nite bruh
>>
>>51768237
sleep well
>>
>>51768233
Statistical analyses
Neural network
FTP client
>>
>>51768252
>of what
>for what
>possible idea
I'll keep thinking, thanks for stirring ideas tho
>>
>>51768209
>>51768224
see >>51768209
or

Specify a microprocessor, build it in a logic simulator, write an assembler for it.
>>
File: i know all the memes.jpg (97 KB, 245x337) Image search: [Google]
i know all the memes.jpg
97 KB, 245x337
What's the best way to implement Advent of Code day 3?

I'm thinking making a 2 dimensional int array of 1000 by 1000 and simply putting santa in the middle.
>>
>>51768298
I'm not signing into the botnet; pic of the question.
>>
>>51768292
NEAT
Unfortunately I'm clueless when it comes to logic sims. That sounds like a great idea, though.
>>
File: 1410308481057.gif (628 KB, 500x375) Image search: [Google]
1410308481057.gif
628 KB, 500x375
good beginner-intermediate projects?

I have made a couple of video games, taken a few programming courses in college/highschool but the projects in school aren't challenging enough.
>>
>>51768289
Of data; there's always data to analyze
For anything; image processing, file compression (as above), etc.
>>
>>51768313
Fizzbuzz
>>
>>51768301
>>
>>51768302
It's just dragging and dropping gates, wires, and black boxing them. Checkout logicsim or logisim; one is dead the other is actively developed.
>>
>>51768313
You want a real challenge?
http://socalcontest.org/current/index.shtml
People compete in these competitions every year.
You have two hours to complete 10 questions.
Most teams only compete 3.
The top 10 are the only ones that exceed 4, and among those only the teams from Caltech, USC, and UCLA solve 7-10.
>>

class Point
{
private:
int m_x;
int m_y;
public:
Point(int x, int y): m_x(x), m_y(y) {}
int getX() { return m_x; }
int getY() { return m_y; }
void setX(int x) { m_x = x; }
void setY(int y) { m_y = y; }
};


>people who create getters and setters for no reason when they could just do
class Point
{
public:
int m_x;
int m_y;
};
>>
>>51768325
thanks

>>51768356
I'm not looking to go into a competition. dont think im good enough for that yet. But I want a good beginner/intermediate challenge to improve my skillz
>>
>>51768366
>making accessors and mutators for a Point
literally no one does that, not even the Java default API.
>>
>>51768339
Sounds like a graph and a house counter.
>>
>>51768339
Is there more to it than that? What are you supposed to do?

>>51768387
That's what I mean; are you supposed to implement something or?
>>
>>51768383
You don't have to finish all of them. As I said, on average most people can finish three in two hours.
When I went last year, I even saw an elementary school team.

The difference between what's in my link and whatever crap you'll come up with, is that the stuff in my link test both your logical thinking skill and your mathematical reasoning.

You can get similar from Project Euler, but those can be really mathy at times.
>>
>>51768366
The problem with that is that you can't track where changes are, but you could throw a "cout << "changing m_x to " << x << endl;" in your setter

which is a complete bullshit excuse for using them
>encapsulation
retarded pointless OO "concept"

>>51768384
Funny story; I started learning C++ last week and am making a program that lets the user create basic shapes and lines on a canvas, and my point class has accessors and mutators
:%)
>>
>>51768409
you do you, anon-kun.
>>
>>51768397
just find the number of houses that get more than zero presents.

the website is language agnostic, you write your own solution and then fill in the answer you get.
>>
>>51768423
In that case: 1. because I didn't get a command string.
>>
>>51768439
here's your command string
http://adventofcode.com/day/3/input
>>
>>51768454
>Puzzle inputs differ by user. Please log in to get your puzzle input.
>>
pleb here

/g/, is this a good selection sort algorithm? Kinda studying sorts right now, I wrote one but idk if its good

 private void modifiedSelectionSort() {
// Selection sort logic
int i = selectionTrack;
if (i < selectionArray.length - 1) {
int index = i;
for (int j = i + 1; j < selectionArray.length; j++)
if (selectionArray[j] < selectionArray[index])
index = j;

int smallerNumber = selectionArray[index];
//selectionArray[index] = selectionArray[i]
swap(selectionArray, index, i); //calls for helper method
selectionArray[i] = smallerNumber;
}
}
>>
>>51768387
>graph
no
It's a hashmap counter. The key is generated by using ^<>v as indicators to subtract or add to your (x,y) values as necessary.
When you're done reading inputs, you take the value set from the hash map and then count the number of houses with values over 2.
My algorithm is an O(n) time complexity and Theta(n) space complexity..
Enjoy.
>>
>>51768463
just login you fucking autist
it's not going to hurt you
>>
>>51768339
This can be solved with a sheet of paper and about half an hour. You're not supposed to brute-force it, you're supposed to determine the probability.

Furthermore, and infinite amount of houses will recevie at least one present.
>>
File: mandelbaum.png (128 KB, 327x491) Image search: [Google]
mandelbaum.png
128 KB, 327x491
>>51768475
I don't care that much at this point.
>>
>>51768480
>determine the probability
I seriously doubt that.
These online code challenges are always fizz-buzz tier.
If they wanted someone to stochastically model the probability of Santa delivering multiple presents, then they shouldn't market it as a "Advent of Code."
Rather, they should be testing people's logical thinking capacity, and the originality of algorithms.

I don't think you can get much better than a hashmap counter though. It's mathematically impossible to get better than O(n) in this problem.
>>
File: steel.webm (3 MB, 720x404) Image search: [Google]
steel.webm
3 MB, 720x404
Ask your much beloved programming literate anything.
>>
How do I flip SDL's coordinate system so its quadrant 1 instead of 4?
>>
>>51768530
Make a rendering function that makes a simple calculation to find the actual SDL y coord (0 is top) from the passed y coord/rect/etc

I suggest just getting over it though
>>
>>51768507
>an infinite two-dimensional grid of houses
What's 1% of infinity, anon?
>>
>>51768524
What project should I make next?

I know C and some C++
I have done:
a toy interpreted language
A 2d platform game
a 2d gravity simulator
a bunch of even more insignificant projects
>>
>>51768567
"an infinite two-dimensional grid of houses" is used to signify a hint to the reader that they aren't supposed to literally make an array the size of the planet, and that it would be dumb.

You can also figure out that Santa is actually only delivering to a fixed number of houses (i.e. not the entire fucking thing) because the website actually gives you sample input.

For another, it's impossible to mathematically indicate how many houses receive more than one present. You're not given enough information for that.

Honestly I think you're just being max autismo or reading the question wrong.
>>
>>51768524
Dang, I shouldn't have stopped at S2.
>>
>>51768570
an 3d game/simulator ?
>>
Hey /dpt/

I just finished the first half of a two-part C++ class at my school and feel like although I've got down most of it, I'm not quite... 'thinking' like a programmer. I know this will take some time. How long did it take all of you to really 'get a feel for it'? I think I just need to do it more. FWIW This is the book we're using.

http://www.amazon.com/Starting-Out-Early-Objects-8th/dp/013336092X/ref=sr_1_2?ie=UTF8&qid=1449650817&sr=8-2&keywords=starting+out+with+c%2B%2B
>>
>>51768719
>thinking like a programmer
took me about three weeks I'd say
http://www.alice.org/index.php
I made a flight sim in this back in high school in one of those three weeks.
Logic is easy.
>>
>>51768719
I became a complete fucking annoying, rude, arrogant and ignorant degenerate and felt like a programmer instantly.
>>
>>51768129
On my kawaii schoolgirl outfit
>>
>>51768570
hey post the code for the 2d gravity simulator. Are you the guy that was asking about gravity = 0 making for infinite bounces?
>>
>No problems anon, you can interface with our REST API

Sounds good.

>You'll need to make three different queries to work your way to the data you want

Yeah I can work with that

>It returns JSON

Pretty standard

>You'll have to parse six layers deep in half a MB of JSON

Well that's new, but whatever

>The final leaf is base64 encoded

So.. I'll use a decoder

>Sweet. Then you've got a packed C structure

wtf

>The third byte can be used with a series of binary ORs to determine which of the several packing formats is in use

Annoying.

>Length fields are represented as 24-bit big endian integers

wtf

>The final structure can only be parsed using an undocumented OpenSSL API. Many languages don't have bindings to undocumented API's btw

...
>>
Wew lad, AoC day 9 was a breeze compared to D7 and D8, at least for me, D8 wasn't that hard but I got stuck with an edge case.
>>
I want to learn Common Lisp over the winter break.

What book should I use? I already know OOP and I have some half a years experience with Haskell.
>>
This is a dumb question, but how do you actually send a program you made to somebody? I want to send my recent project to a friend, but he doesn't have a compiler or anything.

I've never actually had to send anybody an executable before.
>>
>>51769462
SICP
>>
>>51769473
Isn't that scheme, though?

From what I've heard scheme is functional programming oriented where as Common Lisp is multi paradigm.

I want Multiparadigm goodness.
>>
>>51769485
>I want Multiparadigm goodness.
D!
>>
Hey /g/, I was thinking about learning programming, my goal would be to learn C++, Java, and C#, I've done a little studying and find I enjoy making the programs, even when some might find it frustrating (like, constantly having errors, being a total nub, etc), and was wondering if I should start with C before I went into C++, or if I should start with Java, which I've heard is basically the same as C# besides a few things, and then go to C++?
>>
>>51769468
I've only sent them to my professor. Most people are too caught up in the buzz world to ever accept a file in general. One time I even pasted the source to a small little program that would read out whatever you typed into it and no one was willing to try it.
>>
File: 1434217243071.jpg (152 KB, 1031x882) Image search: [Google]
1434217243071.jpg
152 KB, 1031x882
>>51769485
SICP is a CS book that just happens to use scheme
plus scheme is a dialect of lisp anyway
just do it
>>
>>51769749
WIZARDRY
I
Z
A
R
D
R
Y
>>
>>51769508
Start with C++.

I'd skip Java for now, though. It's almost the same as C# in terms of usefulness but C# is a MUCH better language. Java's on the way out, anyway - it's not that useful these days for anything other than android apps.
>>
>>51769777
WIZARD DUBS
GET YOUR WANDS OUT
>>
>>51769789
>Java's on the way out, anyway

*hysterical laughter*

>it's not that useful these days for anything other than android apps.

You mean the largest and fastest growing app market?

*roaring cackles*
>>
>>51769789
is this post real
>>
>>51769797
C# is growing an order of magnitude faster than Java, and it's growing right into Java's market share.
>>
>>51769820
http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

>1: Java +6.01%
>5: C# -0.21%

Just leave the thread
>>
>>51769845
You win this round, javafag. But I'll be back. The C# storm cannot be stopped, and it WILL win. Maybe not today. Maybe not this month. Maybe not this year. But as the decades roll by, you'll see. You'll all see.
>>
>>51769327
I can relate to that.

>Sure, we have a webservice for that.
Okay.

>We only support SOAP.
Fine, where is the WSDL file for that service?

>What's a wizdul? I'll send you an example.
... thanks.

>A single endpoint that accepts another base64 encoded XML blob.
>XSD files in the example aren't even valid since all data types are missing.
>Fields such as name1, name2 ... name5 all over the place.
Goddamn Pajeets.
>>
Why is linux so fucking awful?
Ok, I get it, System.Management is awfully Windows specific in C#. Fine, I understand why Mono can't implement it. But I'm not gonna load in a third party library to find out what's happening with USB drives when I can do that in a few simple lines on a Windows system. So fuck Linux.

But it gets better. Guess what mono can't do?
Convert.ToInt32
In a string that is literally nothing but numbers, it still throws "System.Formatexception: Input string was not in a correct format"

How is linux so bad? how how how how
>>
>>51769964
So you're expecting something that was made specifically for Windows, then nigger ported to Linux to work flawlessly? Also just use Wireshark for monitoring USB data.
>>
>>51769964
>But it gets better. Guess what mono can't do?
>convert.ToInt32

You are literally retarded and have never used C# before.
string str = "13465464";
int i = int.Parse(str);
>>
File: 1328628540573.jpg (33 KB, 640x480) Image search: [Google]
1328628540573.jpg
33 KB, 640x480
>>51769964
>Why isn't Linux Windows?????
>>
>>51769964
Why use C# In Linux? That's a language made by Microsoft.

Windows is god awful to all programming with the exception of the .net platform.
>>
>>51769964
Filing this one under "user error"
>>
>>51769964
>not using haskell
>>>/trash/
>>
File: linuxsucks.png (3 KB, 289x88) Image search: [Google]
linuxsucks.png
3 KB, 289x88
>>51769985
>>51769996
>>51770008
>>51770013
I want my stuff to work without bullshit. Linux is a never ending stream of bullshit.

>>51769995
foreach (string s in splits)
ints.Add(Convert.ToInt32(s));

How could something fuck this up? It's the easiest of things.
>>
>>51770024
So why again are you trying to use Linux here?
>>
>>51770024
>I want my stuff to work without bullshit. Linux is a never ending stream of bullshit.
Comedy gold.
>>
>>51770031
I'm not making it for linux. I just wanted to see if the linux box I have could run even the simplest of simple programs.
It couldn't.
>>
File: ssl-added-and-removed-here.jpg (13 KB, 800x600) Image search: [Google]
ssl-added-and-removed-here.jpg
13 KB, 800x600
>>51769964
C# just isn't ready for cross-platform yet, anon.
>>
File: Untitled.png (5 KB, 413x164) Image search: [Google]
Untitled.png
5 KB, 413x164
Why is Windows so fucking awful? I just want to print the current GID and it won't let me to it. I want to my stuff to work without bullshit, Windows is a never ending stream of bullshit. It can't even compile the simplest of simple programs. How is Windows so bad? How, how, how, how?
>>
>>51770024
Convert.ToInt32 is just this:
if (value == null)
return 0;
return Int32.Parse (value);
>>
does anyone have experience with reverse engineering OSX programs? I'm doing a crackme for practice, and I got otool to output some assembly, but there's a function being called at an address that it's not showing. I couldn't get nm to show me what the function is either. How do I find this function?
>>
Is it possible to make a simple OS with C++?

I want a project to teach me how shitty I am at this.
>>
>>51770061
It's not, you're shit
>>
>>51770197
yes
>>
Is this encryption safe :^)
[CODE]
import java.io.UnsupportedEncodingException;

class XORCipher {
public static byte[] encrypt(byte[] toEncrypt, byte[] key) {
byte[] result = new byte[toEncrypt.length];
for (int i = 0; i < result.length; i++) {
result[i] = (byte)(toEncrypt[i] ^ key[i]);
}
return result;
}
public static byte[] decrypt(byte[] toDecrypt, byte[] key) {
byte[] result = new byte[toDecrypt.length];
for (int i = 0; i < result.length; i++) {
result[i] = (byte)(toDecrypt[i] ^ key[i]);
}
return result;
}
}

public class Main {
public Main() {}

public static void main(String[] args) {
try {
byte[] cryNSA = XORCipher.encrypt("Kek".getBytes(), "Key".getBytes());
System.out.println(new String(cryNSA, "UTF-8"));
byte[] tmp = XORCipher.decrypt(cryNSA, "Key".getBytes());
System.out.println(new String(tmp, "UTF-8"));
} catch (UnsupportedEncodingException e) {
System.out.println(e);
}
}
}

[/CODE]
>>
>>51770223
>java
No.

Not only is it unsafe, but someone could inject arbitrary code.
>>
I'm writing a specs program, did I find my way through dc well?

dc -e '[RAM: ]n'$(sysctl -n hw.physmem)d1048576/n'[MB]p'
>>
camelCase, UPPERCASE or lowercase?
>>
>>51770344
snake_case
>>
>>51770024
All you're doing is reinforcing the stereotype that Windows programmers don't know how to program. Stop.
>>
>>51770344
camelCase for members, TitleCase for types (including enums.) snake_case for standard library. SCREAMING_SNAKE_CAPS for preprocessor. I am a man of conventional tastes.
>>
>>51770391
10/10 absolutely traditional
>>
>>51770344
I like to write my programs like this:
void func(IlIlIlIl lIlIlIII) {
IlIlIlII lIlIlIII = new IlIlIlII();
for (IlIlIlII lIlIlIlll : lIlIlIII) {
lIlIlIII.add(lIlIlIlll);
}
}
>>
>>51770418
Is that i l or i i
>>
>>51770425
>using shit fonts
>>
>>51770444
The nice thing is that even if you use a font that shows the difference, it's still an eye-sore to figure out.
>>
>>51770444
>>51770454
If your I doesn't look like an l, your font is shit. It's supposed to.

t. English person
>>
>>51770024
>How could something fuck this up? It's the easiest of things.
Why don't you debug it it and find out? I'm pretty much 99.9% sure that one of those string is an incorrect format and that shit wouldn't run on windows either.

The problem has exactly nothing to do with linux either. Mono runs on most platforms. And it's probably not mono's fault, it's yours.
>>
anyone here do things like project euler (https://projecteuler.net/) or hackerrank(https://www.hackerrank.com/)?
>>
>>51770344
lisp-case
>>
>>51770770
>substract case from lisp
baka
>>
I have a inventory class called Inventory, which contains a list of an interface called IItem. I also have a class inheriting from IItem called TestItem. In Inventory I have a method to add an item to the Inventory which is a basic Add(IItem item), is it possible to add an nstance of TestItem through this method, without losing the properties of TestItem?

It's probably a stupid question that I should've been able to Google, but I can't figure out how to word it.
>>
>>51770850
I think you misunderstand interfaces. A list of IItem only ensures that all items contained have the same methods and values that IItem has implemented. Other than that it could be literally anything.
If you want to do that then make an abstract "Item" base class.
>>
>>51770545
the main page of project euler always sounded so pretentious to me i could never take it seriously, as if programming and math was something hard to take pride in for knowing it when in reality your average curry nigger can do this just fine
>>
>>51770850
>is it possible to add an nstance of TestItem through this method
yes

>without losing the properties of TestItem?
kinda
Since you're probably using java, use instanceof to determine whether item is TestItem or not, and then act based on that.
>>
>>51770943
In reality they can't do it, they know how to extend templates and that's about it. There's a reason for the stereotype of broken ass Indian software and tech support: their shit doesn't work properly or at best is full of security holes.
>>
>>51770845
(- lisp case)
>>
>>51770906
Thanks! This worked perfectly.

>>51770970
I am using C#, but previous answer got it working for me, thanks for the response.
>>
>write code
>coworker gets tasked with adding a feature to said code
>check it after a week
>managed to completely shit everything up
fuck you thomas
>>
>>51771097
Feels.
>set up nice architecture
>project is handed over to freelancer X
>X: "it felt too complicated so I ditched it"
>code duplication everywhere
>unmaintainable
>>
#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

int main()
{
int diceNumber;
int diceFaces;
char input;

cout << "Hello, welcome to the dice roller \n";
cout << "How many dice do you wish to roll?: ";
cin >> diceNumber;
cout << "You have chosen to roll " << diceNumber << " dices.";
cout << " How many faces do you wish your dice/dices to have?: ";
cin >> diceFaces;
cout << "Your dice/dices will have " << diceFaces << " faces. ";
cout << "Your final imput is " << diceNumber << "d" << diceFaces << "\n";
cout << "Rolling... \n";

for(int rolls = 1; rolls < (diceNumber + 1); rolls = rolls + 1)
{
srand(time(NULL)); // initialize the RNG
int result = rand() % (1 - (diceFaces + 1));
cout << "Your dice number "<< rolls << " rolls a " << result << "\n";
}

return 0;
}
>>
I'm trying to do a project with Visual Studio that requires other libraries (so it needs to use various .h and .lib files from these libraries). What's the best/de facto way of doing this? Right now, I have the library directories stored at the project root, and these contain include directories, lib directories, and so on. Then, in the project settings, I add the appropriate extra include directories and library directories relative to the project root. This seems messy.
>>
>>51771545
What if my dice has -1 faces?
>>
>>51771545
>CLI

when will this meme end?
>>
>>51771545
Please don't use the obsolete garbage that rand() is, use the random header instead which provides superior RNG, also the call doesn't initialize the RNG, it seeds it with current time (and since your loop will most likely run less than a second, the subsequent calls to srand() will have no effect, seed it with chrono).
>>
>>51771600
Anon, if anything GUI is the meme.
>>
>>51771600
>graphical user interfeces
>>
>>51771617
>gui
>meme
what the fuck am i reading
design and graphical shit is what sells these days, doesn't matter that it takes more time to design it than the actual functionality of the program
>>
Working on some shitty text editor. Decided to use C++ for whatever reason.

>>51769468
you put it on your website and link it to them as if it were any other program

don't embed it, no one is going to trust shit they downloaded in an email, and Gmail at the very least blocks .exe files if it detects them in a .zip
>>
>>51771662
>design and graphical shit is what sells these days
>he only thinks about what sells
>he only cares about shekels
>you can't do anything for fun
>you can't do anything for just learning purposes
>>
>>51771685
nice strawman faggot
>>
I'm putting elements into a C++ vector using push_back. vector.reserve has been called ahead of time to reserve memory for exactly as many elements as are going to be inserted.
Yet when calling push_back, the program halts with a malloc error, stating there's an incorrect checksum for the freed object, "object was probably modified after being freed".
I'm not manually allocating or freeing anything, and I haven't been able to find any useful on the subject. What do?
(Or does this go in /sqt/? If so, sorry.)
>>
File: h.jpg (54 KB, 714x629) Image search: [Google]
h.jpg
54 KB, 714x629
>trying to make a precompiled header work in CLion
>>
>>51771714
just post code
push_back will reallocate if the element to be added doesn't fit anyway
>>
File: thinking.jpg (587 KB, 900x900) Image search: [Google]
thinking.jpg
587 KB, 900x900
Can you make your own codding language with C++?
>>
Falling down the LINQ + Lambdas rabbit hole.

Help.

mod.Groups.Find(x => x.GroupName == "SomeGroup").Modules.Remove(mod.Groups.Find(x => x.GroupName == "SomeGroup").Modules.Find(x => x.ModuleName == "SomeModule"));
>>
>>51771743
>just post code
Last line here is where the error occurs, but these few lines probably won't tell you much.
void MatThreshold(cv::Mat& grayscale, Bitmap& bitmap, int threshold)
{
bitmap.reserve(grayscale.rows);
for (int y = 0; y < grayscale.rows; y++)
{
BitmapCol col;
col.reserve(grayscale.cols);
for (int x = 0; x < grayscale.cols; x++)
{
if ((int)grayscale.at<uchar>(y, x) <= threshold)
col.push_back(1);
else
col.push_back(0);
}
bitmap.push_back(col);
}
}

I've tried narrowing it down but can't seem to replicate it.
I reserve once rather than having push_back reallocate for every single element because the processed data can get pretty huge.
>>
>>51771762
yes that's what im doing right now
>>
>>51768129
Is home the official mascot of /dpt/ now?
Why?
>>
>>51771771
>>51771743
I should mention:
typedef std::vector<int> BitmapCol;
typedef std::vector<BitmapCol> Bitmap;
>>
>>51771775
Hime. Phone autocorrected
>>
What do you listen to while devving, /dpt/?
>>
>>51771762
Writing a compiler with C or C++ is asking for trouble
>>
>>51771771
are you multithreading?
>>
>>51771775
I hear it's some retarded mod deleting any non-trap /dtp/ threads. For free, etc.
>>
>>51771878
The UI runs in a separate thread, but I don't have much control over it. (Qt 5 UI.)
>>
Working my way through "learn python the hard way" because I don't know to code and why not
>>
>>51771841
>C++ is asking for trouble

the state of art compilers are written in c++

gcc
g++
llvm
clang
ms cl
v8
js (firefox)
>>
>>51771939
>learn python the hard way

Why anon, why ? (屮゜Д゜)屮
>>
hi in my local uni SE course in OOP they teach us to access object data by creating methods such as
public int getData()
return data;
instead of simply making it public
is it retarded or is the way to go because to me it looks simply a waste of time
>>
File: HntlKcy.jpg (56 KB, 599x607) Image search: [Google]
HntlKcy.jpg
56 KB, 599x607
>>51772027
it's the _ONLY_ way to go.
>>
>>51771968
Funny thing is, Swift compiler is written in C++.
>>
File: SendHelp.png (165 KB, 1280x1600) Image search: [Google]
SendHelp.png
165 KB, 1280x1600
This is suffering, but I'm doing this to accomplish my dreams.
>>
>>51770418
this triggers my autism
>>
>>51772027
Getters/setters are useful when enforcing thread safety. It is also useful for making your API future proof. Maybe getData returns another value than data under certain conditions.
>>
>>51770418
calm down satan.
>>
hi, café guy here

any remarks tips or things you would do differently.

package Model;

import java.util.Iterator;
import java.util.TreeSet;

public class Order implements Comparable<Order> {

private TreeSet<Orderline> orderlines = new TreeSet<>();
private boolean isPaid = false;

public Order() {
}

public boolean addOrderLine(Orderline ol){
if(orderlines.contains(ol)){
Iterator<Orderline> iter = orderlines.iterator();
Orderline temp;
while(iter.hasNext()){
temp = iter.next();
if(temp.equals(ol)){
temp.setAmount(temp.getAmount()+ol.getAmount());
}
}
}
return orderlines.add(ol);
}

public double calculateTotal(TreeSet<Orderline> orderlines){
double total = 0;
for(Orderline o: orderlines){
total = total + o.calculateSubTotal();
}
return total;
}

public TreeSet<Orderline> getOrderlines() {
return orderlines;
}

public void setOrderlines(TreeSet<Orderline> orderlines) {
this.orderlines = orderlines;
}

public void payOrder(){
setPaid(true);
}

public boolean isPaid() {
return isPaid;
}

public void setPaid(boolean isPaid) {
this.isPaid = isPaid;
}

@Override
public int compareTo(Order o) {
return 0;
}

public char[] calculateTotal(Order o1) {
// TODO Auto-generated method stub
return null;
}


//last updated 9-12-15



}
>>
>>51772197
Implement the last 2 methods or throw an UnsupportedOperationException.
>>
>>51772113
C++ isn't suffering -- if you do it right.

C++ is like a nicely paved yellow brick road. If you stay on the road, you get to where you want quickly and with flowers and dancing. If you step off the road, you get raped by black ex-convicts who lust for juicy boipussy, and who will rape your ass until you too lust for their engorged black cocks.
>>
intelIJ, netbeans or eclipse.
>>
>>51772130
>missing the most important point
lel, you oop or you not oop, amiright ?
>>
>>51772166
>>51772120
Just ensuring job security
>>
>>51772243
>fuck open source

do you work at apollo or something
>>
>>51772130
>how are we going to do thread safety?
>we should implement const like in C or C++
>nah bro just put a mutex in every getter and setter
>>
>tfw you start putting semicolons at the end of your sentences;
>>
>>51772306
>>>/reddit/
faggot
>>
>>51772306
us = coders amirite xD;
>>
>>51772027
Getters/setters are a meme. It's only useful when you're checking for invalid values or want to perform some actions after something is set/get

If your code looks like this why even bother. I cringe every time i see it.
void SetFuu(int fuu) 
{
m_Fuu = fuu;
}

int GetFuu()
{
return m_Fuu;
}
>>
File: brainf.png (11 KB, 578x52) Image search: [Google]
brainf.png
11 KB, 578x52
I just wrote a Brainfuck Interpreter in Rust
>>
>>51772113
I don't understand why people who don't enjoy programming force themselves into it.
>>
>>51772364
>writing joke language interpreter in a joke language because being javascript hipster wasn't enough
>>
File: 161017757_44042348.jpg (67 KB, 590x632) Image search: [Google]
161017757_44042348.jpg
67 KB, 590x632
>>51772355
>being this ignorant
lel
>>
>>51772405
>being this much of a JIDF
>>
>>51772355
There's another reason to implement a getter/setter. When setting m_Fuu you could notify all listeners that the value has changed. Qts property system works like that.
>>
>>51772434
>If your code looks like this
>>
After reading some books I think I'm ready for some basic C++ things to do as a practice.

What would you guys recommend? I already did the exercises from the book, but it didn't have a "Let's mash everything we learnt so far together" exercise. What kind of exercise do you guys think would help me get all the basics of C++ together?
>>
>>51772405
>Get a new intern
>boss tells me to take care of him
>explain everything and give him something easy to do
>Leave him alone and come back after a while to check
>Ask him to show what he did
>"Oh I just finished writing all my getters and setters for my classes anon senpai"

He just wasted an hour writing getters and setters for several classes that could have just been public.


>>51772434
Read again.
>>
File: Knipsel.png (83 KB, 643x679) Image search: [Google]
Knipsel.png
83 KB, 643x679
Where we at senpai?
>>
>>51772526
kanker
>>
>>51772536
Neger, alsjeblieft.
>>
File: Untitled.png (52 KB, 736x336) Image search: [Google]
Untitled.png
52 KB, 736x336
>>51772526
>>
File: 1439050547043.jpg (164 KB, 620x877) Image search: [Google]
1439050547043.jpg
164 KB, 620x877
ready to suck cutie anons? pic related
>>
>>51772536
>>51772551
hang jezelf
>>
Is it bad to throw std::runtime_error, or should you create your own exception (hiararchy)?
>>
>>51772501
DON'T TELL ME WHAT TO DO FAGGOT. I ONLY READ WHAT I WANT TO READ.
>>
>>51768129
FAAAAAAAAAAAGOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOT
>>
>>51772572
>I ONLY READ
ONLY FAGGOTS READ
>>
WHY ARE WE SHOUTING????!!!
>>
>>51772593
WHY NOT?
>>
>>51772565
>Is it bad to throw <exception>
Yes
>>
>>51772577
>>51772585

>implying traps are faggots
>>
What's the difference between a lexer and a tokenizer?
>>
>>51772649
Nothing
>>
>>51772654
So they're just two different names for the same thing?
>>
>>51771662
>thinks memes aren't selling points

wtf am i reading
>>
>>51772665
Pretty much

I suppose you could have a lexer that's not strictly a tokenizer, like if you were lexing into S-expressions that are then parsed
>>
>>51772501
>ctrl + enter on class name
>select "generate getters and setters"
plebs, I swear...
>>
I'm looking for a Golang book to read over Christmas break. Is the new Kernighan one good or is there a more recommended one?
>>
>>51772931
>Golang

http://qr.ae/drvVS
http://qr.ae/drvm8
http://yager.io/programming/go.html
http://nomad.so/2015/03/why-gos-design-is-a-disservice-to-intelligent-programmers/
http://java.dzone.com/news/i-don%E2%80%99t-much-get-go
http://dtrace.org/blogs/wesolows/2014/12/29/golang-is-trash/
http://www.lessonsoffailure.com/software/google-go-not-getting-us-anywhere/
http://www.lessonsoffailure.com/software/googles-go-not-getting-us-anywhere-part-2/
http://www.lessonsoffailure.com/software/google-go-good-for-nothing/
https://gist.github.com/kachayev/21e7fe149bc5ae0bd878
>>
>>51772931
>meme book
>>
Is kivy good choice if I want to make GUI for programs that I intend to run on mobile and pc?
Not really concerned about performance, it will be used just to make shitty scripts to have buttons.
>>
>>51773121
never heard of it. Maybe, depending on what you're doing.

In my experience HTML5 is the best cross platform solution for UI across desktop and and mobile platforms. It's a shitshow in some ways, but everything else is worse.

If you want quality, then use Xamarin and mvvm, and code the UI separately and natively for each platform, then share all non UI logic.
>>
How would you guys make something like this shorter? This is how a typical code of mine looks and I have to admit it looks fugly.

#include <iostream>
using namespace std;

//Main
int main()
{
//Variables
char answer;
bool correct = false;

//Clear screen
cout << string(50, '\n');
// Welcome sign
cout << "BLABLABLABLABLA SUPER FUCKING SHITTY TITLE HERE";
// Spaces because Autism
cout << "\n" << "\n" << "\n";
//Cout telling the possible answers
cout << "BLABLABLABLA CHOOSE A, B, C OR D:\n" << "A) ANSWER1\n" << "B) ANSWER2\n" << "C) ANSWER3\n" << "D) ANSWER4\n";
// While loop until answer is correct
while(correct = true)
{
cout << "Insert your input here: ";
cin >> answer;

if(answer == 'A' || answer == 'a')
{
cout << "INCORRECT \n \n";
}
else if(answer == 'B' || answer == 'b')
{
cout << "CORRECT. \n \n";
break;
}
else if(answer == 'C' || answer == 'c')
{
cout << "INCORRECT \n \n";
}
else if (answer == 'D' || answer == 'd')
{
cout << "INCORRECT \n \n";
}
}



return 0;
}
>>
>>51773278

Fugg, I forgot to add the "else"

        else
{
count << "INVALID INPUT \n \n";
}
>>
Lambda expressions.

;3
>>
that feel when got a job thanks to /dpt/
t-thanks guys
>>
>>51773319
>count
FUCK

cout*
>>
>>51772931
Haven't bothered to read the book yet much outside of the first chapter they put up online before official release, it seems really well done. Coming from a Go programmer.
>>
  int tryit(int i)
{
if (i > 0)
return tryit(i-1) * j + k;
else
return 1;
}



i = 3
j = 4
k = 1
x = tryit(i);

Could some one help me understand this recursive function and how to get the right answer from it?
>>
What is your dream, /dpt/?
>>
>>51773358
Hey congrats man!
>>
>>51773430
well what the heck IS the right answer?
>>
>>51773469
The right answer should be 85. I think my problem is understanding how recursion works.
>>
>>51773278
https://ideone.com/6JjCMx
>>
File: 1346000269377.png (6 KB, 281x215) Image search: [Google]
1346000269377.png
6 KB, 281x215
I'm working on a homework assignment for a Binary tree, and I can't figure this shit out.

BinaryTree<std::string> *treeRoot = new BinaryTree<std::string>("root");
BinaryTree<std::string> *currentPtr = treeRoot;
*currentPtr = currentPtr->getLeftSubtree();
treeRoot->setRootData("left sub");
std::cout << treeRoot->getRootData() << std::endl;
std::cout << currentPtr->getRootData() << std::endl;

/* Output:
left sub
left sub
*/


Why is it changing the value of the node that currentPtr is on changes the node the treeRoot is on? Am I not using pointers right?
>>
>>51773494
I would recommend reading "The Little Schemer"
it's super easy to get recursion with the book
>>
>>51773554
Thanks. I'll for the book. I am trying to study for a test so I don't really have time to work through it.

I know the first time you use the function It would be returning 9. But what happens to the 9? How does the 9 become part of the final answer of 85.
>>
>>51773440
To run my own software company and to not be a total autist. The first one is at least possible.
>>
>>51773440
I once had a dream to work as a programmer and be surrounded by like-minded, intelligent people, but nowadays I just feel disillusioned and lost.
>>
>>51773648
just write it out on paper
>>
>>51773509
What is setRootData doing? What if you just output the memory address?
>>
>>51773494

so let's take a function f
f calls itself with it's own parameter -1, but contains a base case for when the iterative parameter reaches 0.
f(int i){
if(i>0){
return f(i-1)
}else{
return 1
}


this means that when f is executed, we see the output of the function being fed into the function all the way back up to the original call.
f(4)<-f(3)<-f(2)<-f(1)<-f(0)

Given that f contains a base case for 0, we can start to calculate the result.
f(4)<-f(3)<-f(2)<-f(1)<-1
f(4)<-f(3)<-f(2)<-1
f(4)<-f(3)<-1
f(4)<-1
1

Obviously for our function f, we're not doing anything with the value returned.
Let's take g then, g being:
g(int i){
if(i>0){
return g(i-1)+1
}else{
return 1
}

The key difference here being that we add 1 in each call.
So we get
g(4)<-g(3)<-g(2)<-g(1)<-g(0)
g(4)<-g(3)<-g(2)<-g(1)<-1
g(4)<-g(3)<-g(2)<-2
g(4)<-g(3)<-3
g(4)<-4
5

So instead of receiving 1, we receive (((((1)+1)+1)+1)+1) = 4, or rather, since we add 1 for each value in the iterator; that is i times, we have 1+4*i. Obviously, simply multiplying isn't the most effective use of functional programming, and many things can be done.

So take
int tryit(int i){
if (i > 0){
return tryit(i-1) * j + k;
}else{
return 1;
}
}


If we work this out like previously, we have
tryit(3)<-tryit(2)<-tryit(1)<-tryit(0)
tryit(3)<-tryit(2)<-tryit(1)<-1
tryit(3)<-tryit(2)<-5
tryit(3)<-21
85

obviously, this isn't the clearest, so let's write in what the function is really doing
k+j*(  k+j*(  k+j*(  1 )))
k+j*( k+j*( 5))
k+j*( 21)
85


clearly using this method, many more complicated things can be done, such as not using a linear iterator, other methods of ending this stack of functions, but the principle remains.

Hope I helped.
>>
>>51773430
if those are the numbers you plug into it...
{ 
i = 3
3 > 0
tryit( 3 - 1 ) * j + k
} // This becomes the repeated process
becomes
{
i = 2 // this is i in this function
2 > 0
tryit( 2 - 1 ) * j + k
}
becomes
{
i = 1
1 > 0
tryit( 1 - 1 ) * j + k
}
becomes
}
i = 0
0 !> 0
tryit(0)
}
since 0 !> 0 you return 1 and you move backwards in the call order
1 * 4 + 1 = 5 // for i = 1
// ^ this might confuse you but it's correct.
// the mention of i inside the function is a
// different one you're "in" it
5 * 4 + 1 = 21 // for i = 2
21 * 4 + 1 = 85 // for i = 3
x = 85


I think. I've been up a while.
>>
>>51773430
int tryit(int i){
if (i > 0)
return tryit(i-1) * j + k;
else
return 1;
}

x = tryit(i)
//x = tryit(3)
// == tryit(3-1) * j + k == tryit(2) * 4 + 1
// == (tryit(2-1) * 4 + 1) * 4 + 1 == tryit(1) * 4 + 1) * 4 + 1
// == ((tryit(1-1) * 4 + 1) * 4 + 1) * 4 + 1
// == ((1 * 4 + 1) * 4 + 1) * 4 + 1
// == 85
>>
>>51773748
Each part of the binary tree has the root pointer data (the current value of the node), the left tree pointer and right tree pointer. setRootData changes the value of the data. I changed my code and got this ouput:

    std::cout << &treeRoot << " = " << treeRoot->getRootData() << " / " << &treeRoot->getRootData() << std::endl;
std::cout << &currentPtr << " = " << currentPtr->getRootData() << " / " << &currentPtr->getRootData() << std::endl;

/*
OUTPUT:

00FAFD94 = left sub / 00FAFBC0
00FAFD88 = left sub / 00FAFC08
*/


Here is the function for setRootData

template<class ItemType>
void BinaryTree<ItemType>::setRootData(const ItemType& newItem)
{
if (pItem != nullptr)
*pItem = newItem;
else
{
pItem = new ItemType(newItem);
leftSubtreePtr = rightSubtreePtr = nullptr;
subtree = false;
}
};
>>
>>51773509
You are assigning root to current pointer. Try assigning currentPtr first and assign those contents to the tree root.
BinaryTree<std::string> *currentPtr = new BinaryTree<std::string>("root");
BinaryTree<std::string> *treeRoot = currentPtr;
*currentPtr = currentPtr->getLeftSubtree();
currentPtr->setRootData("left sub");
std::cout << treeRoot->getRootData() << std::endl;
std::cout << currentPtr->getRootData() << std::endl;


What you're doing when you assign these variables is creating a path and then throwing the bread crumbs backwards. You inch forward through the scheme by moving with currentPtr and then assigning that to be your root, and then using the properties of the root to extend your location using the currentPtr.

Think of it like rock climbing. You reach out and grab on to some rock, and then pull yourself up. After that, you reach out using a stable position, and if you find more rock you pull yourself up and thus have changed your current position.

Make sense?
>>
>>51773780
>>51773790
>>51773816
Thanks you all have been extremely helpful.
>>
>>51773790
Oops, sorry about that last part with i = 0. There shouldn't be a tryit( 0 ). It should just look like this:
{
i = 0
0 !> 0
return 1
}
>>
>>51769845
> It is important to note that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.
>most lines

oh, right.
>>
>>51773899
Makes sense...but doing that didn't work. I've done pointers before and the order of they're initialized didn't seem to matter.
>>
how are you so skillfull in programming /g/. Is it your autism?
>>
>>51773857
It might help to think of it like highlight all and then copy paste

Maybe cut and paste might make more sense but for that you have to consider the difference between cut and copy as the difference between what an address assignment is and what a pointer assignment is.
>>
what does it take to become a big data developer?
>>
>>51774080
Be a big developer.
>>
>>51772931
No real need for a book. Go through the official tutorial and you're good to start exploring libraries and actually writing something. It's helpful to have a senpai though.
>>
>>51774038
oops, try dereferencing the assignment in the second line:
BinaryTree<std::string> *treeRoot = *currentPtr;

This way the treeRoot pointer gets assigned the contents of tree root as a value and doesn't just get the original reference. Otherwise, you simply added a back up file that is constantly updating.
>>
>>51774124
the contents of currentPtr*

ugh sorry
>>
Okay, I'm really new to C++, so I probably made an awful mistake and I'm too stupid to notice it. What am I missing here? Aren't the functions supposed to work? I recently started reading about functions and such, so I might have misunderstood it.

(The code is probably anything but tidy and is probably really fucking bad for C++ standards)

#include <iostream>
using namespace std;

void add()
{
int firstNumber;
int secondNumber;
int result;

cout << "\nPlease choose your first number: ";
cin >> firstNumber;
cout << "\nPlease choose your second number: ";
cin >> secondNumber;
result = firstNumber + secondNumber;
cout << "\nYour result is: " << result << ".\n";

}

void choices()
{
//Variables
int userInput;
while(true)
{
//Selection text and input
cout << "\nEnter a selection, please: ";
cin >> userInput;

//User Input reader
if(userInput == 1)
{
cout << "Your choice is: ADD\n";
void add();
}

else if(userInput == 2)
{
cout << "Your choice is: SUBTRACT\n";
break;
}

else if(userInput == 3)
{
cout << "Your choice is: MULTIPLY\n";
break;
}

else if(userInput == 4)
{
cout << "Your choice is: DIVIDE\n";
break;
}

else if(userInput == 5)
{
cout << "Your choice is: RAISE X TO THE POWER OF Y\n";
break;
}

else if(userInput == 0)
{
break;
}

else
{
cout << "INVALID INPUT\n";
}
}
}

//Main
int main()
{

//Menu
cout << "\033[2J\033[1;1H";
cout << "---------------------------------- \n";
cout << "* 1 - Add * \n";
cout << "* 2 - Subtract * \n";
cout << "* 3 - Multply * \n";
cout << "* 4 - Divide * \n";
cout << "* 5 - Raise X to the power Y * \n";
cout << "* * \n";
cout << "* 0 - Quit * \n";
cout << "---------------------------------- \n";

void choices();
}
>>
>>51774166
I'm a noob, but isn't declaring a variable type inside the for arguments breaking the C11 standard?
>>
Shloud I have the first else statement to the continue instead of the if (bag.items[i] != the_item) ?
void RemoveItemFromBag(Items the_item)
{
if (IsBagEmpty() == false)
{
for (int i = MAX_ITEMS; i >= 0; i--)
{
if (bag.items[i] != the_item)
{
continue; // skip to the next slot down in the bag
}
else
{
bag.items[i] = None;
bag.size--;
return;
}
}
}
else
{
printf("Bag is empty!\n");
return;
}
}
>>
>>51774166
Tell us what is broken.
>>
>>51774219
When I run it it only runs the main function and ignores the others.
>>
>>51774240
// wrong
void add();
// right
add();

Don't add the return type when calling the function.
>>
>>51774240
w...well...
>>
>>51774166
What the other anon said, tell us what it outputs with some examples. Sucks to read through all of it to understand what it does.

I can tell you that the problem is in these lines. Think about function declarations and calling functions.

 //User Input reader
if(userInput == 1)
{
cout << "Your choice is: ADD\n";
void add();
}
>>
>>51774254
>>51774249

Based.

Sorry for the retarded question. It works now.
>>
>>51768129
How did I do /g/?
#include <iostream>
using namespace std;

int main(){
char o = 72, l = 101, f = 108, t = 117, w = 111, h = 87, s = 36*3, d = 114, r = 100, x = 13, a = 32, c = x-1+100, MaX = 10*10/2-40;
int MAX = 17/2-8, MIN = 77/77, i = 11+2; char IOStream[] = {o, l, f, s, w, a, h, w, d, f, r, MaX, x};
while (MAX < MIN-1+i){cout << IOStream[MAX];MAX = MAX + 1;} MAX = 1/1-2+1;
system("pause");
return MAX;
}
>>
>>51774193
meant for
>>51771545
>>
File: 1436550309041.png (491 KB, 724x674) Image search: [Google]
1436550309041.png
491 KB, 724x674
Why do you guys keep learning horrible programming languages like c, c++, or java when you have powerful and expressive programming languages like lisp or haskell ? (honest question).
>>
>>51771841
>>51771968
Hotspot(oracle's JVM) as well
Thread replies: 255
Thread images: 30

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.