/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

dlang.org/blog/2017/07/28/project-highlight-funkwerk/
en.wikipedia.org/wiki/Opaque_pointer
learncpp.com/
twitter.com/SFWRedditImages

Anyone built something with Haskell, if so what was it?

I think Idris was made in Haskell

Nothing practical has ever been nade in Haskell. Only academic circlejerk projects.

Employed Haskell programmer reporting in

So, how are you finding the latest JS framework?

stop using that image
you're scaring the children

Germany loves dlang-chan!
dlang.org/blog/2017/07/28/project-highlight-funkwerk/

splitvalue = *(&(&tp->v0 + tv)->x + axis);

Is this acceptable to you?

Variety is the spice of life, OP. You, on the other hand, are Miracle Whip spread on Wonder Bread.

no

What do you do?

Trying to wrap my head around how C handles headers.

Pic related is my setup for an implementation of linked lists. However, when I try printing the value of "p->Next", I get the following error (gcc)
Test_Poly.c:12:41: error: incomplete definition of type 'struct Node'
printf("Address of p->next: %d\n", p->Next);
~^
./Polynomial_List.h:3:8: note: forward declaration of 'struct Node'
struct Node;


Why is this happening? Don't I include the header file, which specifies how Node should be built?
Using the following gcc command to compile:
gcc Polynomial_List.c Test_Poly.c

either say
export struct node;
in the header
or just define it in header fully

i think that would work

Can you please show the filenames of all the files you included

The top right header file just declares the existance of the struct Node, but doesn't declare what fields it has. The bottom right header file declares what fields it has.
In order to use fields such as ->Next, you need to include the bottom right file, and in order to use those functions you need to include the top right file.

nigga the file on the left includes the header
and he compiles both of the .cpp files
use your eyes

Okay so the bottom right file is a .c file but that's wrong, it needs to be a header file that the left file includes.

The key takeaway here is that compiling multiple C files at once is the same as compiling them seperately. So if you were to just say
gcc Test_Poly.c -c
then it has no way of knowing what ->Next is. So you need to tell it that information by declaring it in a header

Yeah sorry.

Left file is "Test_Poly.c"
Top right is the header file Polynomial_List.h
Bottom right is the implementation file Polynomial_List.c

I'm thinking of ways I can include both the implementation and header files, but I'm worried that might lead to duplicate symbols and leading to compiler errors

Not sure if this helps, but when I
#include "Polynomial_List.c"

int the left file, I get linker errors (duplicate symbols errors for the functions defined)

>it needs to be a header file that the left file includes.
but that's wrong
you're getting duplicate symbol errors because the poly-lists header should have a
#define Polynomial_List_H
right after the #ifndef
right now that #ifndef never does anything

pretty sure you want to do something like this:

en.wikipedia.org/wiki/Opaque_pointer

either define functions to return the inner values required or expose the struct definition in the header file

Don't include the header. There's no reason to have a header file user. This isn't sepples. You only need header files when you are thinking about an interface and then you'll link against the .o file not the .c file.

Functions get compiled into assembly code, and if the same function gets compiled twice (which is what happens when you #include the .c file) then you get a linker error.

However, struct declarations are not compiled into anything. As long as each c file sees the same definition of a struct, you're good to go.
examples:

// a.c
void foo() {}

// b.c
void foo() { printf("yikes"); }

result: LINKER ERROR

// a.c
struct thing {
int x;
};

void foo(struct thing) { printf("x = %d\n", thing.x); }

// b.c
struct thing {
int x;
};

void foo(struct thing); // note: this is a DECLARATION not an IMPLEMENTATION

void bar() {
struct thing;
thing.x = 4;
foo(thing);
}
result: x = 4 (GOOD)

// a.c
struct thing {
int x;
};

// b.c
struct thing {
double y;
};
result: this compiles, but is undefined behavior since a.c and b.c see different versions of struct thing. never do this.

Alright... I should have seen that coming, but unfortunately I don't think that did anything (see pic related)

I want to include header files because it makes it easier to organize imo.

>As long as each c file sees the same definition of a struct, you're good to go
But don't I do this? I have a declaration of a struct, and define it in an implementation file.

Each C file needs to see the definition of a struct. The only way it can "see" it is by having it be inserted into the file.

// a.c
struct thing { int x; }

// b.c
// note: does not #include anything
void foo() {
struct thing t.
printf("%d\n", t.x);
}


$ gcc a.c b.c
ERROR: b.c doesn't "see" the definition of the struct, so it doesn't know that the field .x exists

xmonad was built in haskell
it was heavily used in the corporate world as a fast, safe language before java and C++ came into the picture.

>But don't I do this?
i think the test-poly still sees the undefined struct, might be wrong

you should really be defining structs in the header, not in the .c file

>

Not the same user but you just need to put the struct definition in the header, basically instead of this:

struct Node;


Put this:

struct Node
{
int Coefficient;
int Exponent;
struct Node* Next;
};


And then get rid of the definition in the .c

The header defines a function the name of which should point somewhere. That somewhere would be a library file linked to your program.

Basically the header file does nothing but to announce the existence of the function, alone it's worthless. The library/binary file the function is in (if it's not called from the file itself) defines what the function is.

So for example #include will bring in symbols from stdio, therefore tell (promise to) your program that the function printf (and every other in stdio) exists. Doing -lc when compiling (often done by default by your compiler) will have the program call the libc library in which it will find the actual printf function.

Netbeans-Cpp IDE is pretty comfy.

>xmonad
>Pure and innocent window manager written in 1.2 kLOC.
>Built on top of the heaping garbage fire known as X11.
It hurts.

I moved the definition of Node to the header file... Never thought I'd be so happy to get a seg fault!

Many thanks to everyone!

any day lad

what in the world are you editing text with? This looks like software from the 90's that was ported to cocoa, and it looks even worse than acme.

Emacs... So exactly what what you described.

On an unrelated note, anyone know why the value of p-> Next changes between a function call?

void Initialize(Polynomial p)
{
p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);

}


int main()
{
Polynomial p;

Initialize(p);
printf("Address of p: %d\n", p);
printf("Address of p->Next: %d\n", p->Next);
}


And output is below:
Printing P->NEXT: 0 /* In function Initialize(p) */

/* In main */
Address of p: 136380470
Address of p->Next: -1991765899

looks like some type of vim application

functions only change the inputted values locally
if you want to change p's value use a pointer
pass the function &p and use it in the function as p*

Rate my 7th C++ program
#include
#include
using namespace std;

enum class monster_t {
ogre,
orc,
dragon,
giant_spider,
slime
};

struct monster_detail {
string name;
int health;
};

struct monster {
monster_t type;
monster_detail detail;
};

string get_type_string(monster_t m)
{
switch (m) {
case monster_t::dragon: return "dragon";
case monster_t::giant_spider: return "Giant spider";
case monster_t::ogre: return "ogre";
case monster_t::orc: return "orc";
case monster_t::slime: return "slime";
}
}

void print_monster(monster m)
{
cout

nice to hear

are you going through a game development book?

You have no taste user. Code like that is the only reason I still bother with this crap.

Nope, it's learncpp.com/
Pretty nice resource if you ask me

Oh duh...

I guess I just forgot about this because I was working with pointers and assumed I could change values will-nilly

My only concern is that it's not very prone to being expandable (what if you had 100 monster types? A gargantuan switch/case statement isn't exactly something you would want to type out)

I recommend having an array of structs and a file for monster names... But not really into game development (yet) so take my concern with a grain of salt

2/10
all pretty silly
it would be smarter to have a map that maps strings of monster names -> structs of monster stats

>not creating a pure Linux opengl es context by using generic buffer manager and kernel mode setting
>not creating your own hardware accelerated graphics
>not grabbing input directly from evdev

i'm not a game dev but to me it seems like it'd be better organized if you make a class for every monster than inherits from the monster class. also, if you're not trying to do OOP stuff don't try to learn cpp

This kind of shit is why I'm not productive in Linux. I end up fucking with the env endlessly instead of working.

We need a pastebin.

found an old fizzbuzz i wrote a few years ago. what was i thinking

#include
#include
#include

#define Oo 100ULL
#define __(oo,oO)\
for (o=(Oo*(oo)>>(oO));o>(oO)))OO ++[O]

int _o(const void *o, const void *O) { return
((*(uint64_t*)o) >> 48) > (uint64_t)(*((char*)O + 6)) ;}

int main(void)
{
uint64_t oo, oO, o, O [Oo * 0x1bbbbbbbd4 >> 36], OO = 0;

__(0x3e0f83e1ull, 35) = (o 060; oo =o;
while (!(oO^ (o [O])) && (o [O]&16711680))
printf("%s", (char*)&o ++[O]);
printf(!(o ^oo) ? "%s\n" : "\n", (char*)&o [O]);
} return

0;
}

What should be on it?

But that's the purpose of Linux, of programming. Making programs for other people is for idiots. Do it for yourself

...

If you're dispatching on type (in your case the big switch statement) you should consider a polymorphic approach instead.

Nigga I'm lazy. I have work to do unrelated to my environment, and I generally would like to get that work done. The problem with Linux is sharpening that particular axe is alluringly straightforward, so if I don't check myself I end up grinding metal for hours instead of just chopping the fucking tree down. As weird as it sounds, knowing nothing about how the dev tools I'm using work under the hood leads to far greater productivity for me.

>Making programs for other people is for idiots.
That's pretentious as fuck. I write code for people who can't, but will pay me for my efforts. In turn I pay contractors, attourneys, doctors, etc. for services I need but don't have the time to become an expert on. Eventually you'll need to pay for someone to do something you can't. That doesn't make then superior to you, and you knowing how a computer works doesn't make you superior to others.

If you don't want to define Node in the header, you could also have used a function (inside the header) that took a struct Node pointer and returned the next of it. That's why the error existed. The struct definition was hidden inside the implementation, so the compiler doesn't know how to dereference it in main.

>inheritance
lol

Innovation! This new version allows the dividing planes to not be positioned perfectly at the center of the sphere. This means that elevation changes won't be forced into symmetry at antipodes.

Next time you're having problems, try wearing some thigh-highs and girl clothes. They always help me solves any issues in my programs.

RTFM and Google for Retards

Memes

1920x1080, fewer slices

Elevations:
Magenta: Z < -2
Blue: -2 < Z < -1
Cyan: -1 < Z < 0
Green: 0 < Z < 1
Yellow: 1 < Z < 2
Red: 2 < Z

Where Z = (pixel's elevation minus mean elevation of all pixels) / standard deviation of all pixels' elevations, of course.

These are correct responses

This is not

this guy is just being edgy

There are good arguments to me made against OOP but "lol inheritance" is not one of them.

EVERYTHING in C is PASS-BY-VALUE. Which is why you pass pointers to stuff to save your results outside a function. You pass-by-value a pointer so that when you dereference it the memory pointed at is the same.

Polynomial Initialize()
{
Polynomial p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);
return p;
}


void Initialize(Polynomial *x)
{
Polynomial p = (struct Node*) malloc( sizeof(struct Node));
p->Next = NULL;
printf("Printing P->NEXT: %d \n", p->Next);
*x = p;
}

Isn't multiple inheritance the feature that's looked upon with disdain? And if I recall correctly, C++ is the only major OOP player that supports it.

Inheritance in general is viewed in a far more negative light than it used to be.

Extending functionality in a way that doesn't require dynamic dispatch is done with mixins or composition.

Dynamic dispatch is the only reason to model with inheritance, and it's not a very good one with today's languages.

Thanks!! I kind of completely forgot about pass by value (because I'm kind of used to pass-by-reference in sepples)

Everything works now! I even made an addition function!

is there like a cheatsheet for common/useful methods/imports (in java)?

ive done c++/c# for a few years now as its the standard at my school and while learning java im having trouble thinking of the useful methods i could use instead of doing everything manually.

stuff like string.replace() is super basic but i was doing that shit manually with loops for too long before realizing it was a thing.

Simple worldbuilding...
>Magenta/blue/cyan: Ocean
>Green: Continental shelf
>Yellow: Habitable land
>Red: Uninhabitable mountains/plateaus

In this 4k image, we have one big continent, composed of a big landmass, a small landmass, and a bunch of smaller islands. The continent technically extends underneath the northern ice cap, and there are a few undiscovered islands (yellow dots in the upper-left area of this picture), since the people living on the bigger landmasses haven't yet invented ocean travel.

A lot of people criticize multiple inheritance, whether or not that's fair is up for debate. Python also supports multiple inheritance. Java classes may implement multiple interfaces which is sorta like multiple inheritance.

But what we're talking about here is _not_ multiple inheritance. Multiple inheritance is when one class can have multiple parent classes. In this situation we're talking about one parent having many subclasses, which is considered perfectly fine among people who are into OOP.

There's a growing but still certainly minority opinion that inheritance in general is "bad". This is a position that's come out of seeing people abuse inheritance and a few vocal high-profile language designers advocate "composition over inheritance" which is not a blanket dismissal of inheritance but a statement that inheritance is not the solution to every situation where you want to reuse code.

Usually when I'm using a language I'm not sure familiar with, I scoure the documentation for something I want and if I don't find it very quickly I'll write it myself.

The java documentation is absolutely fucking garbage because you have to go to the parents of the parent of the grandparents to see wherever the fuck a method exists and its signature. Just google shit and you more likely than not find a solution with an example on stack overflow from people tired of the same garbage.

This is one reason why I love Racket, it has absolutely excellent documentation that makes it very easy to find out how something is supposed to be used and find related functions for the same kind of data.

multiple inheritance is if you had "Slime" inherit from "Monter" and also from "DungeonCritter". what i described isn't multiple inheritance

If I had to devote my energy to learning a language that will get me employed between clojure and Haskell, what do you recommend?

redpill me on rust Sup Forums

Clojure will get you employed. As a Haskell lover who doesn't really have any interest in Clojure I still acknowledge that it has more applications in webdev jobs and the such

if you only know clojure and haskell it seems you're oriented towards app development, so java

Yes, I know. Jesus christ. The implication of my question was to clarify whether or not the user who laughed at inheritance was referring to single or multiple variety. Please read more carefully before replying.

Rust is a meme. Improve yourself at C. Unless you want to waste time fighting the borrow and the lifetime checker and putting "unsafe" before writing C.

I've been using rust for a few days now and I only ever fought the borrow checker once; it seems more than obvious how it works, does it not?

Not for C weenies

I should also mention that it's very difficult to write C that does lots of buffer manipulation, whereas writing Rust that does so is trivial. So much so that it's easier to write Rust that does the heavy lifting and export unsafe C bindings.

It is. That's how you write C that doesn't segfault. No training wheels required.

Rust is fine for its purposes. I still use C heavily but that is mainly when doing embedded and other no-allocation based stuff.

I've written >10K+ lines of rust and haven't needed to use unsafe once at all. The borrow checker and all that isn't too big a deal I don't think, and I'd just advise people to make unnecessary clones when they start of to ease in to it.

The big boon to productivity for me is that it prioritizes performance in a way which I won't be stuck at some point in the future at some wall where I may otherwise be with something like python. That and the fact that libraries and the like are so much easier to use which makes it much easier for less low-level things like api-servers and the like.

There are some things I don't really like using it for but in general, it makes you feel confident in the small details and lets you focus on the actual program logic.

If Rust was just C with a borrow checker, I wouldn't use it.
If Rust was C++ with a borrow checker, I still wouldn't use it.

C# is such an incredible language with an incredible IDE Loving it so far.

I've found it most comfortable to use a hybrid approach: Rust staticlib for high level code, compiled together with C to start and do certain syscalls

>The java documentation is absolutely fucking garbage because you have to go to the parents of the parent of the grandparents to see wherever the fuck a method exists and its signature
Inherited methods are listed on every doc page, is clicking one link really that hard for you?

How the fuck does

> Isn't multiple inheritance the feature that's looked upon with disdain? And if I recall correctly, C++ is the only major OOP player that supports it.

imply

> clarify whether or not the user who laughed at inheritance was referring to single or multiple variety

you illiterate shit?

he probably just learned what multiple inheritance is recently and wanted to use it in conversation. be easy on him

Because it's written according to the rules of the English language, and if you knew English you'd be able to correctly comprehend its meaning. As such, calling me an "illiterate shit" shows me the dire severity of your ignorance. Are you an ESL pleb?

Wrong, here's a list of the things implies:
- You're unsure of how multiple inheritance is viewed
- As far as you know C++ is "only major OOP player that supports it" (which is wrong)
- You're asking for clarification on how multiple inheritance is viewed

Nothing in that post implies it was a question directed at , nor is there any mention of single inheritance.

Points though, for calling me an ESL pleb when you can't figure out what your own post means

how do I make my own proglang

assuming proglang is short for programming language
write a parser + compiler/interpreter

that's it
implementing a basic scheme implementation for example is easy as fuck
all you really need are:
define
lambda
cond
if
else
and
or
quote
inc
dec
cons
cdr
car
null?
number?

and a few other things I'm forgetting
most of the other scheme functions can be defined in terms of the above
+ is just repeated inc
* is just repeated +
let is just a lambda
etc....

how do I write a Lisp sexp parser?

working on banging ur mom lol

I've just learned that I can put a static array inside a struct, so I can copy the entire array with only one assignment.
Pretty cool trick!

I'm not going to spoonfeed you
go see how others do it
go look into parsing in general
google it for fucks sake

you'll learn nothing if I tell you everything

It is nice that whoever made this image thinks "backend" and "web development" are two different categories and that "backend" belongs with "scripting".