/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Bad alloc exception:

Attached: 1547156513084.jpg (2335x2507, 685K)

Other urls found in this thread:

mega.nz/#!eBR3BAxI!bIMPnbPQCrYSCI7ljS3LoqPXJFyWqwJAiq1Nzd7U9oM
stackoverflow.com/questions/11620959/making-an-indexed-control-array
asm.ow2.io/
youtu.be/kdxAkCpKkbY
twitter.com/SFWRedditGifs

First for fuck anime.

I'm doing the Princeton algorithms course on Coursera. Anyone have any thoughts on it?

I like the Stanford one

Stackoverflow top voted reply on C++
//Instead of
for (int x : container)
//use
for (int &&x : container)
//it is more efficient

Stackoverflow top voted reply on Java
//How do I get the default window color back?
//Dude just use this:
frame.setBackground(new JFrame().getBackground());

How does a threaded bytecode intepreter work?

So far I have done the classic shit
unsigned char opcode = rom[pc++];
switch (opcode)
case load_constant:
...etc.

but you can store addresses and jump to labels or some shit?

>C++
while (x --\
\
\
\
> 0)
printf("%d ", x);

that probably won't even work

>int &&x
What?

>C++
kek

Attached: kek.png (698x51, 4K)

There is only one thing left to do

Write a C++oC++?

In python, why use
for foo in enumerate(bar)
instead of
for foo in range(len(bar))
?

How do you trust random github projects to not have some kind of keylogger hidden in it?
I feel like most people just blindly download it, then give a star for them
Also why the fuck are people allowed to delete history
>make autoupdate feature for your legit program
>one day decide to download some malicious shit to all the faggots who cloned your repo
>change the code back to original and delete history so nobody will ever know lmao
yeah right fuck github niggers

i dont really understand what you said but it sounds like you dont know how git works

1. len won't work on unbounded iterables, enumerate probably will
2. you can unpack the tuple from enumerate instead so you don't have to pull it out of the iterable using the index

Uh I thought C was supposed to be good at efficiency?
What do I need this boomer language for if it is not even possible

Attached: cbtfo.png (683x421, 30K)

>ANSI
time to update to UTF8, grandpa

>frame.setBackground(new JFrame().getBackground());
Does this allocate/create a whole new java gui window just to extract its default window color?
I hope that's just a joke answer.

it's efficient in terms of the resources if uses at runtime, writing it is not efficient

Yes, we must preserve Linus in a technically living state forever.

>implementing ... efficiently .. not possible
the implementation will not be efficient in C.

Just on the surface of it range(len(bar)) is hella ugly. That's reason enough frankly.

how is implementing not writing

why do you trust your browser or OS or ssl library, all written by strangers who very well might be getting paid secretly to introduce undetectable backdoor-facilitating bugs?

heartbleed was one line of code that went unnoticed for 2 years, during which time god-knows-how-many people exploited it.

at some point you have to trust other people to get any fucking work done.

You're assuming this source is true in this narrow sense you've defined, contrary to just about every piece of evidence available.
You should reconsider your interpretation or reconsider the validity of the source.

>ANSI C
That's a very old standard revision, you mong. C11 has threads.h.

Hello /dpt/.
I have a school assignment to reverse engineer a compiled java .class file using the Reflection API.
I am comfortable using reflection, but I only have experience using it with.java files.
How would one go about accessing a compiled .class java file so that one could use reflection methods on it?

put it in your classpath and use reflection apis on it like any other class?

ANSI C is the only C. Don't let the other faggots tell you otherwise they want another language and using new standards will slowly morph C into something resembling C++ or maybe even JS.

Who needs threading any way?

Something like this?
I've tried putting the .class file in the bin and src.
What I've got running at the moment is adding the .class file by "adding an existing file"

Attached: 2019-04-10 20_17_52-eclipse-workspace - IT7374_Assignment1_2173244_src_Task1_ReflectionDemonstration (969x318, 33K)

i doubt an IDE will let you use raw .class files, i think some will decompile them for you but if you want to use it directly i'd use the cli

Which is faster, calculating 2 x 100 or 100 x 2?

Maybe I'm not understanding my assignment then, because my tutor only ever makes us use Eclipse and he only supplied a .class file to use.
Maybe I'm supposed to write a java class which is similar to the supplied .class file and reverse engineer that.

I really like this chapter in Christer Ericson's Real-Time Collision Detection book.
mega.nz/#!eBR3BAxI!bIMPnbPQCrYSCI7ljS3LoqPXJFyWqwJAiq1Nzd7U9oM
But I'm just wondering, aside from algorithms is there anything I'm missing from this chapter? A topic preferably. Or would it all just be platform specifics? It's fairly old now so I'm wondering what has changed.

just find out where eclipse puts your compiled .class files and put it in there with them

if you do this, you'll still get the red squiggles in your IDE, it won't know what you're talking about, and it'll probably delete the file when you do a clean so be careful

man ides are more of a pain than they're worth

I've done this, I put it in the bin folder with my other compiled .class files.
But Eclipse doesn't automatically pick up on this so I'm not sure if I need to do another step or I'm doing the completely wrong thing.

Compiler will optimize both to the same and realize it can do *2 as a bit shift.

It depends.

Could somebody tell me why Wt's documentation is just two chapters that tell me nothing?
Am I just a brainlet?

if you want hand holding from your IDE you can try pack the class file into a jar file (which is basically just a zip file with a specific directory structure) and add the jar file as a dependency through your IDE
i dunno how you'd figure out the directory structure without knowing what package the class file is in though, you might be able to figure it out by opening the class file in a hex editor or something

computed gotos do not exist in the C standard,
you cannot get a pointer to a label
this functionality only exists in the compiler
therefore it is not part of the C language.

When you are using gcc to do shit that is not defined in the C standard you not writing C, but something else.

Which is why the C language is absolute terrible garbage, but the compilers are good.

Attached: outoforder.jpg (530x325, 39K)

I'm working with RMI in Java, I hate the fucking thing but it's for uni and I get an exception when using it.
I have Java in the Oracle 11 version, not OpenJDK, which apparently causes problems.
I have done some easier examples of using RMI and they worked, now I have to do some mirrored servers that know each other and work together to offer the service, in this example it's donating money, so each mirror takes donation for half the clients, so when someone register the servers check which one has the least clients and that one register the client so that client later contact with that server.
This is the stack print trace, I will upload a photo of my code in a minute.

Attached: fuckjava.png (1132x245, 58K)

The code is in partly in Spanish but I can translate some variables to make you understand it.
codigoDevuelto = returnedCode (a code that should say if the method worked or not)
server = the host it's going to connect to
nombreObjectoRemoto = remoteObjectName (the name of the service, use this variable to bind it too)
Then the println are some basic things to know what the program is doing from the interface.

Attached: fuckjavax2.png (884x360, 31K)

This is the remote method that the mirror has to call, the idea is that you get the IP from wherever you are being called and create a stub for the server.

Attached: fuckjavax3.png (883x263, 24K)

This are the option I'm using to execute the programs, I execute one without IP that simply bound the service to RMI, then I execute the other with the IP as a parameter, so once the service is bound it calls the other.
Both are bound when I sinchronize them.

Attached: javaIsShitPlsKMS.png (1117x486, 116K)

And as you already know if you know RMI I execute "rmiregistry &" before since it wouldn't be bound otherwise, so I don't know what's the fucking problem.

>using static methods instead of creating new objects for everything
This isn't OOP señor

Those methods aren't static, my only static method is the main, they are sinchronized methos which are a different thing.
Also, it makes sense to have only a class for the server because it has very simple functionality.
Also, I don't even care about OOP or not.

first thing i'd check is: is anything listening to the port that the program is trying to connect to?

you can't compare strings using ==

>first thing i'd check is: is anything listening to the port that the program is trying to connect to?
Doubt it, I'm using Virtual Machines to do the tests, they have nothing running except firefox (to download the code), how would you check it?
>you can't compare strings using ==
I'm comparing int

i don't know anything about rmi but did you not need a rmiregistry running for the examples?
>The RMI registry is a simple server-side bootstrap naming facility that enables remote clients to obtain a reference to an initial remote object

I already said here that I had the rmiregistry running.

Do you have a typo in your variable?

Look at the proxy for unknown source. You probably shouldn't have $Proxy1 in a string

Currently teaching myself c# ahead of course for an apprenticeship, attempting to make minesweeper in a windows form.
I'm using a picturebox array for the 'cells', but because they're not individually named I'm having trouble assigning image swaps and mouse functions (I don't feel like writing hundreds of names).
Is there a way to write incrementing names (during the creation loop, for example) ?

I'm using a IDE so no typos since the variable wouldn't highlight.

>Look at the proxy for unknown source. You probably shouldn't have $Proxy1 in a string
I don't understand what you mean by this.

see if it's listening on the port you're trying to connect to, 1099 is the default
you can check with sudo netstat -tulpn or sudo lsof -i -P -n | grep -i listen

Array syntax?

stackoverflow.com/questions/11620959/making-an-indexed-control-array

$Proxy1 is suspicious to me, although I am not a Java programmer

Look for
"com.sun.proxy.$proxy1" unknown source

That's in Java libraries, I shouldn't touch that, I'm googling it now but I can only find solutions of errors I'm not comiting, like not casting the interface but the implementation.

There's rmiregistry in the 1099 port, also when you execute rmiregistry if the 1099 port is occupied you get an exception, so it shouldn't be that problem.

var cellField = new PictureBox[10,15];
for (int r = 0; r < 10; r++)
{
for (int c = 0; c < 10; c++)
{
cellField[r, c] = new PictureBox;
...
}
}

Dear God code is painful to write while phoneposting
I'm noticing there's no direct way to array controls, or are the answers about creating one for all cells best?

Forgot to say, middle section gives attributes (size etc)

What the actual fuck

Attached: 1549575124204.png (1271x673, 443K)

rust users always manage to find new ways to disappoint and disgust me

>you will NEVER work at Bell in the late 70s

Attached: 720125.jpg (540x960, 184K)

is that saber

I don't know
anime is for homos

it's saber but armless

Welp I just made it work suddenly, all I had left to do in the event was assign the sender properly.
Now I have to figure out how to assign the values/mines properly, I'll try to figure it out myself though

so many cute girls (male), though, 1/4 talks are good fap material

give example

That wont work,
if you use JavaFX, you set the scene to something like:
Scene scene = new Scene();
scene.setFill(Color.BLACK);

JFrame is Swing and there is another GUI called AWT that you can use. they are shit desu.

>reverse engineer a compiled java .class file using the Reflection API
thats fucking stupid use the ASM library
asm.ow2.io/

youtu.be/kdxAkCpKkbY

RUST

the language for ponies trannies and pedophiles

you have to use URLClassLoader

I'm about to write a library to help me in some C projects.

Is it worth making a ton of smaller libraries with a bunch of headers, or just one huge one?

I need a 2D engine that has rigid body physics and can be used with C++.
Unity is C#
Unreal is bloated as fuck and does not even have it as far as I'm aware.
Godot does not have 2D rigid body physics,

Any Ideas?
In the worst case, I will have to write it myself with box2d...

it's easy to make your own 2D engine

Sorry, I am retarded I mean RAGDOLL, RAGDOLL physics.

>Is it worth making a ton of smaller libraries with a bunch of headers, or just one huge one?
We don't know what you mean by "ton", "bunch", etc.
Try to make libraries that group your functions logically.

Yes, I have set up one already. It's really not that hard.

However, what is not easy is to create is a whole asset creation pipeline for rigging 2d characters with bones and shapes. It's just an insane amount of work.

Horse cartoons are programming related. Just kidding they're normally a ban on sight, even in desktop threads.

Attached: 1551843834024.png (3000x2584, 278K)

make a simple, textual file format for defining rigs and then make a basic tool where you can place/export them
shouldn't take more than a few days
you should get used to do shit like that if you're using C++, if you don't want to bother with it just use Unity and C#

BACK, not black. "How do I get the default color BACK?"

>you shall not pass

Attached: 1538041407615.jpg (400x400, 32K)

Yea, that was my worst case scenario.
Guess I will have to do it like that...

What about Box2D?
I think I will just use it for physics then. Is that a good Idea?

while(x)
printf("%d ", x--);

This is idiomatic C. Much cleaner.

you thought there were only lvalues and rvalues?

>a glvalue (“generalized” lvalue) is an expression whose evaluation determines the identity of an object, bit-field, or function;
>a prvalue (“pure” rvalue) is an expression whose evaluation either computes the value of the operand of an operator (such prvalue has no result object), or initializes an object or a bit-field (such prvalue is said to have a result object). All class and array prvalues have a result object even if it is discarded. In certain contexts, temporary materialization occurs to create a temporary as the result object;
>an xvalue (an “eXpiring” value) is a glvalue that denotes an object or bit-field whose resources can be reused;
>an lvalue (so-called, historically, because lvalues could appear on the left-hand side of an assignment expression) is a glvalue that is not an xvalue;
>an rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is a prvalue or an xvalue.

modular, always

>However, what is not easy is to create is a whole asset creation pipeline for rigging 2d characters with bones and shapes.
Flash did it a lot. Vector graphics, or just bitmaps, hitbox/limb.

Don't be a twit about it, you can have all the limbs/animations separated, attach hitboxes in a parent-multi-child way, and move along.

If you even wanted to, use a 3D application with stuff snapped to 2D, in an isometric/othographic view. 3D graphics would inherently have skeletal animations, and if you wanted to, non-stiff bones, 3d effects, etc.

If pure 2D doesn't work too well (z-depth fighting), just make the prisms with an inch or two of depth and ignore Z collisions/movement

I've never used it, if it's popular I assume it is fine, it's a waste of time to try and write your own rigid body physics because it's complex and you will never make an improvement over existing tools because it's all well-researched, actual math

>an xvalue (an “eXpiring” value) is a glvalue that denotes an object or bit-field whose resources can be reused;
Resources should be re-used by default. Fuck dynamic metafactories over the androgynous monorails.

kek, it's been so long since i've seen this, back then we used to hate the bronies and now it's trannies and SJWs

>you can have all the limbs/animations separated, attach hitboxes in a parent-multi-child way, and move along.
No, you can't.
If only it was that simple.

You have to add the class as a library.
Put it in a zip file, rename it to .jar, then right click on the project, build path -> configure build path, add jar

Disagree, it's better to Inc/decrement in the loop condition. The more loop invariants the better.