What are you working on, Sup Forums?
old thread:
/dpt/ - Daily Programming Thread:
Other urls found in this thread:
gameprogrammingpatterns.com
discord.gg
tasvideos.org
youtube.com
en.wikipedia.org
yosefk.com
sourceforge.net
twitter.com
Lain is a fucking slut
anime != proper
No
Just stop
Here's the proper one, everyone:
>61564842
>61564892
If rust really not having a String::reverse function then you can always just add:
trait Reverse {
fn reverse(&self) -> Self;
}
impl Reverse for String {
fn reverse(&self) -> Self {
self.chars().rev().collect()
}
}
>having to implement basic things yourself
man its like im really using C
>2 threads
sort it out Sup Forums
Currently trying to make a bullshit mario clone with SDL in C++
I wish I had a better grasp on designing my codebase though. I keep wondering how physics should be done. I have an InputHandler, should that talk to some kind of PhysicsHandler?
Are Rust strings used in UTF-8? Then it is non-trivial to reverse a string because there are multi-byte characters.
>waaah why do I have to write a one line function
Anime or screencaps of code are the only acceptable /dpt/s
Hijab and Koding shit is not
>InputHandler
>PhysicsHandler
so this is...
the power of...
OOP...
lol, this was literally my final project in graphics class
everything has a hitbox. something isn't hitting something, it's falling.
let reversed: String = my_string.chars().rev().collect();
in python this is just
reversed = reversed[::-1]
Cut out the unnecessary oop shit. The ONLY things you should have for oop are the blocks and the enemies. Things with both unified-interface behaviors and state. Not sprites. Not menus. Not mario even. Not "InputHandlers" not "PhysicsHandlers."
Have a loop that looks something like this:
int player_x; //Protip these should have subpixel precision. Mario bros uses 256 coordinates per pixel
int player_y;
int dz;
int dy;
void loop() {
while(game_running) {
apply_gravity();
if(letter_pressed('d'))
dx+=acceleration_speed;
dx = clamp_speed(dx);
x += dx;
//.... blah blah blah
}
}
t. minecraft clone guy
>256 coordinates per pixel
?
In python this is just
>uses tons of memory and has to allocate fucking integers on the heap
In brainfuck that is just
>,[>,]
>Cut out the unnecessary oop shit
Am I being meme'd on by this fuck then? gameprogrammingpatterns.com
Honestly, I feel the more direct way makes sense anyhow, but I thought if I had to live in a world of OOP, maybe I should learn to implement "proper design patterns."
def foo(str):
... return str[::-1]
assembly code
2 0 LOAD_FAST 0 (str)
2 LOAD_CONST 0 (None)
4 LOAD_CONST 0 (None)
6 LOAD_CONST 2 (-1)
8 BUILD_SLICE 3
10 BINARY_SUBSCR
12 RETURN_VALUE
Mario games (most games) use euler integration for physics. If game physics position was merely what pixel was occupied then it would be too inaccurate to be playable or fun.
Since mario's 8 bit they do something like this
int x;
int x_subpixel;
void integrate_x(int speed) {
x_subpixel+=speed;
if(carry_flag_set()) {
x += sign(speed);
}
}
For those who want more instant feedback, we have an unofficial Discord where we make an attempt to discuss programming:
botnet
discord is trash, use irc
Command pattern is great but it's functional programming. The classes used to implement it are a vestige of oop languages either not having first class functions or dogmatism about objects.
I wouldn't worry about the command pattern until you actually have multiple commands to assign to different buttons, i.e. for a menu screen.
intersting
Fuck off to Sup Forums, you proprietary cuck.
OOP is garbage user. Everyone learns this the hard way eventually.
I am pretty sure 8bit marios do not do that.
Believe me they do.
tasvideos.org
IRC is an easily monitored communications channel, and is quite literally just as much of a botnet as any other program in existence.
Oh, I am mistaken. Thanks!
youtube.com
a server operator can choose to spy on you, but that is an issue with a specific server rather than the protocol itself - you can use a FLOSS client to connect to a trusted server running a FLOSS ircd through a secure connection and you can have 100% confidence that you are not being spied on. as it is an open (and very simple) protocol you are free to write your own implementation if you do not trust any of the existing irc daemons/clients, and then host your own server
there is nothing inherently botnet about the IRC protocol, whereas discord is proprietary trash and everything you send through it is probably being stored on some chink/government server somewhere
Gospel of OOP welcomes everyone. I pray that you will find your faith back.
Remember developers, a virtual call is a good call.
>program procedurally for 10 years
>eventually start using objects and methods because I'm developing more complex programs that need to be better organized and more mantainable
>experience no problems
>come online
>everyone hates OOP for some reason
>????
They are just lost, I feel bad for them.
Hey, I didn't say he should get rid of all the oop, just the bits of oop that made no sense to be oop.
Use the right tools for the job.
Imperative OOP is POO
Functional and pure objects are the truth.
I laughed harder at that than I should've
really?
really
damn
>10 years ago everyone loved oop
>better organized
>more maintainable
lol
i survived /dpt/
yes, using abstractions when appropriate make your code more organized and maintainable
Which denomination are you belong to /dpt/?
>are you a retard or an idiot?
First you have to tell me which paradigm would be this philosopher: en.wikipedia.org
Kay's school is fucking retarded so the other one.
But fuck inheritance. Inheritance should not be a feature. Only interfaces for statically typed languages.
not yet nv
you must implement a haskell compiler in javascript
implement my dick in your ass
*invoke
I don't have an ass
your move
do you shit out of your vagina?
that qualifier makes all the difference user. Eating shit when appropriate can save your life. Eat shit everyday.
Personally I keep each variable in it's own object and the only way to access it is to use a special message.
abstractions aren't 'eating shit', if you think abstractions are bad go code everything in assembly
Too abstract, I prefer pure machine code
8008135
>be me
>using Go
>work on handling JSON server-side extensively in order to display stock data on the front-end
>using GO'S BUILT IN ENCODING/JSON PACKAGE
>json.unmarshall(...)
>graphs displaying spastically
>check console log
>Go is randomizing the order on unmarshal
>check Go forums
>"yeah are you sure you need to use json why not just use something else it's not Go's fault it's your fault use some other method why not implement it yourself" etc
>all this blind side turned toward this """feature"""
You shut up about my daughterfu
>webdevs need to post on forums about frameworks to handle simple text data formats
r u god?
What's more:
>check googlesource
>someone offered a change that maintains order for JSON decoding
>Rob Pike: "this makes this too complex sorry"
>closed
>he doesn't understand how ridiculous it is that a builtin designed to handle data for processing randomizes it
I wouldn't have a "webdev" problem if Go had LITERALLY ANY decent GUI package.
>In JSON, they take on these forms:
>An object is an unordered set of name/value pairs
>unordered
use an array if you want it to be ordered, dumbass
>stock data given in ordered JSON format
Sure let me just call every major data source and get them to change that. Thank you!!
>order can't be baked in via structure of the JSON itself
>this order can't be broken down by half-baked generalized de-serializers
Why am I still replying?
objects are unordered. arrays are ordered. this is how json works. if the go parser is unordering arrays it's objectively broken. I suspect you're just using objects and expecting them to be ordered and complaining that they're not, however
Why doesn't C++ have template yet, and when will it?
class example {
private:
int the_member;
public:
template
decltype(the_member) &member() {
return the_member;
// int const & if instance is const
// int & otherwise
// same with volatile and restrict
}
};
The solution to that is not template. C++ gave you brain damage if you thought that was the solution.
The solution is to properly handle const, restrict, and volatile in a sane way.
yosefk.com
Why would I use something like Java or C# when I could use something like Ruby or Python? Speed rarely matters for anything.
Because finding out about type errors at runtime is really boring and tedious
>restrict
C++ doesn't have restrict.
>What are ClassCastExceptions
I rarely get type errors anyway because I'm not a pajeet.
I'm a programmer
you rarely get type errors because you don't write interesting code
this is the only right answer
>Speed rarely matters for anything
>People stop caring about speed
>Shit starts to get slower
>lol just upgrade your shit to 32gb loser, no one has 16 these days
I create interesting projects in Ruby, C# and C, and I still never get type errors in any of the languages.
I said speed rarely matters for most things, I didn't say that speed was shit. Speed rarely matters, but when speed is needed, it is needed badly.
My new collision resolver is complete. I can now do collision detection on any arbitrary shape as long as it's closed over by a finite number of aabbs.
I like Java more than python, never used ruby or C#. But you're right speed usually doesn't matter that much.
The game logic of pic related including the now complex collision detector is running in Scheme, and believe me it uses a fuckton of map, filter, append, and all that other O(n) shit that treats data as if its disposable and leaves a huge mess for the garbage collector to clean up.
Thread "FPS": 1875.244661
Thread Frametime: 533263
Wow it's hurting my performance so much. The biggest performance killer has been the C code that's controlling the renderer (written in C because in that case performance does actually matter).
Without fail every time there has been a performance problem, the solution was not in the Scheme part of the codebase, but in the C.
Wow user, impressed with your progress so far.
>speed doesnt matter
>making a minecraft clone
>minecraft, programmed in java, runs at 25 FPS with huge pop-in even on high-end rigs
please stop
More like Notch was a shit program who made spaghetti code and all the other devs at mojang had to work around it.
if you're programming collision detection using map and filter, actually if you're programming collision detection using any heap-allocated data at all, you're a bad programmer
The issue is not heap allocation but data alignment and cache accesses. Something you don't have control over with Java.
What part of "every time there is a performance problem, it's the performance critical code's fault" do you have trouble with user?
And yes there are performance challenges because worlds have fucktons of mutable data that has to be dynamically loaded onto the graphics card. This isn't a pretty corridor fps where you can load up the megabytes of data before gameplay starts.
This scene is half a million objects, which in order to not be naively rendered, have to be heavily preconditioned.
To get the 200fps I get on this intel 4400HD integrated graphics card, I've had to do lots of intense culling, sorting, and data conditioning, all in C.
>200fps
The performance gains for optimizations often doubled the fps at minimum. The worst is yet to come too. Doubling the view distance would multiply the objects in the scene by 8. So I actually have more optimization to go, but that's GPU optimizations, much of which I'm going to have to write in C (glmultidraw & occlusion culling need to be done at least partially in C).
don't start the data-orientated meme here please, that only really applies when you're doing simple batch processing over thousands of objects (rendering) instead of fairly complex processing over tens or hundreds of objects (physics)
allocations can cause the garbage collector to shit the bed, but worst of all is doing O(n) things which when you have multiple objects working turns into O(n*m) and tanks your performance
dont talk about how performance doesn't matter when you have ONE object moving in an empty world
unless you intend to only have ten characters running around, collision detection is performance critical
What is so special about the C programming language? I mean, other languages like Algol 68, Fortran, PL/I etc. yet C somehow managed to remain popular. Was this because of the popularity of UNIX or is it something more?
>only 500k nanoseconds spent by the CPU per frame
>some of which is C
>some of which is spent doing other things
>the program is still single threaded
Wew. Also adding more physics entities should be only slightly above O^n with proper algorithms.
Yeah Unix.
Because the syntax clicked with enough people and people enjoyed it enough to copy it for every new language aside from some special snowflakes like perl and python.
Also, the language's simple ABI, anemic standard library and lack of complexity means it's relatively easy to get a compiler up and running for your platform.
I feel C was the turning point between "ancient" and "modern" languages. It's technically not the first language of its kind, but it's the most notable and influential.
Nobody wants to use your dinosaur languages.
The UNIX things certainly helps, though.
I've heard that linked lists in scheme with a copying collector can be plenty fast wrt cache locality, since allocation always takes the next available spot in the nursery (so copying/mapping a list would put all of the conses next to eachother). And since copying collectors don't even scan over objects without references, if you e.g. map a 100-element list twenty times, the garbage collector will still only copy 100 conses
>with proper algorithms.
yes, those algorithms don't use map and reduce
and once again, you have ONE object
Map and fold are replacements for loops not algorithms baka. Did you get raped by Gerald Sussman when you were a kid or something user?
dont know who that is, and they're bad because they're inefficient and leave behind lots of data to clean up, as you said
sourceforge.net
ntended as a hybrid between C++ (syntax) and Java (virtual machine) that isn't C#, Internet C++ is an "operating environment"1 based around a C++ virtual machine. Splendid Systems created the project with a similar philosophy as Java but with goals of fast execution and a smaller learning curve. To that end, they claim that no porting is required from NetBSD code and have provided a gcc extension to compile for the platform.
Some weirdos got together in 2001 and tried to join Java with C++.
Boy this is actually pretty intriguing, as in I'm all down for trying to learn the ins and outs of this beast. The only programming experience I have is entry-level python and c++.
Solid question, is it wrong if I am this motivated to learn any programming language just so I could understand this? Wanna learn reverse-engineering too.
Strange thing to reverse engineer but usable knowledge is inherently good so nah as long as you gain usable knowledge.