/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1551829831252.jpg (1280x720, 166K)

Other urls found in this thread:

github.com/samtay/tetris
github.com/hauxir/haskell-tetris
twitter.com/AnonBabble

First for C

Attached: 1470844793325.jpg (500x375, 54K)

Second for C++

>2019
>still advocating C

Attached: risitas.png (272x204, 71K)

Fourth for Forth

Attached: 1518717011958.jpg (3500x1970, 1.17M)

programming socks!

Attached: CA7D9A41-950B-42A8-B24F-CFB5CC38F731.jpg (3264x2448, 2.07M)

>Global variables are bad!

Why were my CS course so obsessed with this one? Wow, I sure love 10 long parameter lists

Use goto also. You will totally piss them off

Attached: go to auschwitz.jpg (480x476, 28K)

refactor you nigger
use structures

So keep passing a reference to a highly specialized struct like some std, in the wild case I'll have to remodulise my function in a completely different program where it wouldn't even make sense?

>Why were my CS course so obsessed with this one?
Because your function might return nonsense, if it reads that variable, but it is changed somewhere else, and it might be difficult to determine when or why this change happens during execution. It's best to use only constants as globals.

because no one wants to read your spaghetti code.

it makes your code hard to read because the behaviour of the methods that use those variables becomes unpredictable

pure functions with immutable arguments is the way to go, as long you call them with a certain input, they will always return the same output, their behaviour won't be affected by external state and they won't affect any external state, this has the added benefit of being able to parallelise the code, since there will be no shared variables you don't have to worry about race conditions

Because programming newbies often abuse them, same with goto. They have their uses when you know what you're doing, but until then they'll do more harm than good.

Why is writing C++ classes so obnoxious? It takes so much effort to add a method or change its signature because you have to keep track of it in two separate files on two separate places that I often don't even want to bother. Languages like Java or C# are so much more comfortable to program in for this reason alone. Hell, I'd rather use C where I can just keep most of the functions to myself in the source file and only export those that I want to expose in the header file.

IDEs take care of that

My first CS professor had an unbelievable hatred for goto. His policy was he mark any assignment turned a 0 if it had any goto on it which was amusing because it was the first cs class most of us had taken so none of us had any fucking idea what goto was.

am I good enough to be hired as a junior dev if I'm able to make non-trivial contributions to open source????????????

Attached: hitler.jpg (1646x908, 541K)

I would say so, sure.

am I good enough to kill myself if I have no friends nor any decent skill at writing software at 24????????

most definitely

learn to use context structs (even though in practice they're just shitty versions of closures)

Meh, fucking multiple translationunits.
If your projects are on the order of 1k - tens of K lines of code just use a unity build, but all code in the header file (i.e inline class methods), and include them all in single .cpp files that gets compiled.

Modules will fix this.

Why does bitwise operation and flagging of enums in C# have to be so... half assed by the .net team

>she still think she is getting decent modules

Hi, I'm a huge brainlet beginner in programming
Using CGI, I want to make a website where there is just a textbox where I can enter some input and depending on that input print some ouptut
To be more specific, I'm trying to make a dialogue program where my algorithm responds depending on the given answer
I already wrote the code in python, I just need to implement it on a website but I don't know how

I just found a company with its entire backend in haskell, and it has nothing to do with the blockchain!!!

banking?

I was whining here about opengl yesterday and I finally managed to get it to werk
actually it were 2 really small mistakes that fucked everything up as said

I set the w value of the position vec4 in the vertex shader to 0 instead of 1.
and in

glBufferData(GL_ARRAY_BUFFER, SIZE, GL_STATIC_DRAW);

I used sizeof on a pointer array to get the SIZE of the array and didnt realise how dumb that was. in every tutorial everyone just uses arrays on the stack and thus this works obviously.

well now it works as it should.

Attached: file.png (1553x912, 31K)

Why CGI? Just wrap your Python script in Flask.

I’m stressed out and want to refresh my interest in programming with a very new thing. Should I try to learn something like Lisp or Haskell? Forth? What’s something very new and interesting? I want to look at programming from a new perspective and learn new things

I'm working on a scraping application to do searches on sites like boorus, pull down all the relevant images, get the tags, translate the tags through a user-provided dictionary if needed, then store and tag the images with tmsu.

Currently the only scraping adapter I've got working is gelbooru but it's pretty comfy. Tmsu is comfy.

haskell is boring as shit

It's actually a school project and I MIST use CGI

Haskell

not gonna tell you, it's my little faerie.

>Lisp or Haskell? Forth?
>What’s something very new

New as in new knowledge to me. I don’t care how recently they were created.

new to him

>The most basic advice is to keep a function of a size so that you can look at it in total on a
screen. Bugs tend to creep in when we can view only part of an algorithm at a time. For many programmers that puts a limit of about 40 lines on a function. My ideal is a much smaller size still,
maybe an average of 7 lines.

Do you agree?

sure but making your functions small won't automatically make them good, but easy to read functions are usually small

welcome to opengl development
trying to figure out where you've fucked up is really irritating
vulkan's a lot better, there's all sorts of debugging utilities

I generally disagree with using functions unless you actually need to reuse or encapsulate the code. Unnecessary functions themselves make the code hard to follow.

Functions are great. They delimit blocks of code with semantic information.

So do comments. Unless you actually have to reuse the block of code or encapsulate it e.g. for a callback, then moving a block of code out into a function just means I have to jump around the file to understand the code and adds unnecessary execution overhead however small that might be. It's an antipattern imo

well put

I was thinking of trying to rewrite a program written in C++ in C# just because I feel like it, with the justification being that it would be more "portable". But if I want it to be more "portable", then surely Java would be the better option? It might also be nice to learn Java anyway, so that I have the option of becoming a Java codemonkey if I really need it. I've heard that Java is absolute dogshit compared to C# though, so how fucked would I be?

>So do comments.
Functions are better at it due to explicit parameters.
>moving a block of code out into a function just means I have to jump around the file
Nested functions exist.
> adds unnecessary execution overhead however small that might be.
Private and nested functions are trivial to inline.

for (uint32_t b = 0; b < 1; ++b) { }

Uhm?

Nested functions don't solve either of those problems though. Mitigate, maybe. But you're still complicating things for little to no benefit.

Working on changing my Authentication with Google OAuth and learning there is no way to ask the user to verify their account. Going to have to impliment some sort of login code system now...

what about it?

Doesn't this only execute once? I'm confused about why this exists

But... they do. Nested functions are by definition defined in the scope of the outer function, which means they're close to the use site. And nested functions that do not escape the outer function are extremely easy to inline, which means there will be no function call overhead.

C# using .NET Core

yeah. I'm guessing someone changed the loop bound in a hurry or something and didn't notice

What is the program? You can still use C# on windows, linux, mac and mobile. Also, Java is not entirely bad but the JCL and most libraries have shit design.

Alright I wasn't sure whether I was just being dumb

java has lots of jobs and it's not bad compared to c#

as a language c# is probably better but last time i did c# the ecosystem was way less mature than java's and writing something useful was very quick and easy

Working on userspace TCP/IP support for my operating system.

Someone in the previous thread said it would be cool if I could get Lynx working, so I spent some time on that and got it working well enough to browse Jow Forums :)

Attached: Screenshot at 2019-03-14 18-09-12.png (1920x1080, 995K)

Any reason you skip argument names in the header for some arguments? Like in _receive and _send functions? Anyway, keep doing what you're doing, your work is impressive.

have you thought about streaming your development on twitch or something

It's a habit I picked up from WebKit:
>Leave meaningless variable names out of function declarations. A good rule of thumb is if the parameter type name contains the parameter name (without trailing numbers or pluralization), then the parameter name isn’t needed. Usually, there should be a parameter name for bools, strings, and numerical types.

I also do it for situations where it's clear from context what something is, e.g a buffer+size pair passed as (void*, size_t)

That might be fun. Unfortunately I have a sucky connection (I'm in a cottage with nothing but 3G)

how come protocol_receive gets two buffers? also what's that int in protocol_send?
liking the NetworkOrdered btw

I guess that's a bit murky. One buffer is const (input), while the other is mutable (output). I strive to keep my programs const-correct in order to make little things like this nice and unambigious :)

The int in protocol_send is the buffer size for the const void*. I'm trying to convince myself to switch to using int instead of size_t for sizes everywhere in the kernel. The reasoning being that it would be easier to check for negative values on syscall entry than to check for unsigned overflow eeeeeverywhere. But some part of me is not convinced yet so I keep writing inconsistent code like this..

And yeah I made myself a NetworkOrdered template after forgetting to call ntohs() for the nth time. Stupid network order.

maybe I'm being stupid here, but why does receive need an input buffer?

Nothing stupid about asking questions.

All the protocol_* virtual functions here are overrides from the IPv4Socket superclass. I try to do most of the work in there, and then delegate the protocol-specific bits to TCPSocket, UDPSocket or SomeOtherNotYetImplementedSocket.

All the buffering happens in IPv4Socket, so when you read from the socket, it take a received packet (a raw IPv4 datagram) from the receive queue and passes it verbatim to TCPSocket::protocol_receive(), which then extracts the TCP payload from the raw packet and copies the relevant bits into the user-provided buffer.)

I'm not sure this is a good design, it just sort of grew into this organically :)

Depending on your use case, the JVM may offer a better language than Java. Pic related.

Attached: JVM Languages.png (768x4245, 3.62M)

how do I bind multiple textures to sampler2D array in the fragment shader?

I read I should do it something like this:

render call:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, tex1);

glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, tex2);

etc.

const GLint samplers[n]{ 0, 1, 2, ... ,n };
glUniform1iv(samplerUniformLocation, 9, samplers);

and my uniform in the fragment shader:
uniform sampler2D tex[2];

but the glUniform1iv doesnt work and only 1 texture works.

Attached: 1550685744849.jpg (729x729, 109K)

yeah that makes sense

It's the same reason why English teachers say you shouldn't start a sentence with "because". Because newer programmers don't know when to declare global variables, they often end up declaring them unnecessarily.

I need a basic Python GUI framework that I can use to shit out a couple quick tools in a day without having to spend days/weeks learning the framework itself. Any suggestions?

When should I call myself Senior C++ dev?

How would I make a game in haskell?
My game state would be a StateT?

>how would i make a game
depends on the game

Why won’t Java compile my script?
alert(“hello world!”)

Let's take something simple such as tetris

cout

here are some terminal examples
github.com/samtay/tetris
github.com/hauxir/haskell-tetris

tomorrow

I don't even like programming, I only pretend to on the internet to fight the patriarchy's misogynistic belief that girls don't like programming

The way I did is I create multiple uniforms for the textures, like tex0, tex1, tex3 then I just use this in the shader:
uniform sampler2D u_Tex0;
uniform sampler2D u_Tex1;
uniform sampler2D u_Tex2;

always be doing something new

satania shit
now THIS is a based devil

Hell Na fucking dick sucker

Attached: 1520274351963.jpg (613x703, 95K)

>t. brainlet

tkinter's pretty good

it actually works with
uniform sampler2D tex[9];

the name of the uniform at index i is "tex[i]"

but as always my problem is something completely different

Attached: 1521670223899.jpg (400x400, 26K)

if __name__ == '__main__':


Somebody actually sat down to design a language and thought to themselves, yeah, this is an elegant way to specify the entry point into a script.

Is the 'n' in "fn" the first or second 'n' in the word "function"

Neither, it's short for "fuck n*ggers". White privilege strikes again.

linear types could have prevented this
the first, e.g. fun

It's not the entry point. The entry point is the first line. In fact, you will never truly need that construct. It is useful, when you have multiple files with "main"-functions, and you want to execute that function only if you run specifically that file. If you only have one main function in your files, that construct is pretty much completely irrelevant.

This. All that conditional does is allow you to change what code executed if your script is being executed as a module vs being executed on it's own. In either cause it's never the entry point.

When you're the guy everyone goes to for answers.

what if I'm self employed?

The script is immediately executed top to bottom, yes, but it's the entry point because no non-trivial script is just going to throw everything in top level like that, especially if you might ever consider importing said script in another script in the future and you don't want the entire thing to immediately execute.