/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Monad_(functional_programming)
twitter.com/SFWRedditGifs

First for D

C#

thank you for using an animie image

Fake thread by anime memers, pls move to actual thread guize:

I'm going to try and relearn C by going through the MIT algorithms book and doing all of the examples/problems with C.

Is there a better way?

>8 hours ago
>like 20 posts

Doesn't look like much of a real thread to me.

Read K&R C.

>Like how not?
CPUs are designed to do the same thing many times in a row. OOP means that you're constantly jumping between objects and executing different code for each. Overcoming this often means you have to forget about encapsulation or subtype polymorphism except at a large scale.

>Just like if you know your program is going to need a lot of objects
Programs don't need objects. This is a hammer/nail situation.

Sometimes you need an 18-wheeler.

Sometimes you need a coupe.

Sometimes you need an ATV with a winch on the front.

OOP and FP are friends, and should be used together and to their strengths.

The same goes for any other programming concept you memers try to pit against each other. Most everything has a time and a place, and can help you if you use it correctly.

int main(int, char**) {
printf("Hello World!\n");
}


main :: IO ()
main = do
putStr "Hello World!\n"


>this triggers the OOP

>OOP and FP are friends, and should be used together and to their strengths.
No, they're really not.

>This is a hammer/nail situation.
What is this situation?

I don't get it.

OOP is not intended for Hello World-like applications.

fn main() {
loop {
println!("Thank you for posting an anime image!");
}
}

user claims that you need OOP because programs need objects. In reality, all he knows is OOP (or his bastardized version of it) and thus cannot fathom programming without objects.

because Hello World programs are a subclass of programs

and OOP is not intended for programs

OOP also isn't intended for anything that isn't (at least conceptually) distributed between many mostly independent actors that still need to communicate.

It reeks of SJW.

>macro
but why

Been working more on graduate research. Windows drivers are a pain in the ass, Win32 is a pain in the ass, and Visual Studio is a mega pain in the ass. Still can't get a good way to send information to this fucking dummy network adapter. I've got no raw sockets, Wireshark is not detecting the damn thing, and it doesn't connect to any sort of external network, so there's no "port" to test with a simple TCP/UDP interface. My professor recommends opening the device file with CreateFile and writing to it directly, so I do that and my test program is getting screwy results. CreateFile returns an INVALID_HANDLE_VALUE, but GetLastError() is behaving non-deterministically and returning a different value on each run of the program, all of which are outside of the range of legal error code values. I'm guessing I'm somehow using the wrong device file path (I'm right now using a combination of devcon and winobj to find a symlink that's more or less \Device\00000033, or something similar), but documentation on all of this shit is terrible. MSDN is unhelpful the second your question about the behavior of things becomes even slightly complicated, as is searching StackOverflow.

Really, just fuck Windows in general.

t. brony

That's not how you into logic.

>I don't like apples.
>Well, you must not like all fruit because apples are fruit.

Because that's how Rust does varargs.

What's wrong?

computers run programs
OOP is run on computers

how OOP is not programs?!?!?!

That wasn't implication, I was stating a fact.
From that broader fact you can determine the more specific instance.

>because programs need objects

if you actually read it in a non-autistical way, you would know I wasn't talking about all programs. Do you really think WoW for example, isn't using OOP?

I guess you could say that a Hello World is a child type of the type Program...

>WoW uses OOP
wtf I hate OOP now

You literally tried to make the logical leap as described, judging by the content of your post, and not whatever fucked up mental gymnastics you're doing in your head.

I didn't imply you meant all programs.

I'm trying to figure out type providers in F#...

type SymbolDividends = HtmlProvider

When I then try to use it, I just get a little popup saying "Loading..." and nothing happens, no intellisense or anything.

>I just get a little popup saying "Loading..." and nothing happens, no intellisense or anything
Is that Visual Studio issue?

>You literally tried to make the logical leap as described
No I didn't.

>>That burning house is dangerous
>Most burning buildings are dangerous
>this explains why that burning house is dangerous

oh ok that must have been casper the friendly ghost who typed that post then

Oh, I suppose you're right. I did imply that by saying he can't fathom programming without objects.

My point about programs not needing objects still stands.

Is OOP the definition of a meme?

>only used because other people use it
>no good arguments for any intrinsic value
>people associate everything with it

you really are an autist. If you go back to my original post in the old thread and try your best not to sperg out, you would know that I am not saying that "programs. need. objects" like it's some universal fact. The whole point of OOP is to make it easier for the programmer to manage the data. Nobody is saying programs need objects. Completely depends on the program/application. It's not hard to understand.

If OOP makes it easier, then why do we need no end of new revisions and books saying "actually, the principles we've been using are completely wrong"?

>don't use inheritance
>avoid deep heirarchies
>use non-OOP features (generics, lambdas, etc)
>calm down with the getters and setters
>XYZ design patterns
>don't use XYZ design patterns
etc etc

Imperative and FP don't do that

is this how you make a 2D int array in C using only one malloc statement?


int *create2DArray( int rows, int cols )
{
int **array;
int *data;

array = malloc(rows * sizeof *array + (rows * (cols * sizeof **array)));int *create2DArray( int rows, int cols )
{
int **array;
int *data;

array = malloc(rows * sizeof *array + (rows * (cols * sizeof **array)));

data = array + rows;

for(int i = 0; i < nrows; i++) {
array[i] = data + i * cols;
}

return array;
}

data = array + rows;

for(int i = 0; i < nrows; i++) {
array[i] = data + i * cols;
}

return array;
}

If any programs need objects at all (for modelling distributed systems of actors), it's an incredibly small fraction.

Also, the idea of an object, encapsulated data and behaviour, is so easy to implement in any language with lexical closures. So even if you do need objects, there is no real reason to use "object-oriented" languages like Java that have dire support for anything else.

Rate (not) my Perl
#!/usr/bin/perl

use v5.14;
use strict;

my $ayy;
$ayy = "LMAO";
say $ayy;
for ($ayy =~ m/(?!^)./gs) {
say $_;
}

fucked it up

int *create2DArray( int rows, int cols )
{
int **array;
int *data;

array = malloc(rows * sizeof *array + (rows * (cols * sizeof **array)));

data = array + rows;

for(int i = 0; i < nrows; i++) {
array[i] = data + i * cols;
}

return array;
}

>malloc

data = array + rows

what the fuck

also malloc can fail, bub

Because OOP is for code monkeys.

>calm down with the getters and setters
wtf why?

>also malloc can fail, bub
Not on Linux

i dont know man it makes sense to me

Where do I get started if I want to start with game development (as side hobby while I study), with the eventuality of joining a tech company in the future. With interest in Robotics as well.

Where do I take my first steps. I have Gamemaker(I know but I got it cheap so I'll use what I have to start). Which language and what tools?

C++, SDL, SFML

create2DArray(-1,-1)

Teehee.

because programing is hard and there will be design patterns no matter what you do

>if FP makes it easier why are there monads?

i shouldve said that i call it from my main where I will check that the rows and cols are at least 1

i just want to know if im on the right track

Monads do make many things easier.

monads aren't a design pattern, they aren't necessary for pure languages, and they aren't necessary for FP
does that answer your question?

microsoft pls

>if FP makes it easier why are there monads?
you must be literally handicapped if you find them """""hard"""""

>monads aren't a design pattern
they literally are. monad stacks are another design pattern.
>they aren't necessary
no, but neither are oop design patterns
>they make it easier
so do oop design patterns

>C++
I hear it's a challenge, good.

I forgot to mention I also want to learn some Web design/programming so I can mount up sites in the relative short term.

It's not a design pattern if it can be expressed first class within the language. Then it's an abstraction.

no they aren't
monad stacks aren't either
that's like saying a list of ints is a design pattern

>I still don't know how to subclass in GTK
So this is what happens when you try to port OOP paradigm into a language with functional paradigm.

>C
>functional
what?

What language?

If it's functional enough you could use existential quantification and rank n types

@58666757
>they literally are. monad stacks are another design pattern.
slit your throat please

i write functional C

en.wikipedia.org/wiki/Monad_(functional_programming)
>They can also be seen as a functional design pattern
>Categories: Software design patterns

>wikipedia
>can be
>are

this is OOPfags trying to understand reality

write me a lambda in C

CAN, and that's just a nod to inferior languages that can't abstract them.

Web development and game development are two different kind of beasts. Focus on one thing.

@58666809
just jump of a bridge already

Then what are web browser games?

in Haskell, a monad is a type class. In OOP, a singleton is an interface.

Design patterns can be expressed in a language and still be a design pattern.

pic

>people do it alot therefore it is a design pattern
wrong

They have nothing to do with web development.

So haskell is a programming paradigm now? Remove yourself from this thread

webdev

Nope, you cannot write an interface for all singletons.

I mean, theoretically, there is a language where you can, but most of the time singletons are used as a pattern. Most of the time, monads are used as an abstraction.

So I guess you need context - a monad is an abstraction in Haskell but a pattern in C#.

#include
#include

template
class table {

public:
table (size_t rows, size_t cols);
~table ();

const size_t rows;
const size_t cols;

const T &operator () (size_t r, size_t c) const;
T &operator () (size_t r, size_t c);

private:
T *_items;

};

template
inline table::table (size_t rows, size_t cols)
: rows (rows)
, cols (cols)
, _items ((int *) malloc (rows * cols * sizeof (T))) {
if (_items == NULL) {
throw "out of memory";
}
}

template
inline table::~table () {
if (_items != NULL) {
free (_items);
}
}

template
inline const T &table::operator () (size_t r, size_t c) const {
return _items[cols * r + c];
}


template
inline T &table::operator () (size_t r, size_t c) {
return _items[cols * r + c];
}

Objectively and academically which route is best to start with? Seeing as I'll be going to school for this too soon. Though through game development I could [potentially] make some income to fund the rest of my ventures. Though the same goes for web. I need to be able to build my own websites in the future. That is absolutely crucial to me. I'd like to at least learn Web Dev. decently enough by year's end to build my sites.

Guess this is just the standard debate of anything getting into the field

>game development
>income
pick one
You're better off building websites for customers.

I'm trying to clean up my apartment.

Well, shit, have a picture as a sign of my gratitude

thank you for the anime pic

thanks for using an anime picture.

What's you're favorite monad?
I'm fond of the List Monad.

the anime monad

thank you for using an anime monad

postAnime :: Cute -> Anime PostReceipt

Optional, because it triggers Haskell snobs as a stateless side effect.

look at me nuggets
why didn't you help a couple of threads earlier?

I was about to ask for help on haskell but I figured it out.

It's not a side effect you retard.

same here. are you me?!

what's a side effect of Optional?