/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

youtu.be/QM1iUe6IofM
wiki.call-cc.org/man/4/Unit lolevel
wiki.call-cc.org/man/4/Types
ats-lang.org
en.wikipedia.org/wiki/Curry–Howard_correspondence
youtube.com/watch?v=kjBOesZCoqc
twitter.com/SFWRedditGifs

Looking for some new programming socks.

>Caturday
>Edition
Do you really have to make this shit faggier than it already is?

Helping a lost soul from Sup Forums and his caturday.

constructors are too complicated

OOPfag reporting in

should I use class inhertience or namespaced global functions for a package of complicated functions needed by certain classes?

how easy is it to make a program that interacts with another program's gui?

there's a bunch of relatively easy python libraries that do different types of input simulation. It probably depends on your platform and if you need to do some video game stuff with like DirectInput.

java?

Not very. autohotkey on windows and xdotool on X.

It's fine for just scripting things, like constantly clicking on button on your own computer but you can't really share because of screen resolution, font size, default window position and a bunch of other shit.

I think more info is warranted. The fact that class inheritance is even a consideration suggests that there's too much coupling going on.

auto bar = std::make_unique(new Foo());


am I now responsible for managing memory?

avoid class inheritance, use (pure) static functions.

no, you're irresponsible for managing memory

C++

objects high up in the dependency tree need to use this function. The alternatively I guess I could pass the object itself to a static function like suggested but this completely goes against how everything else works with simple object methods.

Once bar goes out of scope or is re-assigned Foo is deallocated. So in theory no.

I can't quite make out what the issue is here, but you shouldn't need to pass the entire object, just pass the things that define how to draw it (texture, position, transform, whatever).

The graphics library should be entirely separate from the game objects (it should really be abstracted under a "GraphicsContext" interface in case you wanted to change graphics engine, but it's fine to make it global if you trust you'll always be working with SDL).

Usually the way it works is that all of the game Actors/Objects inherit a "draw" function from being an Actor/Game object which passes the GraphicsContext to it (but if you don't have one of those it doesn't need to pass it as it can be globally accessed) and then those Actors/Objects call the graphic library functions, describing exactly how they need to be drawn.

It does only pass the graphic library relevant data. I was referring to a static function where it'd pass the object to a function to handle the data inside, as opposed to calling a class method that handles itself internal (muh encapsulation). I'd probably have to make all class variables public to do that, as well. I guess I could make a data type to return a const reference from but now we're getting retarded.

What exactly is the thing that's being done when you say "handles itself internal" here? For example of course a game Actor should be handling the construction of a logical description of its appearance internally, but it shouldn't even think about touching SDL functions internally.

essentially that it's variables are private and it does everything in class methods (composite object shown)

I hear that a lot of game programming or just plain graphics programming uses a lot of Linear Algebra. I'm torn between two books on Amazon: Linear Algebra by Georgi E. Shilov, or Matrices and Linear Transformations by Charles G. Cullen. They're both Dover books so they're quality, but I'm not sure if one is more broad or easy to understand the other.
I also heard Linear Algebra and Its Applications by David C. Lay was good but I'm looking to just get one book for now. Anyone able to point me in the right direction? Forgive me if this should be somewhere else.

you sound like an expert

class A {
public:
virtual void Foo() = 0;
};

class B : public A {
public:
void Foo();
};

//..
A* bar = new B();


how should I go about creating a collection of A* pointing to B? i'm currently trying it like so

std::vector gCollection;

void init(){
//loop
auto s = std::make_unique(new B());
gCollection.push_back(std::move(s));
}

it works but it seems goofy. what's a better way?

Let's say I wanna run two basically independent C programs, and each should have a different value for a certain variable (like a random number, but with no conflict). Is there a less gay way of doing it than just writing what can be used/what was used in a file and then reading at program start?

then just pass the object around, like you would in functional programming:
youtu.be/QM1iUe6IofM

>that one video
I remain unconvinced, OOP is pretty intuitive for a lot of stuff. I'm open to alternatives but people seem to hate OOP for bizarre highly subjective reasons.

Looks goofy to you? I'm afraid it's kind of just the way it works. In order to be tracked each individual A needs to be wrapped inside a unique pointer. There might be some shorthand I'm not aware of, but conceptually it should be doing that.

render should be something that everything inherits if that's what you're asking, and then the thing handles its own render logic inside that.

If that's not what you're asking then what specific private object variable does the renderer need to access?

You answered it with your first line. It only needs the variables passed to the function as shown in the image. I guess I could call getters as function parameters if I were to pass it to a static function, though, that seems really ugly and in contrast to how everything else is handled. Not all classes that have render methods need the cropped version.

To be honest, I don't think renderCropped is something that should exist. If the cropping information is something that exists within specific objects then that logic should exist internally (for example if it's a state of the object that it specifically is being cropped) and if it's something about the graphics that is cropped across all things you should find some way to wrap that in the GPU_Target (such as with view areas or orthagonal perspectives or however SDL works).

A Button does not change how it looks logically if the view can only see part of it, it shouldn't be the button that is responsible for the code to only draw part of it.

Reminder that static typing is correct typing.

I don't understand how people using dynamic-typed languages even code. When you press "thing." do you just get a list of 10,000 possible auto-completion results or what?

Type-safety is a courtesy to the programmer.

You're right, when I wrote that I didn't understand the library as well as I do now. I've considered the possibility of rendering it to it's own Target and then rendering that to the screen instead of rendering to the screen directly.

This is something I'll do when I need to refactor how I handle this specific feature but will likely require some UI x/y mouse coord translation. UI buttons are some of the oldest and most hacked together parts of my codebase.

if the ide isn't sure of the type at that point, shouldn't it just not auto-complete?

>Writing C and following linux style guide
I think I'm ok

Pretty much anything that "requires" dynamic types can be rewritten with sum types and/or parametric polymorphism and higher order functions.

C is a Spartan language, and so should your naming be. Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like ThisVariableIsATemporaryCounter. A C programmer would call that variable tmp, which is much easier to write, and not the least more difficult to understand.


>HOLY FUCK THIS GUY USES DESCRIPTIVE VARIABLE NAMES
>HOW DARE HE!?
>KILL HIM

Why wouldn't you be? You were fine before a style guide if you had any balls to tell somebody online their opinion is gay.

Honestly, I'm not totally against the idea of (partially) dynamic types when dependent types are considered. As long as the representation is static I think it's nice to be able to start off without proofs and rely on dynamic checks and testing to rule out incorrect ideas before you stabilize the feature and prove it statically.

fuck wrong thread

When I used VS Code for Javascript, it basically gave me an option of pretty much anything I had previously typed in the past 5 hours.

oh, that's a good idea

lmao in lisp you can't have doubly linked lists

overly descriptive, not just descriptive
you don't need to name your loop counter "LoopCounterForProcessX", "i" is fine

they're both shit

Better than nothing, anyway.

what could it mean?

>lisp
who

Statically typed lisp with pointer and no gc when?

just fucking torrent them and see which is better, holy shit

>static typing
no
also
cl is statically typed

I've never done any sort of fun programming before (newb here), so I was looking through Project Euler, but I realized two basic things.
I don't know how to process extremely large numbers. More specifically, I'm not sure which bignum library I should use
Second is more specific, but "adding even fibonacci numbers less than 4 million" is pretty easy, it's just every 3|nth value through the explicit function for Fibonacci's Sequence. But one issue I found with the bignum library I was using is that since the explicit function requires a floating point right up until the final part of it, it wouldn't be able to pass the correct value to my bignum. Midtyping this I feel like this MIGHT be because the library class is specifically for big integers, but just in case I'm missing something I'd love to hear it.

what are your values?

You can do pointer fucking and manual memory management in Chicken Scheme.

wiki.call-cc.org/man/4/Unit lolevel

>cl is statically typed
It's not. It allows type hinting but the compiler can just ignore them. Also it's fucking verbose.

And Chicken has strict typing compilation:

wiki.call-cc.org/man/4/Types

enjoy your green threads

look up arbitrary precision number libraries for whatever language you're using

I am thanks :)

bloated shit that has basically no real use case
dynamically typed garbage collected shit with no syntax

It's not subjective. Functional programming is mathematically sound, OOP isn't, it's just a bunch of ad-hoc "conveniences".

OOP is """intuitive""" for GUI type shit and toy examples. If Smalltalk and Erlang were the primary OOP languages, then it'd at least be somewhat more reasonable. But working on any large codebase with Java/C++ flavored """OOP""", and reasoning about 'what-goes-where'/'whose-responsible-for-what' becomes a huge fucking chore, and testing it always devolves into all kinds of needless complexity.

Try implementing a non-trivial feature on a large Haskell/ML codebase, then try doing the same on a large Java/C++ codebase, and if you don't want to rip your eyes out by the end of it, I'm afraid you probably have Stockholm Syndrome.

>OOP is """intuitive""" for GUI type shit
IMGUI is vastly superior to the traditional RMGUI that inspired OOP in the first place.

It already exists. It's called ATS:

ats-lang.org

>Functional programming is mathematically sound
OK. That sounds pretty stupid, but let's see where you're going with this.
>OOP isn't, it's just a bunch of ad-hoc "conveniences".
Aaaand now I know that not only is that stupid but you're stupid too.

>OK. That sounds pretty stupid
en.wikipedia.org/wiki/Curry–Howard_correspondence

ATS is ML not Lisp.
Also the syntax is horrible.

I clicked on your link but I'm not reading that shit.

Look, ALL computer science is mathematically sound. If it weren't then computers wouldn't work. Trying to bind design concepts to rigid mathematical standards is no different than the people who try and create and algorithm which tells you how to live your live based on nutritional input and other such stupid things. Not only is it on its face retarded, but it speaks to the retardation of anyone who would present the idea in decent populations as being worth consuming.

Are you fucking high or just retarded?

He's obviously retarded.

no shit, lisp was meant to be a dynamic language, what else did you expect when asking for a "typed lisp"? An ML in lisp clothing is about the most reasonable way of accomplishing that, though I don't know why you wouldn't just start using an ML directly as soon as you realized types are useful.

>doesn't know math or why it's useful
>doesn't realize CS is effectively a branch of math
gtfo brainlet code monkey

>doesn't know what "soundness" means
>conflating shit with Turing Completeness
Applying math doesn't just magically work and make things "mathematical" you retard. Math is an inductive science, meaning that you can only safely infer things based on what's already well defined, and that requires following the rules set by those definitions. You can't just open up a repl, evaluate 1+1 to equal 2, and be all like
>Q.E.D. it's le mathematically sound!

go study abstract algebra or something if you want to actually sound like you know what you're talking about.

Is it possible he's also high?

That is just too much to be labelled as simply stupid.

Neither, I'm just an actual mathematician.

Just. Please stop talking. You actually think that design paradigms can or should be based around "actual mathematics." Fucking Education majors. Valueless.

You're arguing with a "coder"
It's a lost cause

A "coder" who has a PhD in Mathematics and an actual job. And, admitadly, a blood-alcohol level 0.18, but still operating on more neurons than you sorry lot. Passing me this category theory shit like it has anything to do with OOP.

>I'm just an actual mathematician
I have my doubts about this and it starts with

>I clicked on your link but I'm not reading that shit.

It might end with your $300K salary but whatever.

>hmm would it ever be useful to have a logical proof that my program will work as intended every time it is executed?
>no, I'll simply make a billion trivial unit tests and pray that I don't get any unexpected behavior
"actual mathematician"

Nice story sweetie. Now back to making that app in Python.

>actual mathematician
>doesn't realize Stats isn't real math

All programs work as they are programmed to work. OK, I think I get it now. You actually think that you have mathematically mapped out all the consequences of your code simply by "prescribing to functional programming theory" because somebody else did a proof that is vaguely related to things that kind of sound like functional programming theory. Aw. That's. Well, anyway, you don't. If you did you would be wrapped up under such a small little Graph Theory box that you'd never be able to get out of it. And you most certainly would never be able to actually make anything.

How about having a little backbone? Because if you did what you are claiming to be doing then you could replaced with machine learning in a heartbeat. But Machine Learning fails for the same reason that you lot continuously fail: creation is several million orders of magnitude beyond what reductionist are able to map out.

Trying to test my Minecraft server here, come join

73.223.115.53:25565

>PhD in Mathematics
>doesn't know what category theory is
>clearly didn't take any higher level algebra classes during his entire academic career
pajeet, if you're not larping, you need to drop whatever it is you're doing right this instant, march directly over to your school, and demand a refund.

Your last chance to make an intelligent argument.

If you could even involve elementary algebra, that would be great.

Being drunk is not an excuse for being retarded.

Statistics is real mathematics. Bring me some central limit theorem and talk. Stop bringing me this sociology crap. It doesn't even follow its OWN rules. Which, by the way, are amathematical.

>tl;dr
>oh but here's what the link said now
>also PHD in math 300k starting
stop posting

You didn't even respond to my statements, why would I respond to your non-statements?

>amathematical
Is this a word you're inventing now?

Damn it, guys. Can't you see I fucking CRAVE conversation and argument? Why did you just. Give up? Well, fuck. Back to /sci/ I guess. You lot are too beat down to provide me with any fun.

It's not very difficult to figure out what I meant by ajoining the prefix "a-" to the word "mathematical", but I know you small brains have to pick your low-hanging grapes where you can reach them.

>LOLOLOL I TROLLED YOU
yeah, good one. it was pretty funny

>If you did you would be wrapped up under such a small little Graph Theory box that you'd never be able to get out of it.

You complained about bothering to learn category theory; is that because you'd literally be proved completely wrong by category theory?

Aw, isn't that adorable. A weetaded widdle mathlet is intimidated by big scawy math theowees, and thinks he can pwoove them wong with the widdle bitty maths he knows. Don't worry, it's ok, it'll be all right, when you get older, you too will be able to tackle the big maths just like the grownups.

>low-hanging
You started bitching about sociology half way through your post and completely ignored every retarded thing you've said for the past hour.

At this point, it's bed time btw.

Don't read this shit tommorow if you actually are a mathematician, you'll want to kill yourself.

>projecting

>Well, fuck. Back to /sci/ I guess.
no, pls. we already have enough brainlets over there as it is.

Kinda, I have drunk posted before. It can be embarassing.

It's nothing to be ashamed of, he also did admit to being drunk as shit.

Advice, not even close to wisdom though. Anybody whose ever had a drink before could tell him the same: go to bed.

Is there a way in Rust to get references to the members of an enum variant without moving the variant out? Something like this.
enum List {
Node(i32, Box),
Empty
}

let list = List::Node(0, Box::new(List::Empty));

match list {
List::Node(data, next) { // But without invalidating list

}
}

Look, dinguses, this was an argument about "functional programming being mathematically superior to anything else, particularly OOP, here, there's this wikipedia article that supports me." No more, no less. If you can honestly support that idea, then go ahead and be small, brains, but it you're someone who came in half-way and didn't realize what the conversation was about, that's it. No more than that.

Yeah, we all agree with you. Good job on your argument.

It's time for bed now, don't read this thread tommorow.

>uses a lot of Linear Algebra
Yes but you rarely ever have to write them yourself.

I suggest that you start with this video series before reading those book. Having a clear mental picture of how LA works helps a lot.
youtube.com/watch?v=kjBOesZCoqc