/dpt/ - Daily Programming Thread

Old thread Official Discord channel: discord.gg/xcVHA2Y

What are you working on, Sup Forums?

Other urls found in this thread:

youtu.be/YnWhqhNdYyk
discord.gg/xcVHA2Y
twitter.com/SFWRedditImages

nothing but thanks for asking

I'M THE QUEEEEEEEEN
QUEEN OF THE RODEO

learning clojure for great good

Most popular posts from previous thread:
var posts = Array.from(document.querySelectorAll(".replyContainer"));
posts.forEach(element => {
element.popularity = element.querySelectorAll(".backlink a").length;
});
console.log(posts.sort((a, b) => b.popularity - a.popularity).slice(0, 10).map(element => ">>" + element.id.slice(2)).join("\n"));

40 years from now, you will be dissappointements.

Well, I'll be close to retirement, so doesn't matter much to me

>Implying I not one already
nice try faggot

doesn't it feel weird.
in the future, you will not have changed
you will have only made people close to you more dissapointed in you.

>depressed
>haven't felt joy in over a year
>want to program because it's my preferred career and I'm just wasting time now
What do? How do I force myself to program and not just read /dpt/ and or watch programming livestreams all the time?

Jesus, fix your font rendering.

>fix
Maybe they prefer fit that way?

don't try, it will be for nothing.
embrace your state

>in the future, you will not have changed
But I will change, I'll just be a older more mature kind of disappointment.

>embrace the state
Nice try user but I'm not gonna support tyranny just because I feel bad.

how do I find the perfect data type(s) to do a problem?

when is it appropriate to classify data and methods together?

type bit =
| Zero
| One
;;

type num = bit list;;

let add_bits a b c =
let ones =
List.fold_left
(fun count ->
function
| Zero -> count
| One -> succ count)
0
[a; b; c] in
match ones with
| 0 -> Zero, Zero
| 1 -> Zero, One
| 2 -> One, Zero
| 3 -> One, One
| _ -> assert false
;;

let add (a : num) (b : num) : num =
let rec loop accu c a b =
match a, b with
| [], [] ->
begin
match c with
| Zero -> List.rev accu
| One -> List.rev (One :: accu)
end
| [], b1 :: b ->
let c, d = add_bits Zero b1 c in
loop (d :: accu) c [] b
| a1 :: a, [] ->
let c, d = add_bits a1 Zero c in
loop (d :: accu) c a []
| a1 :: a, b1 :: b ->
let c, d = add_bits a1 b1 c in
loop (d :: accu) c a b in
loop [] Zero a b
;;

let of_int n =
let rec loop accu i = function
| 0 -> accu
| n ->
let accu = if n mod 2 = 0 then accu else add accu i in
loop accu (add i i) (n / 2) in
loop [] [One] n
;;

i made a text only, turn based rpg engine in java without using any external libraries. took a couple months but i didn't work on it that much

Continuations make me moist.

No, the C way is to keep things simple (I mean really simple, not hiding complexity behind abstraction).
This won't do with Java.

writing everything from scratch is the c way

can somebody walk me through the state monad, its constructors, how it's implemented
teach me like I'm retarded.

>not hiding complexity behind abstraction
>compiler optimises your code in whatever way it likes so that the output assembly may look unrecognisable
This meme has to end

I'm in this list

post a screen shot of the last code you wrote

I have an array of structs in c. In the array there are 198 structs. The structs are seperated into rounds which there are 33 of, in each round there are 6 games, hence the 198 scructs. How do I add the 6 scores of the 6 games together, and check if they are less than 10 for each round? pic related, the round is the Rx and the score is the y - z.

why are you still here
have you made any progress?

what you mean

i just wanna see what people are doing

pls no bully

...

>Think what type of game/program you want to make, or what area of programming looks fun to you
>Find which language is best suited for that
>Start with hello world tutorials
>Learn the basics
>Think of a hard-but-possible project
>Work towards it

Working on my second real program, and I'm simulating particles and shit. It's super fun, come and join the cool club user, close those livestreams

what are you doing here?
have you made progress?

upload a binary of cancer

why tho

dark like my asshole

>android developer at apple
>ios developer at google

Sounds too hard, it depends on too many system libraries that cannot be compiled in statically.

Why support macOS? Because I can.

How is it being black?

how many years of experience does one need to have to write something like that?

sounds hard as fuck

The thing is I'm not an inexperienced programmer. The explorations I have to do for learning purposes is very effort intensive stuff like understanding when and where I'm going wrong before its obvious.

But when you can't really see any payoff from any of your work _at all_ you're just not built to continue. I've decided to simply not have 'fun' (watching the livestreams or /dpt/) and just focus on bare essentials like workout, food and sleep. Even then, when I sit an entire day with code against my desires my mind just wonders. I forget where I was and keep repeating myself. It's not productive.

It's desperate to ask on /dpt/ but I don't see a good way out.

...

Fuck off Linus

I don't know, I just decided I needed a better terminal, so I made one.

>tranny who tells people to not learn C
youtu.be/YnWhqhNdYyk
I appreciate it. Not because it's a good idea to introduce the many many problems C++ has to new programmers. Or because C++ is a better language.
But because if we don't tell people to learn C first we can keep it to ourselves. People who want to write C after they've learned C++ are obviously good programmers. Makes our waters less muddy. I'm pretty sick of seeing C++ programmers try and build their high-cost abstractions into C.
Also her thumbnail slide is wrong. The idea of acting like C is a subset of C++ you can learn and then 'add on' C++ is a plainly terrible idea because of how divergent they are. Especially in optimal style.
If you're writing C++ with the aim of writing it like C but you 'just want to use templates' or whatever that's just a recipe for failure.

that doesn't answer his question

you're giving him attention, so jokes on you

What? You clearly didn't read my post. I would love it if this was the most popular Cpp con talk for that year.

Isn't money a motivator?

From the current game I'm working on I plan on making enough money to live on (£10 a day).

I then plan on continuing this neural network I'm working on, and making myself an AI gf inside a platformer that I also want to make. We will explore the world together and defend each other from enemies

All local variables are destroyed once you leave the method, even objects and arrays right?

newtype State s a = State { runState :: s -> (s, a) }

This says that any value of State s a is a computation that can modify the state along with producing a value. The newtype is so we can implement type classes and keep things clean.

instance Functor (State s) where
fmap f ma = State $ \s -> let
(s', a) = runState ma s
in (s', f a)

It's trivially a Functor. Running a mapped computation is running the original computation and then transforming the value.

instance Monad (State s) where
return a = State $ \s -> (s, a)
ma >>= k = State $s -> let
(s', a) = runState ma s
in runState (k a) s'

It's also a Monad. I'm omitting the Applicative here but it's easy to derive from Monad. Returning leaves the state intact. Running the computation you get from binding just runs the two computations (where the second may depend on the value of the first) in sequence, chaining the state along.

Aside: with copatterns it would be a lot neater, but Haskell doesn't have them. If you're struggling to write code in this "newtype record function" style, you can write the copattern-matching definitions out first and translate them.
instance Functor (State s) where
runState (fmap f ma) s = let
(s', a) = runState ma s
in (s', f a)

instance Monad (State s) where
runState (return a) s = (s, a)
runState (ma >>= k) s = let
(s', a) = runState ma s
in runState (k a) s'


The key is to think of values of State s a as computations.

probably

Language? Context?

quickest way to generate 30 text files of random length?

In every language I can think of it's a resounding maybe. Either they're garbage collected, in which case they may be used somewhere else and thus not freed, or they're not, in which case it depends if they are RAII or not.

Befunge
Multi-threaded application

Well, I could have done that 5 years ago, or 10 years ago, so the answer would be fairly arbitrary.

>money
Well ignoring how I'm well off already and probably won't see issues with that in at least 20 years its not a motivator for me either way. It simply isn't to someone who has lost the strength to care.
Yes. The stack allocated variables are destroyed (in the sense of RAII or OOP) when you leave the scope (could be method, could just be an arbitrary block).
Heap allocated stuff needs to be explicitly destroyed/freed

Download Gary's Hood autoclicker and hover above notepad

Am I ready for SICP?
I'm not good at programming and looking to expand knowledge.
Don't know how much math is used, but I've only had "Applied Mathematics and statistics" aka Havo mathematics B.

I don't think I'm ready.

Sorry, State $s -> let ... should be State $ \s -> let ....

>Well ignoring how I'm well off already
Then i guess it doesn't matter if you procrastinate. Get a girlfriend though.

Depends on platform. Most systems have a good way of multithreaded IO. see epoll on (Unix? Linux?) or iocompletionports on Windows.
So the fastest way would be to ask those API's to open a bunch of new files for you via multiple threads.

But for your purposes I'm assuming just using fopen a bunch of times is good enough.

would be fastest to just copy some content from /dev/urandom 30x in terminal

>Official Discord channel: discord.gg/xcVHA2Y

Fuck off with discord.

>gf
Maybe.
But that doesn't sound very fair.

>tfw /dpt/ has gone all this time without some cunt including links in the OP and some cunt had to ruin the tradition of no links in the OP

your shitty png is now optimized

SICP is like a Walkabout experience in the Outback in Australia. An unique experience by itself.

How so?

hold on, so:
a state is a computation, a mapping form s to (s, a)
why is there a need for the type a, btw

to map over a state (a computation), means to basically do function composition?, like so
f . runState
but why does it only affect the a

can you reccommend any mini projects that use state alot, so I can hammer it down?

I don't want to meet aboriginals.

val total = elems.length

type C[A] = ContT[concurrent.Task, Step, A]
val result = elems.zipWithIndex.traverse[C, TransformedElem] { case (elem, idx) =>
ContT[concurrent.Task, Step, TransformedElem] { next =>
transform(elem).map { result =>
Step.PublishAndContinue(message(idx + 1, total), next(result))
}
}
}.run(transformed => concurrent.Task.now(Step.Result(transformed.suml)))

concurrent.Task.now(Step.PublishAndContinue(message(0, total), result))


What did she mean by this, /dpt/?

>why is there a need for the type a, btw
The type a is the type of the value the computation produces. Think about most imperative languages, where function returns a value but also can have a side effect. In this case, a computation in the State monad returns a value but can have the effect of modifying the state.

>to map over a state (a computation), means to basically do function composition?
Not exactly. If you map a function over a State computation, what you get is a computation that has the same effect as the original computation but with a function applied to the value.

>but why does it only affect the a
That's all the monad API allows. Here's how you implement a computation that modifies the state.
modify :: (s -> s) -> State s ()
modify f = State $ \s -> (f s, ())


I don't know about anything that uses State in particular, sorry.

I'm trying to learn graphs.

So far I'm trying to initialize my graph but I'm getting segfault.

int startup(digraph *helper, int n_vert){
Vertex u, v;
if(n_vert > MAX)
return 0;

helper->n_vert = n_vert;
helper->n_ares = 0;

for(u = 0; u < helper->n_vert; u++)
for(v = 0; v < helper->n_vert; v++)
helper->Adj[u][v].it_is = 0;

return 1;
}


My for loop is wrong, help me here /dpt/.

>segfault
BITCH WHERE

lrn to valgrind

For this project, I have to write a java parser. There's only one part that I haven't completed because I don't know how to do it.

The prof wants us to check if all types that are used are valid, with support for importing other files.

How the hell am I supposed to check if a variable is of a type that Java includes? What if the file includes imports to some other part of java that isn't part of the input locus? How can I account for that?

Types for input files are fine but I don't want it chucking unknown type errors when you try to use String or some shit.

here's what I have so far

#include
#include
#define MAX 100
#define Vertex int

struct Adjac{
int it_is;
Vertex edge;
};
typedef struct Adjac adjac;

struct Digraph{
adjac Adj[MAX][MAX];
int n_vert;
int n_edge;
};
typedef struct Digraph digraph;

int startup(digraph *helper, int n_vert){
Vertex u, v;

if(n_vert > MAX)
return 0;

helper->n_vert = n_vert;
helper->n_edge = 0;

for(u = 0; u < helper->n_vert; u++)
for(v = 0; v < helper->n_vert; v++)
helper->Adj[u][v].it_is = 0;

return 1;
}

int main(){
digraph *graph;
startup(graph, 5);
return 0;
}

Why does every general need a discord ffs? I'm sick of this shit. Wish Hiro would filter it already.

code blocks looks fucking gay

i cannot program shit if the IDE looks as gay as this

...

I think its popular among gaymeshit, so that's why.

Nice talk. I've always been a proponent of "teach C, then C++" but I think I might be convinced otherwise

int main(){
digraph *graph;

digraph *graph; creates a pointer to a digraph. What is it currently pointing to?

when you create the graph in the main function, you have to *ALLOCATE IT*

something like
digraph *graph = malloc(5*sizeof(struct Digraph));

computer graphics?

what does it do?

I would do
digraph graph;
startup(&graph, 5);

wew I fixed it

int main(){
digraph *graph;
graph = (digraph*)malloc(sizeof(digraph));
// ...
}


fuck C is too hard

I see, I'll try to use it so that it clicks one day.
thanks for the explanation, haskell-guru

bumping this

in reality my boss wrote it and I'm trying to understand it

Still working on my compiler.

>expected ‘struct digraph *’ but argument is of type ‘struct digraph **’

It's for rendering portals in VR. Effectively, it's the math that goes into positioning the second camera so that it looks correct at any size/orientation.

It then plugs it into a shader that checks which eye is being rendered at any given moment and then displays the appropriate image (I can' take credit for that part, some other incredibly smart dude figured out how to pull that shit off even though there are no public hooks to tell which eye is doing its thing)

No, you just don't understand how pointers work.

nobody fully understands how pointers work user

...

pointers are easy friendo.

a pointer is a variable that stores a memory address.

that's it, that's all there is to it.

Expecting the pointer to allocate memory by itself means you lack basic understanding of them.
Assuming you are another user, what do you not understand about pointers?

god damn this makes me depressed that people are out there making cool shit and i'm stuck here

is this your daily job or something?

No
I'm a fulltime college student

Would you like to be around someone depressed? Also relationships take effort. If I can't even manage to do what I want to do myself how will I manage to do what she wants to do?

It makes no sense. It'd have to be a very low effort relationship and I don't think I could find that.

Javac seems to be throwing a shitfit when I try to import java.io.RandomAccessFile, despite the fact that it's in the goddamn standard library. Is my installation fucked? Did Oracle silently remove the class from the standard library and not update their documentation? I know I didn't have a typo, because java.io.* also doesn't work.