[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: 33
File: 1456075074460.jpg (60 KB, 627x627) Image search: [Google]
1456075074460.jpg
60 KB, 627x627
Previous thread: >>54066467

What are you working on, /g/?
>>
>>54074473
>>>/pol/
>>
File: recursion kills.jpg (113 KB, 638x493) Image search: [Google]
recursion kills.jpg
113 KB, 638x493
Keep overflowing the stack, Hime!
>>
so I have this code:

char buffer[MAXMSGLENGTH];
char message[MAXMSGLENGTH];
char *addr = "127.0.0.1";
int port = 7000;
int ADDRESSFLAG, PORTFLAG, sockfd, maxfd, nready;
fd_set readfds;

//initialization stuff
FD_ZERO(&readfds);
FD_SET(STDIN_FILENO, &readfds);
FD_SET(sockfd, &readfds);
maxfd = sockfd;

while(1) {
nready = select(maxfd + 1, &readfds, NULL, NULL, NULL);

//if the user typed a message
if(FD_ISSET(STDIN_FILENO, &readfds)) {
printf("sending message...\n");
if(read_message(STDIN_FILENO, message) < 0) {
log_out(sockfd);
die("STDIN closed, exiting\n");
}
if(send_message(sockfd, message) < 0) {
log_out(sockfd);
die("Server closed connection, exiting\n");
}
printf("message sent.\n");
if(--nready <= 0) { continue; }
}
//if the server has sent us a message
if(FD_ISSET(sockfd, &readfds)) {
if(read_message(sockfd, buffer) == 0) {
//don't print a message we sent
//if(strcmp(message, buffer) != 0) { printf("%s\n", buffer); }
printf("message received.\n");
if(--nready <= 0) { continue; }
}

}
}


but FD_ISSET(STDIN_FILENO, &readfds) never returns true even if I type something in and hit enter. What could be the cause?
>>
File: 1442758241336.jpg (182 KB, 978x655) Image search: [Google]
1442758241336.jpg
182 KB, 978x655
>>54074487
if anything, this is the garbage that should get deleted
>>
Get raped and kill yourself, you retarded fucking faggot sack of shit with down syndrome.
>>
File: 91i328.jpg (142 KB, 740x740) Image search: [Google]
91i328.jpg
142 KB, 740x740
>>54074493
>C
>>
>>54074487
Keep overflowing the stack, Hime!
>>
Without Indians, American programming will collapse
>>
>>54074520
indeed. americans are so retarded that even indians do a better job programming.
>>
C# best languagefu
>>
>>54074486
>>54074520
>>>/trash/
>>
Reminder that when we say we hate newfags, webfags, tripfags, javafags, snekfags and literal fags, and want them to fucking leave, we aren't fucking joking
>>
>>54074537
and Cfags and FPfags
>>
>>54074558
Newfag/webfag/tripfag/snekfag/literal fag detected
>>
>>54074514
C's nice, don't be a pleb
>>
>>54074571
It's not very cute or concise
>>
>>54074570
FP is literally shit, just a short-lived fad that a few clueless neckbeards fell for
>>
>>54074565
Makifags are /a/ rejects trying to force a meme
>>
>>54074493
You haven't initialised sockfd, is that voluntary? My guess would be that it fucks up fdmax in the current state of affairs of what you posted... more generally, try writing a program that only selects on stdin by altering this one and see if it narrows down
>>
>>
>>54074601
doesn't answer the question
>>
Maki is for those with taste. Shit waifus like lain and holo is for newfags who fell for memes.
>>
>>54074565
yes

>muh animu
>literally who animu character
>>
>>54074608
it's done in my initialization code I omitted it so it wouldn't be too long to post.

The socket get initialized properly and the server acknowledges the connection. but typing something in stdin does nothing,
>>
>>54074671
Kill yourself newfag, maki is part of /g/ culture
>>
File: MAKI.jpg (52 KB, 440x567) Image search: [Google]
MAKI.jpg
52 KB, 440x567
>>54074565
friendly reminder that idolfags are literally the bronies of anime
>>
File: suicide.jpg (18 KB, 480x471) Image search: [Google]
suicide.jpg
18 KB, 480x471
Am I wrong?
https://github.com/i3/i3/pull/2303
>>
>>54074537
Fuck off retard.
>>
>>54074701
Kill yourself newfag
>>
>>54074608
>>54074676
it actually wasn't too long I'm just blind, here's the whole thing. The helper functions I wrote work, I tested them independently

char buffer[MAXMSGLENGTH];
char message[MAXMSGLENGTH];
char *addr = "127.0.0.1";
int port = 7000;
int ADDRESSFLAG, PORTFLAG, sockfd, maxfd, nready;
fd_set readfds;

//command line arg reading

if((sockfd = connect_to_server(addr, port)) < 0) {
die("");
}

FD_ZERO(&readfds);
FD_SET(STDIN_FILENO, &readfds);
FD_SET(sockfd, &readfds);
maxfd = sockfd;

while(1) {
nready = select(maxfd + 1, &readfds, NULL, NULL, NULL);

//if the user typed a message
if(FD_ISSET(STDIN_FILENO, &readfds)) {
printf("sending message...\n");
if(read_message(STDIN_FILENO, message) < 0) {
log_out(sockfd);
die("STDIN closed, exiting\n");
}
if(send_message(sockfd, message) < 0) {
log_out(sockfd);
die("Server closed connection, exiting\n");
}
printf("message sent.\n");
if(--nready <= 0) { continue; }
}
//if the server has sent us a message
if(FD_ISSET(sockfd, &readfds)) {
if(read_message(sockfd, buffer) == 0) {
//don't print a message we sent
//if(strcmp(message, buffer) != 0) { printf("%s\n", buffer); }
printf("message received.\n");
if(--nready <= 0) { continue; }
}

}
}
>>
>>54074719
Get out
>>
File: chaika1.jpg (83 KB, 487x460) Image search: [Google]
chaika1.jpg
83 KB, 487x460
is this the anime discussion thread?
>>
>>54074711
>https://github.com/i3/i3/pull/2303

You expect people in CURRENT_YEAR to care about optimization?

I wish you the best of luck in that, everyone would rather be lazy
>>
>>54074744
ye

feel when no programmer trap anime bf
>>
>programming
>chinese cartoon girls

what's the connection
>>
>>54074744
>not maki or any of the id@l girls
>>
>>54074693
since fucking when
>>
>>54074784
>shit girls
>>
>>54074773
/g/ is where you pretend to be a programmer
>>
>>54074787
It's a forced meme, along with akari and that pink haired C programmer trap.
>>
>>54074773
neckbeards
>>
Implementing a R7RS scheme on top of the python ast, with interop between python and scheme.
>>
maki is a disgusting cum slut
>>
>>54074809
the silliest thing i've read all day
>>
File: browser #112.png (2 MB, 1680x1050) Image search: [Google]
browser #112.png
2 MB, 1680x1050
pretend programmer comin thru.

all of this can soon be yours for the very low price of your freedom!
>>
>>54074787
Last year, /g/ has accepted maki.

>>54074802
Fag
>>
>>54074826
gpl2 or i kill ymsefl
>>
>>54074823
meh, why?
>>
File: 6213690.gif (135 KB, 500x254) Image search: [Google]
6213690.gif
135 KB, 500x254
>>54074821
>>
i started watching love live just for maki
i have never seen an anime before

its ok
>>
File: c23.jpg (11 KB, 234x250) Image search: [Google]
c23.jpg
11 KB, 234x250
>>54074758
I did it for them, all they had to do is merge.
>>
>>54074821
You take that back. She's the queen of /g/, many people worship her, including me.
>>
>>54074857
Is maki even a regular character?
I would imagine an idol show has just 2 or 3 girls hogging all the screen time, but then again i've never watched idol anime before.
>>
>>54074862
>>54074862
>all they had to do is merge

That would mean they'd have to admit they did something wrong and you did something right.

MUH PRIDE MORE IMPORTANT
>>
>>54074857
Watch it again. If you can't figure out why love live and maki is amazing, maybe naruto is more suitable for you.
>>
>>54074885
its always cute girls doing cute things
the ep just gets better when maki is in there
>>
>>54074493
god i hate 1970's style C
>>
>>54074893
All I'm asking if I am wrong or not.
>>
>>54074711
you may not be wrong but you come across as a whining autist and I'm inclined to agree that the millisecond of optimization is not worth it.

can you prove in any way the current code is bottlenecked by a measurable amount because of that?
>>
File: OH MY GOD.jpg (67 KB, 1280x720) Image search: [Google]
OH MY GOD.jpg
67 KB, 1280x720
>>54074857
>I've never seen an anime before
>>
>>54074711
>>54074862
I'd reject your pull request too.
>titled: "REMOVED USELESS CODE"
>optimizing some non-essential setup wizard that will run exactly once

You're basically no better than those "women coders" whose entire git history consists of pull requests fixing punctuation and adding "code of conducts".
Your contribution was useless and insulting.
>>
>>54074880
I hope you're okay worshiping a whore
>>
>>54074907
this is what they taught me in school, what's wrong with it? I'm still new to this c business.
>>
>>54074897
What is the appeal of idol anime?
All the music is generic and unmemorable and their production companies are pretty shameless about milking their franchises for everything they're worth.
Just look at idolm@ster, it's been running for over 10 years with the same cast and their seiyuus are all christmas cakes now
>>
>>54074934
b-b-but muh speed mufugguh
>>
>>54074880
shut up fag
>>
>>54074711
personally i use sizeof - 1 but it's not very significant and strlen is arguably more readable
>>
>>54074957
It's not 1970 anymore, you can mix code and variable declarations.

You can also declare variables right before they're needed so you don't end up with unreadable garbage.
>>
>>54074966
maki is the appeal
>>
>>54074711
yes you are wrong. this reeks of premature optimization, and 'look at how smart i am' smugness changes that have 0 impact on the final product.
>>
>>54074986
that doesn't seem like a valid criticism but ok
>>
>>54074926
It's not about optimization, it's about readability, it's idiotic to call strlen on string literals.
>>54074934
Just a minor clean up that should just be merged without much talk. But after that discussion, I'm thinking I don't care to contribute further, or use i3 in general.
>>
>>54074711
your change was garbage and you talked like a stuck up neet autist
>>
>>54074984
I don't think it is readable though, because when I read strlen, I read:
>function call that contains a loop
But they are using it, counting on the compiler to change it to something different. So basically, strlen means different things in different parts of the code.
>>
Can I write javashit without using an IDE?
Can I write javashit for Android without using an IDE?
>>
>>54075041
>MUH SPEED
Wow dude, it's a fucking setup wizard. It's never going to run on your machine again.
And you come off as pretentious and annoying.
I'm glad you got shot down.
Don't contribute to any more projects ever again.
>>
>>54075041
>it's about readability, it's idiotic to call strlen on string literals
now you are just being wrong, and boneheaded.

sizeof() is for the size of a certain variable or struct. now, i'm guessing (haven't got a copy of the standard nearby) that C guarantees sizeof(char) to be 1, but how many people know this? also, the point of this code is to get the length of the string literal. what happens if
...
sizeof("string literal")
...

later gets changed to
const char* literal = "string literal";
...
sizeof(literal)
...

now the code breaks, and shit gets fucked up, all because you want to save a couple microseconds on a 1-time setup wizard.

actually no, because you want to publicly show how clever you are and how much you know about C. that's the real reason why you're making this pull request.

faggot.
>>
>>54075072
I would not have minded if they just said the change was worthless. What they said was that they are right, and tried to send stackoverflow links to prove it.
>>
>>54074711
>I was going to give you links that prove my point, but you did it for me.
this isn't 4chan kiddo, you don't get to act like a prick without repercussions
>>
>>54075068
get over it, the strings aren't even long
>>
>>54075101
Anon, they told you 2 things:
>the change is worthless
>they are right and you are wrong

Your change was stupid.
Never worry about optimization in a fucking C program unless that function is going to be called hundreds of millions of times per second.
>>
>>54075094
Sorry, but not true, and were you to research more, you'd find you are not supposed to declare a variable in that fashion, but rather "const char literal[]"
I did the pull request, because I was looking for a specific fix of a bug I had encountered, while doing so, I saw code I deemed bad, that is all
>>
Tried to optimize my code by replacing pow(2,n) with 1 << n. Strangely, this increased runtime by 9 ms.
>>
>>54075136
>you are not supposed to declare a variable in that fashion, but rather "const char literal[]"
gunna need a fucking citation on that one, buddy.

i see "const char* string = "blah"" all over the fucking place.
>>
/dpt/ help

#include "PlayerClass.h"

class Player {
public:
PlayerClass k;
int l;
Player(PlayerClass klasse, int level) : k{klasse}, l{level} {};
}


Player.h:12:1: error: expected ';' after class definition
}
^

and when I put the ; it says
Player.h:12:2: error: multiple types in one declaration
};
^

what is wrong with my shitty class?
>>
>>54075141
function call
>>
>>54075141
try 1U << n with n being unsigned
>>
>>54075141
on modern processors, arithmetic and floating point math runs several times faster than "traditional" bit math like bitshifts and XOR swaps.
>>
>>54075159
or branching

>>54075157
use (s not {s in the initializer
>>
>>54075110
Oh, feeling the repercussions so hard...
>>54075123
Ok, the other pull request they closed was on a protocol that is called in a tight loop, they closed it referencing the config wizard one...
>>
>>54075141
show us the surrounding code.

also, how are you benchmarking? might be an issue with timing/measurement.

also, this is a dumb optimization that the compiler probably already made for you.
>>
>>54075161
oh yeah you need to balance your workload like don't use only bitshifts
>>
>>54075141
are you casting 1 << n to float/double?
>>
>>54075161
>floating point runs faster than bitwise ops
pure, unadulterated horseshit
>>
>>54075156
Just how I learned, sorry.
>>
>>54075202
you should use an intel processor made this millennium, senpai
>>
>>54075202
depends on the surrounding code
>>
>>54075173
>use (s not {s in the initializer
sorry what?
>>
I want to learn some ML and AI stuff and maybe a new language in a way that's a step or two removed from doing exercises out of a book. I'm thinking of making some kind of Runescape bot that does automated fishing and mining and stuff.

Good idea? Practical? Any good resources to start with?
>>
>>54075216
k{klasse}, l{level}
k(klasse), l(level)
>>
>>54075175
>Oh, feeling the repercussions so hard...
>he says as he fills a thread with his butthurt at being denied a pull request
once again your autistic neet argumentation tactics need work
inb4 "b-b-but i'm not butthurt"
>>
>>54075156
it's how you're supposed to do it in order to use sizeof - 1, not our fault that you have to deal with shit fag code "I don't know much about compiler optimization, but I would assume that this will be optimized by the compiler anyway" just fucking die
>>
>>54075235
and by learn ML and AI stuff, I mean building the tools from (mostly) scratch, not simply applying someone's libraries.
>>
import random
import webbrowser
import time
print("This program started at: " + time.ctime())
timeVar = 0
while (timeVar < 3):
time.sleep(10)
randnumber = random.randint(0, 3)
if x == 0:
webbrowser.open("https://www.4chan.org/")
if x == 1:
webbrowser.open("https://www.4chan.org/")
if x == 2:
webbrowser.open("https://www.4chan.org/")
if x == 3:
webbrowser.open("https://www.4chan.org/")

timeVar = timeVar + 1


When I run this program it just quits. What error do I have?
>>
>>54075249
ah ok so I didn't get you wrong
Player.h:12:2: error: multiple types in one declaration
};
^
still the same
>>
>>54075123
>Never worry about optimization in a fucking C program unless that function is going to be called hundreds of millions of times per second.

ok, i agree that the guy's change was autistic, but there's no reason to be this opposed to optimization. it's like when i see people using double when float would suffice. that's just bad programming.
>>
>>54075175
I sincerely hope you're planning on deleting your github after this.
If I was an employer and I was looking through your github and seeing your autistic argumentativeattitude toward premature optimization and your history of insulting pull requests, I'd trash your resume.
>>
Implemented this >>54075160 and it was 330ms faster than pow

>>54075161 is incorrect

>>54075159 why would a function call be faster than a built in operation?
>>
>>54075263
do you even know what the fuck you are talking about? do you know what the difference really is, instead of 'do it dis way so u kan use sizeof() - 1 and have it just werk!'?
>>
File: fuck yeah seaking.jpg (69 KB, 584x594) Image search: [Google]
fuck yeah seaking.jpg
69 KB, 584x594
>>54075299
>Implemented this >>54075160 (You) and it was 330ms faster than pow
>>
>>54075250
I am fine, just wanted to hear more opinions.
>>
>>54075299
no, a function call would be slower, and there's also the fact that you've got to branch in pow
>>
>>54075302
it's a const char array, which can decay into a const char pointer, so fucking what, there is no point in declaring it as a pointer instead of array
>>
>>54075299
>>54075317

x << 3;

vs

fn(x,3) =
if x is 2
ret x << 3
else
other impl

fn(x, 3); // set up stack for call, jump to fn
>>
>>54075284
Doubles are usually faster than float.
Also, if you're working in a constrained embedded environment, I doubt you would be using 4 whole bytes for a floating point value.
>>
>>54075317
yeah the reason I posted that was because pow was 9ms faster than left shift operator
>>
>>54075333
maybe it's a huge fucking char array, and i don't want it taking up a ton of stack space, faggot.
>>
>>54075354
probably a compiler optimisation
>>
File: 2DbinaryPattern.png (28 KB, 999x698) Image search: [Google]
2DbinaryPattern.png
28 KB, 999x698
oops, didn't realize the other thread died
Does an algorithm for matching 2D arrays of ordered data like this exist or is there a blindingly faster one I don't know about?
>>
>>54075371
>what is static
>>
>>54075157
Have you tried actually reading?

> expected ';' after class definition

Why not just do what it says?

Also like the other guy said, your initializer list is wrong, you want to use k(klasse) and l(level).
>>
>>54075387
why does this not just use == or some boolean predicate for elements
>>
>>54075378
It seems to be because left shift is designed for unsigned integers and I was using signed integers. When I made them unsigned, it sped it up way faster than pow.
>>
>>54075416
well it's only efficient when log(alphabet) is less than the length of the matching string
>>
>>54075279
#include "PlayerClass.h"

class Player {
public:
PlayerClass k;
int l;
Player(PlayerClass klasse, int level): k {klasse}, l {level} {}
};

There's no semicolon after method's declaration.
>>
>>54074473
S-should I crossdress?
>>
>>54075438
different instructions for unsigned and signed lshift, probably logical for unsigned and arithmetic shift for signed

>>54075465
not an error
>>
>>54075486
no
>>
>>54075404
>Have you tried actually reading?
rofl
have you?
read my post again
just wow

>your initializer list is wrong, you want to use k(klasse) and l(level)
no I don't, k{klasse}, l{level} is perfectly fine and working
>>
>>54075506
oh yeah you're missing the ; after } in your post
>>
>>54075531
yeah on purpose, makes sense when you read my post from left to write, from top to bottom
>>
>>54075589
>write
right*
>>
>>54075589
swap the {s with (s, you don't use {s in sub-initializers
>>
>>54075608
and why?

found the error btw, was in the included file
{ or ( is not the problem
why would I ever want to change that?
give me a really good reason
>>
>>54075630
oh nvm, thought that was a bug
>>
>>54075643
sounded like just another /dpt/ style guide I have to follow
>>
>Have to bring an O(n^3) algorithm down to O(n) for a specific case
>Spent the past few days wondering how the hell to do it
>Have to turn in assignment by Monday night
>Sit down with a piece of paper and start stepping through some matrix row operations
>Get an "A-Ha" moment after about 10 minutes
>Now I just need to implement the thing in Java and turn it in
>Most of the difficulty now is just going to be in not fucking up some array indices because I have to do some awkward transformations on them

Feels good man. Pen and paper = best tools for theoretical computer science.
>>
>>54075809

I love that shit. When you're at the keyboard it can be hard to actually figure something, but once you've got a piece of paper in front of you, the magic starts flowing.

That said, use a fucking pencil.
>>
File: 1231231231.jpg (2 KB, 125x92) Image search: [Google]
1231231231.jpg
2 KB, 125x92
>>54075907
>pencil
>>
>>54075922

I love the pencil nearly as much as I love black women. I refuse to use pen.
>>
>>54075809
this is why i use graph paper now, so comfy
>>
>>54075907

Did I say pen? Sorry, I used a pencil.

>>54075962

Graph paper's alright, and better for some purposes, but it can also be more distracting than plain white paper for some purposes.
>>
>>54075996
>Sorry, I used a pencil.

You fucking better have.
>>
>>54075996 >>54076014
Have you married each other yet?
>>
>>54076061

Ruby isn't a black negress.
>>
File: comfy.png (167 KB, 376x328) Image search: [Google]
comfy.png
167 KB, 376x328
DAILY PROGRAMMING CHALLENGE!

Using any programming language you like, write a function that takes this matrix of characters and rotates them 90 degrees to the right!

before:    after:
a b c d m i e a
e f g h n j f b
i j k l o k g c
m n o p p l h d
>>
>>54076086
Do your own homework
>>
>>54076130
>any programming language
>>
File: W9WTcKSC.png (655 KB, 500x657) Image search: [Google]
W9WTcKSC.png
655 KB, 500x657
Is it weird to use getchar() in C++?
>>
File: szbhp.jpg (48 KB, 460x345) Image search: [Google]
szbhp.jpg
48 KB, 460x345
>>54076165

fuk u libtard
>>
>>54076165
https://www.youtube.com/watch?v=EdCU2DfMBpU
>>
Another intro to java question:

I'm supposed to be updating my program that uses if and else statements so that they use loops, but it makes more sense to me to use if-else. Any suggestions in turning this into while/for loops?

public void livingRoom() {

JOptionPane.showMessageDialog(null, "Welcome, " + userName + ", to the living room.");
String ans = JOptionPane.showInputDialog(null, "You see a chest. Would you like to explore it? \n(Yes/No)");

if (ans.equals("Yes")) {
JOptionPane.showMessageDialog(null, itemChest);
amountOfLoot++;
mapLocationNum = 1;
}

ans = JOptionPane.showInputDialog(null, "Would you like to walk into the \"bathroom\" or back to the \"front door\"?");

if (ans.equals("bathroom")) {
livingBathroom();
} else {
frontDoor();
}
}
>>
>>54076267
java is such a disgusting language, lol
>>
File: 320402394.jpg (82 KB, 680x680) Image search: [Google]
320402394.jpg
82 KB, 680x680
>>
>>54076165

getchar() has its uses, even in C++. But you should check to make sure that your use case can't be covered by the C++ standard library first. It may be the case that you can achieve what you want more effectively without reading 1 character at a time.
>>
>>54076281
its because of stupid JOptionPane. Makes everything look cluttered.
>>
>>54076300
>string has dozens of function pointer array members larger than the actual string

fucking hell
>>
>>54076086
rot90(["abcd"; "efgh"; "ijkl"; "mnop"], -1)
>>
File: 1400924908474.jpg (1 MB, 2591x2592) Image search: [Google]
1400924908474.jpg
1 MB, 2591x2592
>>54076317
pls just help me
>>
>>54076317
what
>>
>>54076371
i've never used java, but I am to assume that every time a "string" class is instantiated, you're also allocating a function pointer for every single function in the string class, correct?
>>
>>54076267
if you want to do some java room-style text game there should be two main classes: player and room. room can have basic functionality like entered text, items and connected rooms etc. and then you don't have to retype all that jpane showDialog clutter in all your functions. you can extend the room class as needed to add some fancier rooms, like if enemyRoom where the room has some enemy, or something of the sort.
>>
>>54076388
>you're also allocating a function pointer for every single function in the string class, correct?

No. Look up the JVM spec for "method area"
>>
>>54074473
im trying to recompile a decompiled dll from enter the gungeon...

visual studio wont install properly and i can only use it 1 time the n i have to uninstall after i close it because its a legacy version . visual studio community wont finish installing. win7 no service pack 3

not sure if any one knows whats its like to be able to code in the language thats used to only find recompiling to a specific format almost impossible

mono develop isnt compiling to dll and loading the dll in unity 4.6 seems to only need the key. i get partial file structure but cant rewrite anything

any ways its more annoying than anything. i am beginning to think stealing their key and installing unity5 to change the dll might be easier. its just 8 values on the rewards manager that need to be adjusted

zero previous experience with dlls...
>>
>>54076393
I won't deny that this shit could be a lot better made, but at the time we had learned if-else statements and this shit made sense and now she wants us to update it with more functionality using loops. I have to work with what I got, unless its completely impossible
>>
>>54076437
jesus. well idk man, thats a horrible way to learn to program. you should read the entire book of whatever language you're going to learn from before you write a single line of code.
>>
Database question for ya'll:

I'm setting up a table listing Options for Stocks. seems pretty obvious to me that the ticker, or name, of each stock should be the primary key. each option then has a date and price associated with it and there can be over 500 of these date/price combinations for each stock.

how can I set this up well? do I really need 500+ columns for each row? seems there must be a better way.

theres a finite number of dates that can be used for each stock (say, 10 different dates) but theres not necessarily a relationship between what the prices are listed for each date.
>>
>>54076267
Use a while statement for the yes condition
So after they select no, the parameter you used for the while loop will be set to false so it will never happen. Also you can set the loop to end if the user enters the right choice.
Then use a switch statement within the while loop.
>>
>>54076480
I can't change anything major because im also sharing this code with someone else, and we've kinda split up some of the work. It's my first time working with someone on the same program, and I already know we're doing it inefficiently but i thought it would be simple since loops are pretty simple and its due monday so we got no time to be changing it all. I just need help with that one method, and then i could figure the rest out. SOMEONE
>>
easy question but what's the most efficient way to sort a sublist within an arraylist using Collections.sort() so that it can be rendered per frame. for example if you have an array (odd) 1, 3, 5, 7 and another array (even) 2, 4, 6, 8
numbers.addAll(odd);
numbers.addAll(even);

Collections.sort(numbers);
say you want to sort the array for odd so that it goes backwards like 7, 5, 3, 1 so that the numbers array is 7, 2, 5, 4, 3, 6, 1, 8
>>
>>54076644
what i'm saying is your program is shit and you should be able to figure out how to add a few loops. quit being a fucking needy nigger and clogging this thread with your ugly java clutter.
>>
File: banana.png (818 KB, 780x582) Image search: [Google]
banana.png
818 KB, 780x582
I'm trying to wrap my head around multithreaded programming.

Is there any possible situation in which I would have two threads accessing shared data, but would not need to use mutexes?

If both are only reading from the data and not writing to it, then sure, mutexes may not be required.

But if either thread is writing to the shared data, is there any situation in which I can get away without blocking off the read/write with a mutex variable?

I'm also having a little bit of trouble with "visualizing" multithreaded code in my head. Any tips for developing an intuition for writing correct multithreaded code?
>>
>>54076822
you could do it with something equivalent to java's volatile keyword or AtomicInteger, AtomicBoolean etc
>>
>>54076822
Think of it this way.
If the output of your program is not dependent on your threads doing things in a specific order, then yes, you don't need mutexes.
If mutexes are becoming a bottleneck for your application, you may want to look into giving each thread it's own cache and having another thread collate those caches asynchronously.
>>
>>54076822
http://developer.android.com/training/articles/smp.html
>>
>Tfw I can only build beginner and intermediate programmers but can't build any hard cool ones

Seriously how do you get to the level of building hard complex applications?
>>
>>54076857
>If the output of your program is not dependent on your threads doing things in a specific order, then yes, you don't need mutexes.
Wrong.
>>
>>54076866
just do it faggot

oh wait you're a faggot so you'll forever be doomed to do lazy half assed shit
>>
>>54076866
By doing it.
>>
>>54076879
I tried doing it but it's too hard and doesn't go anywhere
>>
>>54076840
Doesn't Java's volatile keyword do an implicit mutex lock?

For the sake of argument, let's suppose that I was programming in C and using the pthreads library or a similar low-level thread library.

Would there still be a way around mutex vars then?

>>54076857
>If the output of your program is not dependent on your threads doing things in a specific order, then yes, you don't need mutexes.
That makes a lot of sense, thanks for the tip.
So, even if I had a program where multiple threads were writing to the same shared data at the same time, but the order in which things happened didn't matter at all, then I don't have to use mutex variables?

>>54076865
I'll take a look at that, thanks

>>54076874
Could you elaborate on that?
>>
>>54076889
https://www.youtube.com/watch?v=BQ4yd2W50No

faggot
>>
>>54076891
Just because program logic can be reordered doesn't mean you can have multiple writes going on, they don't magically become atomic instructions.
>>
>>54075041
>But after that discussion, I'm thinking I don't care to contribute further, or use i3 in general.
lmfao this is the definition of buttblasted
>>
>>54075276

what is "x"?
>>
>>54076866

programmers are lazy and that's ok

you'll write a hard complex application when you have to, and probably not sooner

also typically you work on other people's complex programs for a while before trying your own
>>
>>54076904

I understand what you are saying, but I still can't understand a situation in which that would happen.

Could you give me an example of when multiple simultaneous writes in this situation would cause a problem?
>>
>>54076656
answer this you cunts
>>
>>54074514
Don't blame C.
Berkeley sockets are at fault here.
>>
>>54076940
When the write has not yet completed and another thread overwrites your work you are left in an inconsistent state.
Basically anything can go wrong at that point and all your guarantees are off.
Your program correctness is out of the window.
>>
>>54076866
Create simple abstractions and use them as part of larger, more complex abstractions.
Keep doing this until you've built an application.
>>
/g/ got a favor to ask you, for the life of me I can't figure out a work around for this and it's due in 2 hours. it keeps printing -858993460 instead of the right account number, any ideas as to why?

int main()
{
Account acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7, acc8, acc9;
Account list[10] = { acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7, acc8, acc9 };

acc0.setAccountId(0), acc1.setAccountId(1), acc2.setAccountId(2), acc3.setAccountId(3),
acc4.setAccountId(4), acc5.setAccountId(5), acc6.setAccountId(6), acc7.setAccountId(7),
acc8.setAccountId(8), acc9.setAccountId(9);

int inputaccnum;
cout << "Please enter an account number from 0-9: " << endl;
cin >> inputaccnum;
cout << list[inputaccnum].getAccountId();
......


the function is referencing is simply

int getAccountId()
{
return accountId;
}
>>
File: votingrepublican.jpg (59 KB, 800x600) Image search: [Google]
votingrepublican.jpg
59 KB, 800x600
>>54076186
Fuck off, conservatard.
>>
File: Capture.png (34 KB, 984x581) Image search: [Google]
Capture.png
34 KB, 984x581
I made a thing to make rainbow text on /sci/ or LaTeX in general with the \color{#hexcode}{\text{your text here}} commands but the generated LaTeX is too large for 4chan for anything above a sentence or two unfortunately

Is this shit more or less readable than Haskell, in your opinion
>>
public class Vector2 
{
public double x { get; set; } = 0;
public double y { get; set; } = 0;
}


>Of course, the default value of any number will always be 0 , so in this case we haven't changed anything, but it conveys the idea and the syntax correctly.

This is in the C# book I'm reading. Is this true? I thought variables/properties will never have a value unless it's been assigned to them?
>>
>>54076656

i think you'd better sort the different arrays how you like before you combine them

you can only have one compareTo() at a time, i think...
>>
>>54076958
Let's say this program is running on an x86 processor.

If data is being written to memory, then wouldn't the write boil down to a single "mov" instruction?

If two threads try to write to memory at the same time, and since the bus will only allow one core to access the memory at once, wouldn't one core be given preference over the other?

In the end, wouldn't all of the "mov" instructions finish correctly?

In what situation would I get an inconsistent state?
>>
>>54076656
>>54076944
In Java? You have to make your own comparator and use it with sort.
Collections.sort(list, customComparator); 

Our you could Collections.reverseOrder to get a comparator that sorts lists in reverse. Use the reverse comparator on odds and then combine the two lists step by step, but that wont always result in an appropriately sorted final list.
>>
>>54076995
This is the same in java too, I believe. They probably default it to 0 so that you don't have to explicitly set it to 0 for convenience.
>>
>>54076995
Default constructors initialize all primitive types to 0, 0.0, false etc.
reference types are set to null.
>>
>>54074711
>uint32_t
>Not size_t
I would not accept your pull request.
>>
>>54077002
>>54077011
i know about comparators, the thing is if i resort the arrays based on a comparator after then the part of the array that i don't wanted resorted would be resorted
>>
>>54076980

what does setAccountId() look like?
>>
>>54076981
>conservatard.

I'm not.
>>
>>54077031
>>54076995
think about how objects work in memory, and you'll see why you'd need to do this.

The alternative is a random value.
>>
>>54077031
>>54077024

So does that mean only properties are initialized that way, not class variables?
>>
>>54077038

i think you're out of luck here unfortunately.

want part of the list sorted differently than another part?

split into 2 lists, sort them, recombine them.
>>
>>54077043
set accountid() looks like this

void setAccountId(int x)
{
accountId = x;
}
>>
>>54076995
they must have one value or another. they start out with 0 or null if you don't specify otherwise
>>
>>54077008
When you get scheduled out mid write.
When you have different state in different cores (caches are per core)

Lets take this example.
http://play.golang.org/p/eULb7-smch
On the playground (GOMAXPROCS=1) this produces the correct result.
On my laptop using the amount of cores available it leads to pretty random numbers.

[sjon@x220 play]$ go run main.go
1083655
[sjon@x220 play]$ go run main.go
1494957
[sjon@x220 play]$ go run main.go
1073136
[sjon@x220 play]$ go run main.go
1034426
[sjon@x220 play]$ go run main.go
2000000
[sjon@x220 play]$ go run main.go
1066256
>>
>>54076980
>>54077043
Here's a link to the full code if that helps
http://pastebin.com/AbJ0irXB
>>
>>54077064
Lost
>>
>>54074473

https://www.youtube.com/watch?v=hxyiafJ7CeQ
https://www.youtube.com/watch?v=hxyiafJ7CeQ
https://www.youtube.com/watch?v=hxyiafJ7CeQ
https://www.youtube.com/watch?v=hxyiafJ7CeQ
>>
>>54077050

I guess I always kind of figured that when the object was initialized with the new keyword that any variables without values would be pointing to a space in memory that was empty. I suppose it makes sense that they have to be set to something though.
>>
>>54077090
???
>>
>>54077068
Oh man, you're completely correct.

I just wrote a similar program in C with pthreads, and the exact same thing is happening.

I think I get why this is happening.

Thanks for the help
>>
>>54076980

i don't know c++ but do you want to use "new" when you're making all those accounts?
>>
File: browser #112.png (1 MB, 1680x1050) Image search: [Google]
browser #112.png
1 MB, 1680x1050
>>
>>54077160
>>I don't know c++
>>do you want to use "new"
Appreciate the effort but no you don't. I have other functions working just fine such as .getBalance and shit it's literally just specificially this one function
>>
>>54076980
I don't know C++ either, but when you make that list array, does each account get copied into the new array, or does only its reference get copied in?

Because if it gets copied in, then all of the setAccountId calls affect only the original accounts, not the ones copied into the list, which could have any value.
>>
>>54077242
it's just the reference gets copied in.
>>
>installing git on windows
>easy install
>set up ssh key for my remote repo in windows' git bash
>git -T [email protected]
>prompts for password
>wtf?
>spend like 2 hours trying to figure out wtf is wrong
>ssh into my linux server / router
>install git, put my private repo key on there, it works immediately
>windows git bash still won't work with ssh

please someone tell me what is wrong
>>
hello friends.

I am trying to download a raw text file from github in lua like such:

local http = require("socket.http")
local s = http.request("http://github.com/torvalds/linux/raw/master/README")
print(s)


s always winds up being an empty string, which I do not understand. Where am I going wrong?
>>
>>54077284
>>prompts for password
>>wtf?
>>spend like 2 hours trying to figure out wtf is wrong
Did you try entering the password?
>>
>>54077284
Are you using the SSH remote address?
>>
>>54076980
classic Account example homework for uni assignment I have done this before all in Java
>>
File: 1270537027582.jpg (38 KB, 693x390) Image search: [Google]
1270537027582.jpg
38 KB, 693x390
Newbie here. Just a few questions if you don't mind.

I've recently started teaching myself C++ before I start college next year. I'd like your opinion /g/ if that's an okay language to start from?

And if so, do any of you experienced users have any books you could recommend me/I should read?

I already did some minor research to start, but I'd appreciate /g/'s opinion. I realize its best to program in order to learn programming itself rather than a language, but I feel there's just too many places to start from. It's a bit overwhelming, so I just picked something that looked interesting and started from there. I just wanted to take that first step really.
>>
>>54077307
>>54077314
.... when I do a
 git clone [email protected]:repo.git 

from the window's git bash command line, git will look to git bash's ~/.ssh/id_rsa file (rather the IdentityFile I have defined in that .ssh/config file), and use that to authenticate me to my repo

it is not working, and I have no idea why, doing
 ssh -T [email protected] -vv 


shows that git is trying to use the correct key but for some reason it's not working

setting it up on a linux server in 2 minutes yields the correct results
>>
>>54077320
I have done this is my java class as well but c++ is just some fuckery. Every single other function works except for the getaccountid, which leads me to think that there is a mistake in how I made the getaccountid function but idk how else I would fucking write that.
>>
>>54077349
But did you try entering the password?
>>
>>54077372

google "858993460", there's a ton of stack overflow about this.
>>
File: screenFetch-2016-04-16_22-07-05.png (66 KB, 1280x1024) Image search: [Google]
screenFetch-2016-04-16_22-07-05.png
66 KB, 1280x1024
I feel as if I am going to be roasted so hard I will turn as black as my shitty color scheme. Btw can someone tell me how to configure xterm.
>>
>>54077449
https://wiki.archlinux.org/index.php/Xterm

next time: >>54073838
>>
>>54077467
Thank you for being a sir, sir
>>
File: 1442098930937.jpg (68 KB, 1024x576) Image search: [Google]
1442098930937.jpg
68 KB, 1024x576
>>54077379
>>
>>54077481
next time:>>>/reddit/
>>
In C++ if I add
strLength = cin.gcount()
to my simple while loop why does it suddenly stop printing stuff when, without it, it will ask for input and print indefinitely? It is some weird shit with the buffer or something?
>>
>>54076822
>But if either thread is writing to the shared data, is there any situation in which I can get away without blocking off the read/write with a mutex variable?
Yes, if the writes are atomic.
>>
Does NVMe mean that I won't be able to communicate with SSDs using ATA anymore? and have to implement an NVMe driver?
Or will they still be backwards compatible with ATA?
Or am I retarded and ATA and NVMe are completely different things?
>>
>>54077569
>to my simple while loop

Where did you add it? Also, I don't think gcount does what you want.
>>
>>54077651
Right before the cout statement. Does cin.gcount() somehow interfere with the functioning of cin.getline()?
>>
So classes are reference types. When you have a value type (like an int) in a class is that variable just a reference to the value on the heap? Or does that variable actually contain the value?
>>
I have to make a hangman game in 4 hrs, how fucked am i?
>>
>>54077768
Depends how much of a retard you are.
>>
>>54077768

Not very depending on your skill and language.
>>
>>54077768
Should be very easy to do, provided you get off 4chan. What language?
>>
>>54077768
ctrl+c ctrl+v
>>
easiest language to get/parse html?

think I'm going to use python, have used it a few times for this purpose. am I making my life easy?
>>
File: WAKEMEUP.png (185 KB, 564x404) Image search: [Google]
WAKEMEUP.png
185 KB, 564x404
Using VB NET (Visual Studio 2015)
I read data from a csv file and show it on a report from the sql tools

Now i want to add an image to the report for each item how do i do it?

>inb4 he fell for the vb net meme xD
>>
>>54076980
>>54077372
>>54077257
>>54077226
>it's just the reference gets copied in.
No, that is in Java. In C++, the value gets copied in. Changing the account after you've put them into the list has no effect on the version in the array, so you effectively just have uninitialized account variables there.

BTW, in the default constructor, you should set the account id to something that lets you know it isn't ready, like -1. This would have facilitated your troubleshooting, too.
>>
>>54077877

Python and BeautifulSoup make this a total breeze. You won't regret it.
>>
>>54077877
Yeah, it's fine. Use this:

https://www.crummy.com/software/BeautifulSoup/bs4/doc/
>>
Are the headers for adding SSE functionality portable between compilers?
>>
>>54074711
This is autism on a whole new level
Even if you're correct, you'd probably save not even a millisecond of time
On a program that's run only once
Thread replies: 255
Thread images: 33

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.