/dpt/ - Daily Programming Thread

Real Programmers Edition #7

Previous thread: What are you working on, Jow Forums?

Attached: wirth.jpg (200x250, 9K)

Other urls found in this thread:

blog.s-m.ac/ocaml-rust-ffi/
godbolt.org/g/VFBBWY
en.m.wikipedia.org/wiki/Entity–component–system
en.wikipedia.org/wiki/Name_mangling#C
gafferongames.com/post/fix_your_timestep/
web.mit.edu/alexmv/6.037/sicp.pdf
github.com/sarabander/sicp-pdf/blob/master/sicp.pdf
github.com/sarabander/
twitter.com/NSFWRedditGif

WiFi p2p daemon in Rust

Attached: 1*lOEJf3tEoWCHYoWEg69A7g.jpg (1600x1832, 165K)

How would I display data belonging to a multidimensional array in a C# table? The format is supposed to be:

//Empty - 1pm - 2pm - 3pm - 4pm - revenue
//Month

wtf nigger did you fucking damage your brain or something? lmao

Reminder that Chad in marketing makes more than you ever will.

Attached: final-tech-jobs-salaries-1aad.png (950x1908, 62K)

...

fuck you, candy-ass nigger

I'm using two for loops to iterate through the data, but there's gotta be a less spaghetti way to do this, right?

Attached: 1521313756127.gif (498x374, 902K)

>CS grad.png

graduating next semester, actually

desu i posted just to see if someone would code it for me. took me less than 15 minutes to do it myself, though.

faggit

Attached: 1521554311796.png (484x605, 163K)

*blocks your path*
blog.s-m.ac/ocaml-rust-ffi/

Why are there so many C# programmers that are dumb as bricks?

It's babies first programming language, it replaced Java in most universities.

I'm pretty sure C# and Micro$oft fandom correlates with dog ownership.

Attached: hplovecraft-cats.jpg (480x724, 166K)

lol that website's name makes me think of that shuttle that exploded with astronauts onboard

>loops
lmao
that's so 1960s
my fellow C hacker

Because C# was made for them. Worst of all is since the language tries to do everything (albeit badly), devs are so full of themselves.

I'm not even a C# programmer m8. This is just for some shitty course. I use Java and PHP.

Attached: 1525877685568.jpg (800x600, 39K)

>does two for loops in 15 minutes
>actually paying for that education

Automating this autism
static void Main(string[] args)
{
//take input from pipes or args and ask for input if there is none
string input = Console.IsInputRedirected ? Console.In.ReadToEnd() : args.Length > 0 ? String.Join(" ", args) : Console.ReadLine();
string output = String.Concat(input.Where(c => !Char.IsLetterOrDigit(c)));
Console.WriteLine(output);
}

How do I ask the interviewer whether I was rejected or not? I've heard nothing from him about two weeks. Seems like I have been rejected, but the guy who also works there say that at least half of the employees are fucking around on the vacation.

...

I'm a C# programmer and have a cat since I was a child.

send him a pic of your programming socks.

Luckily, I don't define my self-worth in how much money I make

Enjoy your brain bugs you cuck

Attached: Toxoplasma_gondii_Life_cycle_PHIL_3421_lores.png (800x1050, 268K)

>OMG SYMBOLS so EVIL my brains are going to explode
Why is Jow Forums full of brainlets?

Attached: 1507259674652.png (300x300, 9K)

It's mostly just the C programmers.

Attached: 1509887318116.png (1834x1200, 639K)

((())) is the only syntax you need.

>java has a bad synt-

>take input from pipes or args and ask for input if there is none
Is microsoft producing too many brainlets in the field of CS?

What language is this even

C was a mistake

(>>=) is all you need.

I'm almost certain this was made in jest.
Who doesn't have a domain complex enough that they wish their environment was simple?

data Block = Sep Int | Comp Int Int deriving Show
preprocess :: String -> [Block]
preprocess (
(\rec -> \case (\case x@(any isNumber -> True) -> (\((read -> a), (read . tail -> b)) -> Comp a b) . break (=='x') $ x;
(Sep . length -> x) -> x -> x):xs -> x : rec xs;
[] -> []
,) . filter (not . null) . (splitOn ")" = xs))
) = xs


What do you fellow girls think of my ViewPattern abomination?

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.

— Brian W. Kernighan and P. J. Plauger in The Elements of Programming Style.

What an idiot. Cats aren't displaying superior intelligence at all and through testing they've been shown to be inferior.
Lovecraft is just someone who loves the unknown. Cats don't show their motives, they don't possess honesty. Of course he would explain his bias favorably.
Also he clearly hasn't had a dog if he thinks dogs are always up to play.

I don't need to debug it because the type system proves it's correct.

>appeal to authority
CS is not for you

It doesn't.
Even formally proven programs are prone to logical bugs.
Your ignorance to such a basic fact is proof of your stupidity and worthlessness of your opinion.

As if that set of features is proven to be helpful.
You don't understand the difference in citing experience in lieu of better evidence and appeal to authority in a rigid debate.
Clearly not fit for any intellectual work.

Can I created a method inside an abstract class on Java that modifies the subclasses variables? I'm still learning how to Java and how to OOP.

I created a an abstract class called Movable that checks if object can ""move"", and change the position, and than I created subclasses called like Monster Player and NPC, and when I try to use ""move"" the variable for those objects don't actually change.

Am I using abstract class wrong? Shouldn't I use to cut it out how much repetitive methods I have?

This is a programming thread, not a CS thread.

Does Rust only use the name of the function to identify functions, or does it use the module it is in too?

of course it uses modules

You're citing an old ass text, which does not even fit the context (it's warning against writing hacky programs, not against using abstractions). Kernighan thinks many of these functional abstractions are very important and certainly will be more important in the future.

But how does Rust differentiate function names across modules and traits?

>Shouldn't I use to cut it out how much repetitive methods I have?
That's not really the greatest use of inheritance. If you can, you should use composition to avoid repeating classes.
In this case you might have an entirely new class that is only responsible for moving Movable objects.

OOP can become a bit ridiculous sometimes, and you have to create new classes and abstractions for every little thing if you want to keep your code clean.

>repeating classes
I meant repeating methods

give me an example? Clearly foo::function and bar::function are different. And Rust doesn't allow function overloading.

name mangling

Yes, does Rust automatically convert foo::function to foo_function?

How does Rust do name mangling?

I don't know if it's documented anywhere, but it looks quite a lot like C++ with its _Z prefix.

You can see an example of a mangled name here.
godbolt.org/g/VFBBWY

If you mean that the functions modify data in subclasses when defined then yes. But you can't define a function in any parent class that modifies the subclass fields.
You should probably post code for help.

Typically for oop games is entity component systems (ECS).
en.m.wikipedia.org/wiki/Entity–component–system
(look for appropriate resources for how to implement).

It's very likely what you want.

())()))(

Usually it's the compiler that does name mangling. In Rusts case it's llvm right?

That is the abstract class, after that I created Player, NPC and monster and extending Movable. I guess it won't work, I will try to understand a little more of composition like said, it seems to be simple for now.
public abstract class Movable {

protected int maxX;
protected int maxY;
protected int posX;
protected int posY;

public boolean canMove(int x, int y, int direction) {
// 0 north, 1, south, 2 west, 3 east
switch(direction) {
case 0: if ((x - 1) >= 0) { return true; } break;
case 1: if ((x + 1) = 0) { return true; } break;
case 3: if ((y + 1)

LLVM is the backend which generates the assembly from IR. I think I remember reading something that they use a hash of the function name or something for Rust, which is independent of LLVM assembly name allocation.

It appears that Rust mangles similar to how C++ does it: en.wikipedia.org/wiki/Name_mangling#C

Why then did Rust not allow function overloading for normal functions, but for methods? Like Go I suppose.

-ax

Hello /dpg/, don't know if this is the best place to ask or if I should ask amateur game dev general, but here it goes:
I am learning C++ and OpenGL, and am currently making a simple 2d game. I want to create a bullet graphic whenever the player left clicks. These graphics coords will be updated every x seconds using usleep so that it makes them move towards the enemy planes. My problem is that I call usleep inside a method that is called during display, which means that my player bullets time are tied to my game display, causing problems if I want to have two independent times (for example if player attacks are faster than enemy attacks), also high usleep times cause the whole game to wait, not just the bullets. How could I separate the bullet update time from the rest of the game?
My code is below
void update_player_lclick_attack()
{
for (std::vector::iterator it = PBulletvector.begin() ; it != PBulletvector.end(); ++it){
(*it).setY( (*it).getY()+g_bullet_offset );
}
usleep(g_bullet_offset_time);
glutPostRedisplay();
}
void draw_player_lclick_attack(){
glColor3f(1.0f, 1.0f, 1.0f);
for (std::vector::iterator it = PBulletvector.begin() ; it != PBulletvector.end(); ++it){
glPushMatrix();
glTranslatef( (*it).getX(),(*it).getY(),0.0f);
glScalef(10.0f, 20.0f, 1.0f);
draw_player_lclick_attack_graphic();
glPopMatrix();
}
update_player_lclick_attack();
}
void draw_enemy_plane(){
glColor3f(1.0f, 1.0f, 1.0f);
glPushMatrix();
glTranslatef(500,800,0.0f);
glScalef(100.0f, -100.0f, 1.0f);
draw_enemy_plane_graphic();
glScalef(-1.0f, 1.0f,1.0f);
draw_enemy_plane_graphic();
draw_enemy_plane_hitbox();
glPopMatrix();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(2.0f);
draw_borders();
draw_menu();
draw_player_plane();
draw_player_lclick_attack();
draw_enemy_plane();
glutSwapBuffers();
}

because rust is a shitlang

Why are the max values part of the entitiy? They seem like they should be part of the world?
Also canMove looks like it should be a stand-alone function.

>case 0
>case 1
>....
Use enums, pajeet

Are you a rock star developer?

Attached: j29xd9yo0tb11.jpg (800x764, 71K)

Because Rust has traits
enum ObjectConstruct
{
Default,
WithDims(u32, u32),
WithDimsAndPos(u32, u32, u32, u32)
}

#[derive(Default, Show)]
struct Object
{
name: String,
width: u32,
height: u32,
x: u32,
y: u32,
}

impl Object {
fn new(name: &str, options: ObjectConstruct) -> Object {
match options {
ObjectConstruct::Default => Object { name: name.to_string(), ..Default::default() },
ObjectConstruct::WithDims(w, h) => Object { name: name.to_string(), width: w, height: w, ..Default::default() },
ObjectConstruct::WithDimsAndPos(w, h, x, y) => Object { name: name.to_string(), width: w, height: w, x: x, y: x }
}
}
}

fn main()
{
let test: Object = Object::new("Object Name", ObjectConstruct::Default);
let test2: Object = Object::new("Object Name", ObjectConstruct::WithDims(100, 100));
let test3: Object = Object::new("Object Name", ObjectConstruct::WithDimsAndPos(100, 100, 50, 50));

println!("{:?}", test);
println!("{:?}", test2);
println!("{:?}", test3);
}

GIVE ME PDF TO SICP OR ELSE

Attached: 1509897214279.jpg (2048x1536, 126K)

What is the trait Show? Isn't the one to print them Display?

Here is an excellent post about how to write a correct game loop: gafferongames.com/post/fix_your_timestep/
Basically you want to run your game loop as fast as you can and render on every iteration, but your logic to run at a fixed rate. You do this by choosing a constant delta time (say 1/60 second) and on every frame you measure the time it took to render the last frame and add that time to a counter. Once the counter is larger than your delta time you update your logic.

web.mit.edu/alexmv/6.037/sicp.pdf

How difficult is making websites compared to actual programming?

Thanks bro, I'll check it out

depends on the website.

not difficult if you can live with the fact that, compared to actual programming, it's not structured at all and usually a giant mess full of dirty hacks.

This book is shit

>compared to actual programming, it's not structured at all and usually a giant mess full of dirty hacks.
This couldn't be more far than the truth.

Congrats in proving you don't know what you're talking about.

sure buddy ;)

Attached: Screenshot_2018-07-24-08-22-02-01.jpg (1438x2000, 625K)

t. code monkey

>glut
>fixed-function pipeline OpenGL
>std::vector::iterator it = PBulletvector.begin() ; it != PBulletvector.end(); ++it

good lord, man. you seriously need to update your learning material. use GLFW, use OpenGL 3.X, and for the love of god, learn modern C++. you can just do this:

for (auto& bullet : PBulletVector)
{
//...
}

Why are you giving the wors pdf ever? You can barely read the formulas.
Here is the superior version: github.com/sarabander/sicp-pdf/blob/master/sicp.pdf

>t. never worked with spring beans

>auto
Disgusting.

for (auto k: {1, -1, 3, 5}) {
}


wtf I love C++ now

are you retarded?

>manlets only make $76000
they just don't learn!

I want to see the type immediately when i look at the code.

Then do
for (Playerbuller& bullet : PBBulletvector) {
}

See now that's much better.

pick your favorite format
github.com/sarabander/

Attached: 1511609996220.png (1280x720, 1.14M)

>this is your brain on C

Attached: 1507635639067.gif (400x400, 216K)

Scala is dead, use Haskell.

I disagree, with auto it's a lot easier to change the type without resorting to templating clusterfucks.

>unironic autism

>use academic wankery

no thanks

why not

hey guys, i am developing a webapp using spring mvc + jpa and hibernate, does anyone know how to change the datasource at runtime?

He doesn't understand it

How do I report back to the main thread from a worker thread? a shared List which the main thread keeps monitoring?