/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

reddit.com/r/rust/comments/7lq5t3/featurenll_available_in_nightly/drowto0/
twitter.com/AnonBabble

Threadly reminder to use #![feature(nll)].

int inodes;
int inodeCount;
int nrof_inodes;
int nrInodes;
int n_inodes;

Which variable name is best. Any better suggestions?

inodes_count

Threadly reminder not to use Rust.

who is this semen demon?

i am a girl btw

a girl(male)

>pair of legs

Sup Forums will get off to anything.

In the next 10 years will it even be possible to find a programming job? It feels like programming is slowly fading away, like it won't be useful.

Yes, but only if you start learning Rust today.

wow nice can u be my gf and clash penises?

Im making a game with a tilemap in java with Slick2D, but my character keeps glitching through the floor. It only happens if he's accelerating both downwards and in a sideways direction.

My current method of detecting which side of a square was hit involves turning the square i collided with into 4 triangles, then checking which of them my characters hitbox is in.

I thought the problem was what i have in the picture (black=player, red=collidedBox), but even after making it so that hitting the top 2px of a box always gives "top", it isn't working.

Are there anyone here that can help me?

At what point in your game loop are you doing the collision detection? Perhaps do it earlier

...

im doing it after applying movement. i don't think swapping them would do anything tho

I have a "final solution" kind of thing worked out, but im unsure if its good practice or not.

Right now the highest tier Entity class handles hitbox detection, but i need to go one subclass lower for physics to be available. I'm thinking of doing the advanced hitbox detection in the mobile entities instead, and using instanceof in my main loop to check which version of the hitbox detection i need to use.

What exactly did you expect? You move diagonally fast enough, so the corner of your character ends up in the rightmost triangle, so instead of getting pushed up and out of the floor, you push the character to the right and further into the floor.

I get that that was a problem. I made it so the top part of every box gives "top" to fix that problem, but it still isn't fixed.

That's why im confused.

>I made it so the top part of every box gives "top" to fix that problem, but it still isn't fixed.
I just told you: if you move diagonally, the corner may very well end up in the right or left part of the box.

>Look at me I'm girl coder teehee.
Gas all women.

I don't see the problem.

i dont think you understand what i mean. basically, i added a line like in the picture, and made it so anything above that line gives "top"

>woman

Try setting it all the way to the bottom of the tile just to see that it works correctly. Then start raising it and see at what point the problem returns.

how did i not think about that.

appearantly it isn't working correctly at all. even with the whole box included in the line, i still get a lot of "bottomRight + topRight".

thanks user

Welcome. What you should really do, however, is to just see what tiles surround the one you're colliding with and cancel directions that push you into another tile.

>programming won't be useful
>the world is literally getting taken over by machines

trying to debrick mi4c i stole from my co-workers home
thing is so fucked up it doesn't show comports
battery seems to function alright and other hardware looked undamaged
interesting case

What's the difference between an array and a matrix?

should i learn programming if i hate maths?

array = [ 1, 2, 3 ]
matrix = [ 1, 2, 3 ]
[ 4, 5, 6 ]

basically an array is a 'line' of variables while a matrix is a rectangle

Have you just assumed their gender?

"inodes count" reads like English is not your first language. Should be inode count.
As for the best format:
val inode-cnt = sum-shit

obviously, read as something between "aye-node-count" and "aye-node-cunt" depending on accent and how srs bzns we're talking about.

But we both know your shitlang doesn't support the most key-ergonomic and readable identifier format - kebab-case.

>i am a girl btw
oblig
post prog-socks + feminine benis or gtfo

But in ordinary language, outside of programming, an array is almost always two-dimensional, isn't it?

bog-standard game physak problem - yer moving too fast
this frame yer in, next one yer out
google around for how this shit's solved properly

>should i learn programming if i hate maths?
No. If you "hate math", you'd probably be a female-tier programmer.

>bog-standard game physak problem - yer moving too fast
That's not the problem. The problem is that he treats tiles as if they exist in a vacuum instead of taking into account their vicinity.

I just wanted to update you, and everything is working correctly now, so thanks a lot. I messed around with this for ~5 hours yesterday, so im hella glad its over.

tee-bee-ef good tile patterns (and colors) are pretty sexy in a muh autism way

You're about to publish a C and/or C++ project, what static analyzer(s) do you run and what arguments do you give them before pushing to public release?

>Should be inode count.
That's what I wrote.
But you're right, English isn't my first language.

give it back, jamal

Well, now you have a problem with the left, right and bottom sides...

ah bollocks, saw too many "inodes" and me brain thought you'd written "inodesCount"
my bad
>English isn't my first language.
same here

>#![feature(nll)]
reddit.com/r/rust/comments/7lq5t3/featurenll_available_in_nightly/drowto0/

>>Segfault without using any unsafe component.

The absolute state of Rust.

>what static analyzer(s) do you run and what arguments do you give them
rm -rf projdir

and rewrite it in a language that ain't full of "implementation defined" and "undefined" behavior, and isn't a literal footgun
inb4 rast

But that would rob you of the sense of accomplishment when don't shoot yourself in the foot.

By the way, what you did with the triangles, it's called Voronoi regions. I don't know if you were working based on intuition or if you knew it for a fact, but each triangle is exactly the area which contains all the points inside the square that are closer to the corresponding edge of the square than all the others.

> fixed the same day
The absolute state of Rust.

I too, enjoy doing things in ways that are unnecessarily hard and round-about
to mask my incompetence
and feel accomplished when I don't make mistakes that a non-shit compiler should've taken care of in the first place

That is actually a neat dress

the friend function concept in sepples is all backwards

...

>the friend function concept in sepples is all backwards
I was thinking the same thing. In my upcoming Better C, I have enemy functions instead: you just mark functions as enemies using regex and then they can't access your insides.

that's pretty cool. i got the part about the corner points from another guy, but came up with the triangles myself, so i guess thats something to be proud about.

>tfw working on C++03 code
>tfw have to use std::auto_ptr instead of std::unique_ptr

>they can't access your insides.
that's pretty analphobic, user

no they all work correctly. the problem was about the top side sometimes being registered as a "right" or "left" when the detection happened far to the corner.

post the follow-up

>clean tiles
vs
>cracked, dirty, slutty tiles

I don't know what good that would do.

I was thinking that functions should be able to declare themselves friends of a class instead of having to modify the class with a friend declaration. I think that would be more usefull.

Jai isn't even released yet.

RAII is a poor idea anyway, but it's especially broken without move semantics. Please don't do this.

That's fucking stupid, because it means anything can break encapsulation.

Why are you forced to use C++03?

Well, it's still better than deleting the object by hand at every exit point, I'm not a C-tard after all.

>using meme languages
ishiggydiggy

No, no it isn't.

Exactly. If you're going to allow breaking encapsulation, might as well do it in a practically useful manner. The point is you'll still be doing it intentionally and not by accident.

I think you'd need something similar to your line fix for when you're sliding down a wall instead of walking across the floor, and then this breaks your first line fix, because now there's an area on the edge where one line fix says up and the other says sideways.

>RAII is a poor idea anyway

Implicit behavior is bad.
Exception-throwing constructors are bad.
Destructors which cannot report errors (e.g. I/O errors on closing a file handle) are bad.

RAII is not a silver bullet.

NSA should be proud, growing a subculture of smug self-righteous C-tards was its biggest achievement.

if 2 corners are both inside the players hitbox, it returns their common side.

example: player hugging a wall to his right, sliding down. for every frame he will move slightly inside the wall, which puts the topLeft and bottomLeft corner in his hitbox. since they share left, the collision will detect left, and he will be repositioned accordingly.

>sepplesfag bragging about safety

Forgetting to clean up resources, or splattering boilerplate all over the place, is worse.

Does anyone know what algorithm Sup Forums uses to generate tripcodes?

>Forgetting to clean up resources
What are you, retarded? Your own inability to keep track of your resources is not a compelling argument for adopting such a limiting idiom.
>splattering boilerplate all over the place is worse.
In what low level programming language is silently injecting arbitrary code at the end of every scope preferable to a single obvious and explicit function call?

Jai is pretty much what the original C should have been. It embodies the spirit of C much better than C does.

As a practical tool though, Rust is what most people who use C or C++ for new projects should probably be using, as soon as library support becomes good enough for their usecase

>for every frame he will move slightly inside the wall, which puts the topLeft and bottomLeft corner in his hitbox. since they share left, the collision will detect left, and he will be repositioned accordingly.
Sometimes you'll have it touching two tiles, having one corner in each tile. I guess you can do the same thing, though. Yeah, that should work.

>Your own inability to keep track of your resources is not a compelling argument for adopting such a limiting idiom.
Are you saying that it is always possible to keep track of resources at all times and all points in the project no matter how big it is?

> a single obvious and explicit function call
Do all your functions have a single exit point? How do you keep track of which resources should be freed, which you failed to create and which hasn't been created yet?

int n;

>Do all your functions have a single exit point?
Most of them do. The ones which don't can be made to have a single exit point with common resource-releasing code with goto.
>How do you keep track of which resources should be freed, which you failed to create and which hasn't been created yet?
Ideally a construct like defer is available for this. With template hacks in C++ you should be able to replicate something like defer.

Nope. That doesn't mean that tracking resource ownership with your type system (or even a naming convention) necessitates using RAII, if that's what you were implying.

the one on the left..

> The ones which don't can be made to have a single exit point with common resource-releasing code with goto.
I see.
> a construct like defer
Wait, are you a Go-tard?

>> The ones which don't can be made to have a single exit point with common resource-releasing code with goto.
>because apple can't code it means goto is bad
you're retarded

>Exception-throwing constructors are bad.
Not necessary for RAII, see Rust.

>Destructors which cannot report errors (e.g. I/O errors on closing a file handle) are bad.
Automatic destructors can throw and they do not preclude manual destructors. With an effect system, it's possible to make it a compile time error to not call the manual destructor in a situation where throwing is not allowed.

int n;
int m;
int k;

Very descriptive.

>goto fail
Are you saying this code isn't obviously wrong? Anyone who has written C for more than a week can look at code like
[spoiler]if (cond)
foo();
foo();
bar();[/spoiler]
and determine that it's incorrect.

>Wait, are you a Go-tard?
Not really fond of the language and I don't use it regularly. I don't think its approach to error handling is perfect, but I do think there is a lot to be learned.
Using defer to insert code at scope exit is generally preferable to automatic destructors because it's explicit and you can insert error handling code if the close function is capable of raising an error.

>Not necessary for RAII, see Rust.
This is correct and something I agree is an improvement in Rust's interpretation of RAII, but the topic was originally being discussed in the realm of sepples.
That said, I'm skeptical whether returning heavy objects by value from these static methods is as efficient as C style init functions.
>Automatic destructors can throw
No, they can't. At least not practically. In C++ throwing an exception in a destructor calls std::terminate if it isn't caught by the destructor. (i.e. it's as though it's declared noexcept)
In Rust a panic inside drop aborts.
>With an effect system, it's possible to make it a compile time error to not call the manual destructor in a situation where throwing is not allowed.
I'm afraid I'm not familiar enough with this topic to be able to say if what you're saying is correct but it seems like a useful thing.

Is there a difference between these functions?

int Get(){ return glob; }


const int& Get(){ return glob; }

The first returns an int by value (copy)
The second returns a reference to a const int

They'll behave pretty much the same.

An int is smaller and simpler than a pointer (and also does not complicate aliasing) so you should probably return by value in this case. For larger and more complicated objects like a vector you should consider returning by const ref.

The difference between const reference to T and just T is that the const reference will use a pointer* whilst just T will copy-construct it.
*if T is small like an int, the compiler might not even bother to use a pointer or a reference.

How do I define a macro in Lisp which has multiple "keywords"?

I want to call it like this:
>(repeat (print i) until (< i 3))
"repeat" and "until" is what I mean by "keywords".

I wouldn't even bother you guys about it but I don't know what to google.

>you should probably return by value in this case. For larger and more complicated objects like a vector you should consider returning by const ref.
Oh, right. Thanks.

>(and also does not complicate aliasing)
I don't know what this means. How do references complicate aliasing?

looks like the one on the right started HRT earlier

>mfw spent a total of 29 hours trying to solve the first assignment given at a python 2 protocol programming course I'm attending
I feel good for not giving up, but also stupid for taking this long to solve this shit.

const int& ref = Get();
std::cout