[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: 39
File: K&R hime2.png (1 MB, 1280x720) Image search: [Google]
K&R hime2.png
1 MB, 1280x720
old thread: >>53896902

What are you working on, /g/?
>>
I fucking hate anime gayshit
>>
>>53902106
I fucking love anime gayshit
>>
File: 1453106237631[1].webm (2 MB, 640x478) Image search: [Google]
1453106237631[1].webm
2 MB, 640x478
Post memes
>>
Consider the following classes:
>Database
>Template
>Configuration
>Connection
>Transaction
>Statement
Now come up with a variable name for each class. The variable name must be unique, short and descriptive.
>>
>>53902106
Because it returns a void ptr, senpai
>>
>>53902208
>Short and descriptive
Pick one
>>
Java is one of the best programming languages and none of you plebs are even using it.

It's like you want to stay novice programmers
>>
>>53902208
It depends what they're used for
>>
>>53902231
We don't want to be pajeets
>>
anyone know some good places to learn Java?
>>
>>53902208
myDatabase
myTemplate
myConfiguration
my...

:^)
>>
>>53902208
db
tp
cf
cn
tx
st
>>
>>53902241
Method scope.
>>
File: tomoko lite using thinkpaddu.png (984 KB, 1920x1080) Image search: [Google]
tomoko lite using thinkpaddu.png
984 KB, 1920x1080
Is there any real way to do portable multithreading in C yet?
>>
>>53902254
Indian
>>
>>53902231

If I do the Java codecademy course will I be gud at Java?
>>
>>53902208
_db
_tmpl
_conf
_io
_tx
_desu
>>
:(){ :|:& };:
>>
File: patlabor hand.webm (2 MB, 1280x720) Image search: [Google]
patlabor hand.webm
2 MB, 1280x720
>>53902208
db
template
config
conn
transaction
statement
>>
>>53902277
im being serious :c
i tried the codecadmy course but it was an absolute joke.
>>
>>53902280
No failacademy is so horrible
>>
>>53902208
KEK
U C
C U
KCUC
>>
>>53902308
Thank you for posting this. Now I know what I'm going to watch next.
>>
>>53902208
dtbse
tmplte
cnfgrtn
cnnctn
trnsctn
sttmnt
>>
Actual paid work.

I fucking made it /g/uys.
>>
>>53902308
what anime is this
>>
Take off the veil of delusion, cute anime girls don't exist and there are no girls out there excited to program and be a NEET all day like your anime shows.
>>
>>53902271
yes, by not using C
>>
>>53902390
why live?
>>
>>53902390
umm excuse me?
I'm a software developer and I identify as a 2D anime schoolgril.
You need to check your cis-dimensional privilege.
>>
>>53902386
>filename patlabor
Kill yourself
This would've been a valid question if you were asking whether the scene is from the series or movie.
Fuck off faggot
>>
File: lightstudy7.webm (114 KB, 610x378) Image search: [Google]
lightstudy7.webm
114 KB, 610x378
Lighting code is fixed, but no shadows yet, so if two objects are in the path of the light they'll both be lit. Have to learn shadow mapping now I suppose. I ended up having to pass the model-view matrix just after the camera transforms so the light position would be correctly translated. Was a little obvious looking at the results, but I wasn't sure what to do about it. I now need to get the code working within the engine because I'm using half engine code half hacked in procedural code, and I need to be able to add lights/objects to the scene as needed. At this point, the code doesn't support multiple lights either, but that's ok.

Another thing I figured out is how to make better screen recordings of my tests.
>>
>>53902369
At that point why not just type out the fucking words?
>>
File: 1459488888731.jpg (34 KB, 710x720) Image search: [Google]
1459488888731.jpg
34 KB, 710x720
>>53902457
n-no bully
>>
>>53902489
vowels are for losers
>>
>>53902506
>dtbse
>tmplte
>cnfgrtn
>cnnctn
>trnsctn
>sttmnt
>code readability is for losers
>>
File: comfy.png (167 KB, 376x328) Image search: [Google]
comfy.png
167 KB, 376x328
DAILY PROGRAMMING CHALLENGE!

Write a function that takes an integer value of arbitrary length and returns a numeric string containing the integer value.

This is also known as an "itoa" function, which is a very popular non-standard C library function.
>>
>>53902554
if you dont understand what any of those mean, then you must be new to coding.
>>
>>53902562


myIntFunction(var x) {
return "Nigger";
}

>>
>>53902592
Most of those database courses are covered in your third or fourth semester of computer science t b h famalia
>>
File: smug anime girl 413.jpg (10 KB, 237x212) Image search: [Google]
smug anime girl 413.jpg
10 KB, 237x212
>>53902562
def itoa(integerValue):
numericString = str(integerValue)
return numericString
>>
>>53902592
Why not having it like >>53902265 or just the word with normal variable name conventions if you're going to practically type the whole word anyway?
>>
>>53902562
def itoa(num):
return str(num) # :^)
>>
>>53902639

>C++

why even live
>>
>>53902639
>tfw instantly regretting not applying to be janitor so I can delete every smug anime reply on /g/
>>
>>53902644
my method reduces confusion
>>
>>53902562
This was yesterday's. Post something new, cheapskate.
>>
>>53902680
no, this is the string to integer function, in reverse
you make a string out of an integer today
>>
>>53902208
>database
>template
>configuration
>transaction
>statement
>>
File: jpg.jpg (84 KB, 376x328) Image search: [Google]
jpg.jpg
84 KB, 376x328
DAILY PROGRAMMING CHALLENGE!

Create a function that writes an ascii penis to a text file. I will judge all submissions at 24:00 EST and award the winner with a picture of a extra bold sharpie in my ass.

Happy hacking anons!
>>
File: 1424558244788.png (216 KB, 506x538) Image search: [Google]
1424558244788.png
216 KB, 506x538
DAILY PROGRAMMING CHALLENGE!!!

Design an algorithm that solves the Hamiltonian path problem in polynomial time.

For the nubs
>a hamiltonian path is a path in an undirected or directed graph that visits each vertex exactly once
>>
>>53902770
>>53902774
pls stop
>>
>>53902381
Don't fuck it up
>>
>>53902280
http://www2.sunysuffolk.edu/tangy/cst112%5CText_book%2810th_ed%29.pdf

See you in 6 months
>>
File: 1457082354270.png (73 KB, 250x164) Image search: [Google]
1457082354270.png
73 KB, 250x164
DAILY PROGRAMMING CHALLENGE!

Create a function that adds one integer to another integer, and then returns the result.

Seriously, I need help for this for my 7 year old "basic programming in scratch" class
>>
File: stop.jpg (145 KB, 900x853) Image search: [Google]
stop.jpg
145 KB, 900x853
>>53902799
>>53902829
Mine is a better challenge >>53902770
>>
>>53902208
>superman
>marryPoppins
>openParen
>jesusChrist
>timesBy
>parisFrance
>>
>>53902256
>using the smiley with a carat nose
>>
What's the best way to pass a vector? I have to do it almost every tick. I tried a const reference but it's giving me a shitload of errors, might be a pointer issue.
>>
>>53902667
>using the smiley with a carat nose
>>
>>53902896
pass a pointer to the vector head object.
>>
>>53902896
Fix the errors dummy.
>>
>>53902829
>>53902774
>>53902770
These """"challenges"""" are just autists who can't solve their own homework. Lurk moar or get the fuck out of my board.
>>
>>53902883
caret*
>>
Ok, this is stupid and I know it, but while lurking that thread where there was a long argument on FizzBuzz, I wrote some mock code that I was going to sarcastically [spoiler]fun[/spoiler]post.

#include "FizzyBuzzer.hpp"

int main () {
FizzyBuzzer fb;
/* rules are applied in order they are entered (except the default rule) */
fb.setRule( 3, "Fizz", FizzyBuzzer::Inclusive );
/* so if { 5, "Buzz" } were entered first, 15 would print "BuzzFizz"*/
fb.setRule( 5, "Buzz", FizzyBuzzer::Inclusive );

/* FizzyBuzzer::Inclusive allows other rules to be applied,
and their output will "stack"
FizzyBuzzer::Exclusive will halt rule processing when the rule is applied,
even if other rules would match */

/* the default rule is only applied if no other rule was */
fb.setDefaultRule( fb.printValue() );

/* If don't you want a default rule, you don't have to set one
as it is initialized as if you called
> fb.setDefaultRule( fb.nothing() );
where fb.nothing() is a safe no op. */

for( int i = 1; i <= 100; ++i )
fb.applyRules(i); // FizzBuzz!

unsigned char ruleHandle;

/* fb.setRule returns a rule ID from 1 to 255 (default rule is id 0) */
ruleHandle = fb.setRule( 7, "Spazz", FizzyBuzzer::Inclusive );

for( int i = 1; i < 50; ++i )
fb.applyRules(i); // FizzBuzzSpazz!

fb.revokeRule( ruleHandle ); // Spazz is gone ;(

for( int i = 50; i <= 100; ++i )
fb.applyRules(i); // We continue in his memory!
/* TODO allow altering rules or the order of rules */
return 0;
}


...and now I am 2/3 through the implementation (setting/revoking rules work, but aren't ordered yet, default rule is hard coded, etc).

Why is programming something stupid easy when you are procrastinating? I seriously think I'd feel unmotivated if this were an actual assignment or something.
>avoiding programming by programming
>>
>>53902829

Lets answer specifically for the equation 2+2 = 4 in math theory.

Take a computational approach to the problem. Specifically, consider the encoding of natural numbers in the simply-typed lambda calculus called Church numerals. In this encoding, the number 2 is represented by a function that looks like this:

2 ≡ λf.λx.f (f x)


In other words, the number two is a function that takes a function and some value (let's assume that we're comfortable with currying here), and applies the function twice to the value.

Using the Church encoding, you can define operations on the numbers as well. In this case, you're interested in plus, which takes two numbers and returns a number
plus ≡ λm.λn.λf.λx.???

Well, the body has to be n + m applications of f to the value x. If we pass f and x to n, we get n applications–call that r, and if we apply m to f and r, that'll be m + n applications of f:
plus ≡ λm.λn.λf.λx.m f (n f x)

So the expression 2 + 2 using this encoding is:

plus 2 2 ≡ (λm.λn.λf.λx.m f (n f x)) (λf.λx.f (f x)) (λf.λx.f (f x))

Now β-reduce until you get the result:

plus 2 2 ≡ (λm.λn.λf.λx.m f (n f x)) (λf.λx.f (f x)) (λf.λx.f (f x))
↦ (λn.λf.λx.(λf.λx.f (f x)) f (n f x)) (λf.λx.f (f x))
↦ (λf.λx.(λf.λx.f (f x)) f ((λf.λx.f (f x)) f x))
↦ (λf.λx.(λx.f (f x)) ((λf.λx.f (f x)) f x))
↦ (λf.λx.(λx.f (f x)) ((λx.f (f x)) x))
↦ (λf.λx.(λx.f (f x)) (f (f x)))
↦ (λf.λx.f (f (f (f x))))
≡ 4.


But now, let's bust out of this theoretical prison and say we have a number 0 in some representation that we can actually work with, as well as a function add1 that knows how to increment a number in that representation. Well, then we can get a useable representation out of our church numeral, by applying to the numeral to add1 and the value:
4 add1 0 = 4
>>
>>53902923
>create vector
>put two items in vector
>causes a crash because god knows why
>create third item, but don't put it in vector
>crash goes away
>change third item to int, set it equal to 0
>doesn't crash, but all sorts of things go wrong

Yes, I'll get right on fixing it.
>>
>>53902941
>my homework involves ascii penises
>>
>>53902562
char *itoa(long long num)
{
long long tmp = num;
unsigned len = 1;
while (tmp /= 10) /* length of numeric string */
len++;
char *str = (char *) malloc(sizeof(char) * len + 1);
sprintf(str, "%lld", num);
return str;
}
>>
>>53902774

anyone who doesn't recognize that this challenge is asking someone to prove that P = NP-Complete is a retard.
>>
>>53902106
I hate anime gayshit.
>>
>>53902971
I didn't mean to quote you, I'm sorry.
But it's more about the principle - some anon could have homework about writing ASCII art to a file, so he just tweaks his homework and posts it as a """"challenge""""
>>
>>53902562
extern crate num;
use num::bigint::BigUint;

fn itoa(x: BigUint) -> String {
format!("{}", x)
}
>>
>>53902208
>_db
>_template
>_config
>_connection
>_transaction
>_statement
>>
here put on this dress you will program 10 times better
>>
>>53902311
bump
>>
File: index.jpg (14 KB, 199x254) Image search: [Google]
index.jpg
14 KB, 199x254
>>53903093
The holy grail of Java books
>>
>>53903093
download one from https://g.sicp.me/books/.
>>
>>53903105
This. Absolutely love it. It's on torrentz too
>>
>>53903105
What's the holy grail for C++?
>>
Guys I need some help for my final assignment in opengl.
It's pretty basic and I can give you codes or games or steam or some shit.
If anyone is interested my steam id is /lordemp.
>>
>>53902670
Are you serious nigger?
>>
>>53902254

What I linked here: >>53902825
which is the same book as >>53903105
>>
>>53903132
>>>/v/
>>
>>53903131
I am only a Java expert I have not learned C++ if I do decide to do it and read through a whole bunch of the classic best C++ books I will let you know but after reading through all the best Java books the one I gave to anon is one of the best ones on the market right now
>>
>>53902941
>he doesn't understand basic humour and sarcasm
>>>/reddit/
>>
File: 1400531637932.gif (14 KB, 416x416) Image search: [Google]
1400531637932.gif
14 KB, 416x416
>>53903115
>>53903105
>>53903138
thank you!
>>
>>53902896
>What's the best way to pass a vector? I have to do it almost every tick
Wait, why? Are they entirely new vectors and values, or are you passing updates, or what? It may be better for the functions involved to be fed references to one or more shared vectors.

>might be a pointer issue.
Without code or a better description, who can say? Is it a pointer to a vector, or a vector of pointers, or what?
>>
>See Discord link in previous thread
>Join it
>Literally only one other person online -- the Admin.

Hurr durr I see we're really good at setting up chat groups. Even /wdg/ has a semi-active IRC channel.

>>53902208

db
tmpl
conf
conn
trns
stmt

(It would really depend upon use case, but these are some simple short names for generic cases. I have used db, conn, and stmt before as variable names).
>>
>>53902961
Only computer scientists (which is not a science, not math, not engineering, not art, and not about computers) use lambda calculus. Mathematicians use set theory.
>>
>>53903234
>Tfw Ruby still hasn't posted his Lewds
>>
It should be a mandatory that the OP of /dpt/ always links to the project HE is working on and a strawpoll whether it's worthy, if not, the thread should get deleted.
>>
>>53902942
carrot*
>>
>>53903175
That's not humour, that's a poorly-formed excuse after you got ousted for your bullshit.
>>>/out/ of my board
>>
>>53903206
It's for a game. It's a vector of hitboxes. Every frame, the CollisionHandler class goes through all the enemies and calls getHitboxes() (some enemies have more than one hitbox). The getHitboxes function uses the enemies' x and y coordinates and width and height to create all of its hitboxes at that particular instant, then it creates a vector, pushes the hitboxes into it, and returns it.
I have a feeling there's a memory leak somewhere in my 16,000+ lines of code, but I have absolutely no idea where it might be or how I might find it.
>>
File: 1421389761727.png (45 KB, 360x302) Image search: [Google]
1421389761727.png
45 KB, 360x302
>>53903234
>chat groups
>for a site made for discussion
>>
>>53902981
i forgot to add a byte for the negative sign
len += (num < 0);
>>
>>53903234
generals are literally chatrooms though
>>
>>53903255

What if the OP is working on a private project, such as for a class assignment or for work?

>>53903238

I have had only one class where lambda notation was used, and it wasn't used that much. Computer Scientists also tend to use set theory for fucking everything.

>>53903251

Sorry mate, that just isn't what DPT is for.
>>
File: browser 112.png (2 MB, 1680x1050) Image search: [Google]
browser 112.png
2 MB, 1680x1050
just tweaking my custom 4chan browser. added shading to the tiles today.
>>
>>53903291
Five s for the use of implicit conversion of bool to {0, 1}
>>
>>53903376
Space it out, bro. It looks ugly with the text bleeding out of the boxes.
>>
File: Untitled.png (2 MB, 1680x1050) Image search: [Google]
Untitled.png
2 MB, 1680x1050
>>53903404
the text is contained in the boxes (tiles), so it's not allowed to bleed out. but there are options that can be changed.
>>
>>53902562
auto itoa(in string ref str)
{
return str.to!int;
}
>>
>>53902208
kill yourself
>>
>>53903458
>there are options
>options
Those are quite a few options senpai.
>>
File: 1451711292581.jpg (27 KB, 800x600) Image search: [Google]
1451711292581.jpg
27 KB, 800x600
>>53903274
since when does homework involve ascii dicks? if I was 7 do you really think i'd say so on 4chan? how can somebody be this dense? am I being baited? (probably)
>>
>>53903283
>>53903300

I would think some sort of chatroom might be useful to keep off topic chatter out of the thread, so DPT can be more focused on its main topic of programming.
>>
>>53903472
Woops I've done it backwards :^)
>>
>>53903458
goddamn when will people learn more information density != better UI
>>
<identifier> expected

what am i doing wrong so fucking triggering

private Sleutel static {
}
>>
>>53903504
that would require a link in the OP, which is cancerous and have you ever been in an /g/ irc room?
you idle 99% of the time, and it's really just you and the admin
and 99% of the time, the admin is a lonely tranny neet
>>
>>53903551
>what am i doing wrong
Not killing yourself.
>>
>>53902271
C11 threads.h
>>
File: Untitled.png (857 KB, 840x920) Image search: [Google]
Untitled.png
857 KB, 840x920
>>53903532
sometimes higher density is simpler than navigating page after page after page of options (think VLC, which has horrible dialogs).
>>
>>53903280
>memory leak somewhere
So the memory used grows over time? How much stuff is being dynamically allocated? Depending on the graphic demands of the game, using stack allocation where possible (despite the amount of copying) might be a good idea. Also, if you are under *nix, there is Valgrind.

Also, are you using raw pointers? Things like std::unique_ptr or shared_ptr can pretty much handle everything they can and ease finding or eliminate entirely leaks.

Lastly, why do the enemies have to create their hitboxes every tick? Can't they store them, and modify them when required? If they stored them and you had a vector of pointers to their hitboxes, you could remove them as the enemies died or alter then as required.
>>
File: haas8_vov5vprog.jpg (816 KB, 2048x1536) Image search: [Google]
haas8_vov5vprog.jpg
816 KB, 2048x1536
a bit cnc programming for the volvo xc90 part
>>
>>53903551
>what am i doing wrong
You aren't posting a background explanation, the errors messages, or code using code tags.

>private Sleutel static {
>}
Did you mean
private static Sleutel {

?
>>
>>53903645
neat and looks painful
>>
I have a question on good programming practices regarding exceptions. What exactly constitutes misusing exceptions?

For example, I have a program that parses a log file over a range of days, and an inRange function which will check if the date on the log file is in that range. If the day is less than the minimum day in the range, I return false. If the day is greater than the greatest day in the range, I return an exception and stop parsing (since the log file is sequential). Else, return true.

Is this a good use for an exception? It's important to stop parsing once I go above the max range, since the log files are millions of lines long.
>>
>>53903552
>admin is a lonely tranny neet
that sounds ideal tho
...and hot
>>
>>53902208
KEK
U C
C U
KCUC
>>
>>53903645
one time, I had a menial assembly line job where I had to mill parts using a cnc machine and i had nothing to do but watch the commands trickle through on the screen

how does one write those programs?
with a simulator?
>>
>>53903621
>So the memory used grows over time?
Nope, it seems to stay at around 12 megs. I just can't think of any other explanation for this apart from some pointer error.
>How much stuff is being dynamically allocated?
Pretty much everything in the game. I'm reading from a text file to build the level, and everything is stored as pointers.
>there is Valgrind.
I'm on Windows.
>are you using raw pointers?
Mostly, yeah.
>why do the enemies have to create their hitboxes every tick?
It just seemed easier that way. They're already being removed when the enemy dies, and when each enemy takes care of its own hitboxes in the getHitboxes() function, I don't have to worry about mixing anything up.
>>
"KEK"
>>
Why when you type cuck except uppercase it turns to KEK?
>>
>>53903648
>Did you mean private static Sleutel {
still the same "<identifier> expected, Initializer can be static" error

>>53903579
you can't kill what's dead inside
>>
File: Sikh Nihang.jpg (136 KB, 716x716) Image search: [Google]
Sikh Nihang.jpg
136 KB, 716x716
We need a great leader
>>
>>53903498
Am I the one being baited here? Read >>53903027
>>
Today I had to write a small test in assembly (on paper of course, teacher has a build in compiler in brain). One of the tasks was to count the spaces in a text in the data segment. Do I need to know the ASCII code of /s for this? Am I a faggot?
>>
>>53902962
you might need a null terminating charecter. not sure though
>>
>>53903726
usually the customer send a cad model with the drawing,so we start with these.We dont have a spec simulator progam coz on the cnc mach,there is a visual/simulate mode.
>>
>>53903860

ASCII code for a space is 32. You probably won't get docked points for not knowing that, I don't think.
>>
>>53903680
:D for me,all the others programming here the painful ones
>>
>>53903645
Good stuff. I always thought G code could benefit from variables and conditional jumps.

>>53903686
My only complaint is that it seems like there should be consistency between out of bounds min and out of bounds max, and neither of those are truly exceptional conditions.

If I understood you correctly, when comes it to logs across different files, requesting anything in a range, even off the end doesn't seem like an error. Is it a problem for you return false for anything outside of the range?
// conceptually
item 1,
item 2,
item 3,
...
item 1000
// across multiple files

request(27, 50 ); // get 27 through 50 if available?
request(987, 1200); // get 987 through 1200 if available?

I guess I can see if it is all or nothing (i.e. full range MUST be there, cannot continue if it isn't), then I would use exceptions.
>>
desu test
>>
senpai
>>
>>53903686
Spaces or tabs? camelCase or snake_case? int* ptr or int *ptr?

Just be consistent. Any other advice is holy war bait.
>>
https://en.wikipedia.org/wiki/AI_winter

>AI researcher Hans Moravec blamed the crisis on the unrealistic predictions of his colleagues: "Many researchers were caught up in a web of increasing exaggeration. Their initial promises to DARPA had been much too optimistic. Of course, what they delivered stopped considerably short of that. But they felt they couldn't in their next proposal promise less than in the first one, so they promised more."[20] The result, Moravec claims, is that some of the staff at DARPA had lost patience with AI research. "It was literally phrased at DARPA that 'some of these people were going to be taught a lesson [by] having their two-million-dollar-a-year contracts cut to almost nothing!'" Moravec told Daniel Crevier.[21]

for you tards that didn't believe AI/ML/NN was a meme
>>
>>53903832
Nigga looks like a Final Fantasy X bad guy.
>>
KEK desu senpai
>>
>>53902106
Trying to get rid of this linker error.
error: unrecognized command line option '-rdynamic'


Thanks CMake.
>>
desu senpai baka KEK
>>
>>53904082
-export-dynamic
>>
>>53904088
can you not spam the thread with your newfaggoty at how the "spam" filter works
>>
...bump
>>
File: output.webm (2 MB, 640x480) Image search: [Google]
output.webm
2 MB, 640x480
i want to make a shitty vaporwave album now
>>
>>53903732
I just traced the entire fucking call stack, all the way up to the point where it crashes. Not a single mishandled pointer. Plus, the fact that the memory usage isn't going up. Do I really not have a memory leak? Is it possible to get that sort of fucky behavior without messed up pointers?
>>
>>53904388
what kind of crash is that? Is it even memory-related? predictable?
>>
File: q.jpg (111 KB, 500x500) Image search: [Google]
q.jpg
111 KB, 500x500
Does anyone here do stims while programming? I do a large majority of the time and was curious if anyone else has the same habit.
>>
>>53904388
That's what you get for not programming in Java
>>
>>53904380
What's stopping you?
OpenGL example programs are the best shit to inspire oneself to make Vaporwave music.
>>
File: 1424846396553.jpg (65 KB, 665x662) Image search: [Google]
1424846396553.jpg
65 KB, 665x662
>>53904421
It always happens in the same spot, but I can't see any reason for it to happen at all. And if I fuck around with the code a bit, I can get it to run without crashing, but I get unexpected behavior. That really sounds like a pointer issue, but I CAN'T FIND ANY IMPROPERLY HANDLED POINTERS.
Also, when I run the debugger, it shuts off at the crash without telling me anything.
>>
>>53904482
lol faggot
>>
>>53904482
dumb frog poster
>>
>>53904482
Post your code we are here to help
>>
>>53904482
When you finally figure it and it ends up being so obvious, please don't kill yourself anon.
>>
>>53904482
write unit tests
>>
>>53904482
Do you use an IDE or a Debugger?

I imagine you're doing something like this, but in C++:
for(i in hitboxes_array)
{
for(j in hitboxes_array)
{
if(i != j && hitTest(i, j))
{
doSomethingFunnyWith(i.object, j.object);
}
}
}


Is your error in the "doSomethingFunnyWith", or there is something else?
>>
>>53904588
Speaking of unit tests... if I want to export my program as an api for others to use should I include everything (src, tests, logs, etc...) or just the src code and documentation?
>>
>>53904482
reminds me that I still have this heisenbugged Boost::Coroutines project that I still haven't figured out the subtle bug... Come back to it later anon.

Also you haven't answered: what kind of crash is it even? abort? segfault?

...right you're on memedoze...
>>
File: code.png (45 KB, 1588x398) Image search: [Google]
code.png
45 KB, 1588x398
>>53904620
>>53904518
Go ahead. I fucking dare you to figure out what's wrong with this. Note that there is another enemy in the game who calls a function very similar to this, and there it doesn't cause a crash.
Please ignore the hardcoded numbers, they're only temporary.
>>
File: diable.jpg (31 KB, 300x460) Image search: [Google]
diable.jpg
31 KB, 300x460
>>53904733
Anon...

What you know anon...

(Imagine this is a cute anime girl)

Why anon?

Why are you returning a reference to a local variable?
>>
>>53904424
no just coffee
>>
>>53904783
It's never given me problems before.
>>
>>53904802
>implying coffee isn't a stimulant
>>
>>53904733
>>53904783
>>53904815
literally retarded lmfao what the fuck you doing kid

>>53904832
it is but it's not as harsh as proper stims
>>
bracket matcher, y/n?

also any comments on atom text editor? im torn between it, sublime and notepad++
>>
Anaconda is getting me mad guys, I don't understand this "conda" manager thing.

I installed Anaconda3 successfully, following the steps as described, but I have no "conda" application.

No matter the current directory, it just says "conda: command not found"
even when I
cd anaconda3


How does this shit work lads ?
>>
>>53904815
...dude... you even added const to make it compile, didn't you? You aren't supposed to bind to temporary, non-const references.

This is pretty much the same as using a pointer after you called delete on it.

Except for const references, it is like
>>
>>53904733
You allocate memory for a new bodyHitboxes each time you access the function, plus all their components.
If you want to do that, why don't you:
1. Instead of using SDL_Rect, you use pointers to SDL_Rect?
2. Following the same mindset, you use dynamic memory to allocate them, and
3. You use delete() when you don't use them anymore?

Basically do something like this:
(inside the function)
SDL_Rect* tailHitbox = new SDL_Rect();
SDL_Rect* headHitbox = new SDL_Rect();
[...]
vector<SDL_Rect*> bodyHitboxes;

(when you don't use them anymore, you just run a loop like this)
for(i = 0; i < your_vector_with_hitboxes.length; i++)
delete(your_vector_with_hitboxes[i]);
>>
>>53904875
I forgot, when you delete the memory allocated for each item in your vector, remove the pointer from the vector, if you don't want to have a beautiful segmentation fault.
>>
>>53904815
It's the canonical example of undefined behavior anon!
I checked: g++ build -Wall stops it. Make America great again!
>>
Hello dear friends.
I'm doing a quiz for my 1st year uni assigment in java and hit a roadblock.

I've decided to go with a JTabbedPane approached where you can click between panes to select which question you want.

I got that part working, but how could I make the buttons in the quiz increase a counter when pressed?

They are all generated with a if loop where the panes will make as many array entries there are.

I can post code if you guys want/
>>
>>53904875
>using delete with parentheses
>using delete at all
maybe OP is a bit retarded, but your suggestions are fully retarded, so...
>>
File: not today.jpg (69 KB, 447x453) Image search: [Google]
not today.jpg
69 KB, 447x453
>>53904873
>you even added const to make it compile, didn't you?
I added const because as I learned (from 4chan) that a const reference is the fastest way to pass a vector.
Like I said, this is the first time this code has given me issues. I've used this before and I've never had any problems.
>>
File: Absolutely-disgusting.jpg (74 KB, 720x540) Image search: [Google]
Absolutely-disgusting.jpg
74 KB, 720x540
>>53904924
>uni
>>
best way to implement logging in c++?

have a global inline function that adds text to a macro and have a non-critical thread eventually get around to emptying the vector and printing the text to a file?
>>
>>53904961
if you consider yourself competent enough to use C/C++ you should RTFM
>>
#dpt on irc.freenode.net

gogogo
>>
>>53905034
adds text to a vector* (or some basic logging data structure containing text and like a flag, same thing)
>>
>>53904972
:)

No seriously, I don't even want you guys to make the solution for me, maybe point me in the right direction
>>
>>53904961
>I learned (from 4chan) that a const reference is the fastest way to pass a vector.
Strawman, albeit an involuntary one. I remember being super pedant with an anon about returning. This was in vain.
>>
>>53902271
well, the C11 standard has something for threads, but compilers aren't required to recognize it, so gcc will start bitching if one of the files you feed it has that in it.
>>
File: kawaii-rms.png (185 KB, 298x360) Image search: [Google]
kawaii-rms.png
185 KB, 298x360
>>53904783
Why did you pick worst girl anon
>>
>>53902961
tldr
>>
>>53904923
>/g/
>trump supporters

Why am I not surprised?
>>
>>53904961
>a const reference is the fastest way to pass a vector
For input, a const reference is the fastest way to pass input data to a function that will not change the data. To me, it looks like you were returning a local non-const variable as const, then doing non-const things with it after it fell out of scope.

We can only see that part of your code, but it seems like there are some things you may want to restructure.
>>
File: dumb bitch BTFO.png (307 KB, 492x449) Image search: [Google]
dumb bitch BTFO.png
307 KB, 492x449
>>53905146
fag
>>
How did you guys get your first big project off the ground?

I've been programming for a while so I got the basics more or less down, but I can't do anything more than some little fun tools, bigger projects just go over my head.
>>
File: truth.jpg (39 KB, 460x259) Image search: [Google]
truth.jpg
39 KB, 460x259
>>53905146
Because it's not surprising? We are concerned literates fyi
>>
File: Selection_056.png (20 KB, 727x97) Image search: [Google]
Selection_056.png
20 KB, 727x97
>>53905046
well i tried
>>
>>53904961

>a const reference is the fastest way to pass a vector
For function arguments. NOT for return values, dipshit. You should never under any circumstance RETURN a pointer or reference to something sitting on the stack.
>>
>>53905146
Trumps stance on H1-B visas should be appealing to this board and also /pol/ is part of this site.
>>
>>53905187
What is a big project to you?
>>
>>53905241
fizzbuzz
>>
>>53905187
just

DO IT

https://www.youtube.com/watch?v=5-sfG8BV8wU

but seriously just get to it, don't be afraid to try things, and keep at it, don't give up
>>
>>53905212
Object* myObject;
myObject = someFunctionThatReturnsAnObjectPointer();


What about that?
>>
Trying to brush up on Python as I never use it. Just decided to make a silly little Go Fish game/"AI" opponent.

For the AI opponent, my goal is for it to ask for a number that they have the most of. For example, if their hand is 4d6s8h8cJs, they would ask for an 8.

How I'm trying to doing it is sorting the hand by number, then keeping a count of how many times we've seen the current card's value, if it's bigger than the current max, set it as the max, if the card value is different, set counter back to 1.

So, it would go through the previous hand like

4d - 1 4 - set max to 4
6s - 1 6
8h - 1 8
8c - 2 8 - set max to 8
Js - 1 J

and then it of course would ask for an 8.

It might be my lack of familiarity with Python, but I'm not sure why the following code doesn't implement that correctly:

        for i in range(0, len(self.hand)):
# Sort hand according to value
self.hand = sorted(self.hand, key=lambda tup: tup[0])

last = current

# cards are tuples of value and suit, i.e. ('K', 'club')
current = self.hand[i][0]

# If we're still counting the same value
if current == last:
currentcount += 1
# If we're on a new value now
else:
currentcount = 1

# If our current count is bigger than the max
if currentcount > maximumcount and current != self.last_ask:
maximum = current


I'm not quite sure where it goes wrong, I can post a sample run if that would make it easier. Thanks guys.
>>
>>53905222

His stance on cryptography is not appealing. His belief that you can or should "shut down a part of the internet" to get ISIS to be unable to use it, is retarded, and deserving of a bitch slap.

I do not want either Trump or Hillary to be the next president of the United States, because they're both tyrants who think they should have a right to regulate the Internet.
>>
>>53905197
kek'd
>>
>>53905046
>freenode
>>
>>53905325
No one running for president understands the case for cryptography but when they start getting advised on the topic they take back their stance. Lindsey Graham did exactly this and he is one stubborn person.
>>
>>53905046
why freenode
>>
>>53902106
Someone starred one of my repositories last year, but I don't have any stars under "Your stars." What's going on?
>>
>>53905438
idk it's just what I had open
>>
>>53905455
Your Stars is for things you starred. To see who starred your repo, click on the number of stars it has while viewing the repo.
>>
>>53905288
What you need to do is learn the difference between the stack and heap. That'll solve all your questions
>>
the main function is inside a fucking class
>>
I have several txt documents and need to make a search and sort program using the data in the files, the only problem is the data in these files is fragmented so I have a file for the average hours of sunlight in a month listed in the order they were collected, then another for the average rainfall in a month listed in the order it was collected, etc.

Is there a way I can take each line of each file and link them together with the same corresponding lines so I can seaarch throught them, sort them or ourput them on the console?

Will I have to use multiple arrays?

It's C# by the way.
>>
>>53905288
If that returns the address of an object that has fallen out of scope, then it is illegal. If the object was stack-allocated in that function, then this code is NOPE.

Dynamic allocation allows one to control the scope. If the object was dynamically allocated and is still valid, then that code is fine.
>>
>>53905288

No, do it like this:
Object myObject = someFunctionThatReturnsAnObject();


Let me explain with some code...

#include <iostream>

struct Foo {
double a;
double b;

Foo(); // Base constructor
Foo(const Foo& other); // Copy constructor
};

Foo::Foo() : a(0.0), b(0.5)
{
std::cout << "Normal constructor called" << std::endl;
}

Foo::Foo(const Foo& other)
{
std::cout << "Copy constructor called" << std::endl;
}

Foo someFunctionThatReturnsFoo(double d)
{
Foo f;
f.a = d;
std::cout << "Address of f in func: " << &f << std::endl;
return f;
}

int main()
{
Foo f = someFunctionThatReturnsFoo(1.0);
std::cout << "Address of f in main: " << &f << std::endl;
return 0;
}


This outputs (on my machine):
Normal constructor called
Address of f in func: 0x24fe40
Address of f in main: 0x24fe40


You may be wondering why they have the same address, and why the copy constructor is not invoked when you are returning an object. The answer is that the compiler is allocating the stack storage for the Foo object in main, and constructing it in place in the function that returns the object. Or it is memcpying it. Either way, the copy constructor is never invoked, despite being non-trivial.
>>
>>53905529

File.ReadAllLines
>>
>>53905289
1) The Counter module in collections might help you simplify your code.

2)
last = current
shouldn't run because current has not been defined yet.

3) Why are you sorting the hand in every iteration?

4) Where was currentcount defined?

5) You can replace
range(0, len(self.hand))
with
range(len(self.hand))


6) I'm not sure what the problem is with your algorithm (or exactly how your algorithm is supposed to work), but I would suggest either 1) using the Counter class mentioned above; or 2) getting the number of times that the hand[i] by comparing ti to hand[i-1]. If the two are equal, increment currentcount, else update maxcount if currentcount > maxcount.
>>
>>53905527
>javafags will defend this
>>
>>53905588
you're giving this kid way too much help.
>>
>>53905588
 Object myObject = someFunctionThatReturnsAnObject();/
 always looked cancerous to me because it *felt* like you make a variable on the stack myObject, then call a function that returns another variable that is then copied to the one you already made, but of course the compiler knows better than I do. I've always preferred the pointer way though
>>
>>53905527

Fact: You can write a C# program with no classes.
>>
>>53905529
>Is there a way I can take each line of each file and link them together with the same corresponding lines so I can seaarch throught them, sort them or ourput them on the console?
Yes. Yes there is.

If they are both from the same time period, and they both have the same ordering, then the date/time should be enough to make things easy.

>>53905529
>Will I have to use multiple arrays?
I probably would at first during the reading phase, but I would consider making a class or struct that keeps the bits of data together would be a better idea. Depends on what you have, but it sounds like you have sunlight and rainfall data that is keyed by day/date?
>>
>>53905635
yo dog I heard you liked code in your code 
so I put code in your code so you can code while you code while you code
while you code
>>
>>53905611
Thanks a bunch anon!
>>
>>53905650
we're 
reaching recursive levels of memes
>>
>>53905650
wops
>>
>>53903238
4 = {0 1 2 3} = {0 {0} {0 {0}} {0 {0} {0 {0}}}}
Ordinals are pretty.
>>
>>53905718
it's a  tangy kind of
forced meme
>>
>>53905529
I've found C# is absolutely great for these kinds of tasks.

You could probably find a fancy way of using LINQ to query all the lines and zip them up into a single list if you wanted to. But it's probably easier to query each property as a separate list to start out.

There's ways to doing everything you're asking. Start with reading it in as a list of strings, and then start googling each specific task you want to accomplish next. Then ask questions if you can't figure it out after doing that
>>
>>53905640

Are you writing main inside of a struct instead? Or can C# actually do top level functions like, say, F#?
>>
File: Untitled489030.png (59 KB, 1920x994) Image search: [Google]
Untitled489030.png
59 KB, 1920x994
Front-end for DNS in LDAP
>>
How do I fizzbuzz in Kodu?
>>
File: example.png (43 KB, 536x746) Image search: [Google]
example.png
43 KB, 536x746
>>53905609
So that will assign the contents of each file to a string array? But how do I link each array together? Someone else recommend

>>53905643
It's ordered like pic related.

>>53905795
Thanks fo the LINQ rec.
>>
>>53905797
>Are you writing main inside of a struct instead?

Don't give away the answers, you fuck. You already knew this because we had this exchange last time I said you didn't need to use a single class.
>>
>>53905907
[sub]is this[/sub]what i think[sup]it is[/sup]


inb4 it isnt
>>
Reminder that goto is for professionals
>>
>>53905882

You could turn that into an array of structs once you've read it in

new Thing(year[i], month[i], rain[i], sun[i]);
>>
>>53905912
>boohoo someone ruined my babbys first programming facts question
>>
>>53905960
disgusting repetition
>>
>>53905951
Reminder that all code eventually complies to have various jmp instructions, which are basically gotos.
>>
>>53905912
You seem mad, dear tripfaggot. Calm down.
>>
>>53906002
Reminder that the concept of function calls ruined programming forever
>>
>>53906025
What else do you propose? SQL-like declarations?
>>
/dpt/ I am looking for an open API that I could use to develop an app to study.
Could you guys suggest me one?
>>
Now with more constructors and a destructor

#include <utility>
#include <iostream>

struct Foo {
double a;
double b;

Foo(); // Base constructor
Foo(const Foo& other); // Copy constructor
Foo(const Foo&& other); // Move constructor
Foo& operator=(const Foo& other);
~Foo(); // Destructor
};

Foo::Foo() : a(0.0), b(0.5)
{
std::cout << "Normal constructor called" << std::endl;
}

Foo::Foo(const Foo& other)
{
std::cout << "Copy constructor called" << std::endl;
}

Foo::Foo(const Foo&& o) : a(std::move(o.a)), b(std::move(o.b))
{
std::cout << "Move constructor called" << std::endl;
}

Foo::~Foo()
{
std::cout << "Destructor called" << std::endl;
}

Foo& Foo::operator=(const Foo& other)
{
a = other.a;
b = other.b;
std::cout << "Assignment operator called" << std::endl;
return *this;
}

Foo someFunctionThatReturnsFoo(double d)
{
Foo f;
f.a = d;
std::cout << "Address of f in func: " << &f << std::endl;
return f;
}

int main()
{
Foo f = someFunctionThatReturnsFoo(1.0);
std::cout << "Address of f in main: " << &f << std::endl;
return 0;
}


And our output is...

Normal constructor called
Address of f in func: 0x24fe30
Address of f in main: 0x24fe30
Destructor called


All constructors and destructors here are non-trivial, and yet the result still suggests that returning a struct by value does not invoke any constructors or destructors. Conclusion: you should be returning structs by value.
>>
>>53905995
>babbys first programming facts

Not really, it's just a fun little fact. As far as I know, it's not actually mentioned anywhere that the entry point can be within a struct.

>>53905998

No ur mum
>>
>>53906025
How?
>>
>>53906022

Not mad, Ruby's just not playing along.
>>
>>53906049
This is what I don't like about C++

>Foo()
>Foo(const Foo&)
>Foo(const Foo&&)
>>
>>53906070
And that's why most people hate tripfags. Circlejerk drama, even if it's a party of two.
>>
File: Time4Programmingx.gif (478 KB, 500x250) Image search: [Google]
Time4Programmingx.gif
478 KB, 500x250
>>
>>53906117
>sleeping when you could be programming
>>
>>53903552
>the admin is a lonely tranny neet
So, your average /g/entooman
>>
>>53906130
Her dreams are algorithms
>>
>>53906051
Is there actually a difference between structs and classes other than the default member visibility?
>>
>>53906130
not all of us have drugs, anon
>>
>>53906142
aren't we all trannies here?
>>
>>53906101

You won't like Rust.
Thread replies: 255
Thread images: 39

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.