/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

youtube.com/watch?v=fycgYBGUUhM
science.raphael.poss.name/rust-for-functional-programmers.html
github.com/PistonDevelopers/piston/wiki/Games-Made-With-Piston
pastebin.com/3WiUmbFw
pastebin.com/HrQbEXax
pastebin.com/QTMpZrXp
pastebin.com/kPRvRqa2
twitter.com/SFWRedditVideos

Lisp is the most powerful programming language. Also, nice premature thread, FAGGOT

Filipino is the most powerful programming language on earth.

time for another mix
youtube.com/watch?v=fycgYBGUUhM

Nah, Julia is where it's at.

Lisp is dead. Long live Lisp!

totoo yan!

Haskell

So, is Rust a functional language Sup Forums?
science.raphael.poss.name/rust-for-functional-programmers.html

It's a half-assed one.

What about Scheme?

trying to write some software for mapping out server networks in terms of how each server talks to each other

In what case would an union be usefull?
And the example please.

The only usage of union that i could understand is for easier casting between an unsigned and signed variable

Scheme falls within the Lisp family.

Unions are for reusing the same memory location with different types. If you try to do this naively (e.g. allocating for one type and simply casting to another) you may run into issues related to alignment or size. Unions deal with that for you.

Overrated dynamic shitlang. Pretends to be functional, but the standard forces scheme implementations to include a bunch of mutable data structures, while including no efficient persistent data structures, meaning that Scheme programs written in a functional style are bog-slow compared to say, Clojure ones.

Also, fuck the cultural overempathis on explicit recursion and fuck call/cc especially. You know a functional construct is confusing when even Haskellers hate it because it produces weird and incomprehensible code.

Scheme has a powerful macro system and higher order functions. Use those, write structured code. Don't use that explicit tail recursion faggotry.

Also, the standards committee deprecated the only good compiler that the language ever had. It would have been an okay language if Stalin was still around to optimize ruthlessly.

Think implementing a compiler or interpreter.

struct datum {
enum datum_type type;
union {
int datum_int;
double datum_double;
struct string datum_string
/* ... */
};
}

That's a tagged union and the most popular use of unions I know of.

Right. Most modern language include that as a separate construct since it's by far the most common use of the feature.

Another use I can think of is look how in_addr_t is implemented on most systems(at least linux/BSD).

It's 32-bit IPv4 address but creates a struct/union of it to access bytes in the address without bit operations.

It works but isn't necessary at all. Convenient though for the person writing things that take these address.

A webcam game using webrtc, and canvas for motion detection and facial detection.

Why even ask what people are working on, the only thing anyone here works on is their next new bait post.

I'm working on a game in Rust.

(usually wrapped in sockaddr_in), forgot to mention.

sockaddr, although is a special thing in the POSIX library isn't usually implemented with a union because a lot of those types are not on every system so they do:

struct sockaddr {
type;
char sockaddr_data[sizeof(BIGGEST_POSSIBLE_VALUE)];

And then cast it internally.

meta

care to share anything?
im interested in seeing what rust game code looks like.

I just started.

github.com/PistonDevelopers/piston/wiki/Games-Made-With-Piston

Which is why you have to do shit like:

struct sockaddr_in sin;
sin.sin_type = ...;
/* ... */
connect(fd, (struct sockaddr *)&sin, sizeof(sin));

It's retarded but it comes from before anonymous structs/unions were standard.

Although I have to admit, for the time this is good "generic" sockets. Although it's almost on par with qsort() being generic, they tried.

how do i properly write this constructor

class TScreen {
std::vector mScreenButtons;
TScreen( std::vector && buttons, ... ) : mScreenButtons(std::move(buttons)), ...{ ... }
}


i want to use this class like so

std::vector screenOneButtons = {
{//construct a button},
{//construct a button},
....
};

std::vector screenTwoButtons...;
//repeat until i have all the necessary buttons

std::vector Scenes = {
{ screenOneButtons, //etc},
{ screenTwoButtons, //etc}
}


please help

rewrite it in lisp

>i want to use this class like so
Have you tried lisp? It's the only only language I know of where you spend more time defining how you'll write your code than actually doing it.

It's pretty cool in that sense though, although not very practical.

have you tried lisp? why make shit up?

Learning category theory.

It has many traditionally functional features, so sure it's functional.
This seems like a nice Rust guide.

Hi frens,
Next year I'm going to learn Java, PHP and MySQL from an incompetent teacher to make a database. What's the best ways not to get screwed in the ass by this.

Java web forum

Forget about Java and PHP. Retain all the SQL that you end up learning.

Piston is a really fucking bad library. It was haphazardly made right when Rust came out, then Rust changed a lot and Piston stayed this fractured mess of bad Rust features, Java-esque overengineered APIs, and shitty documentation.

I actually started this year, but the only Java project she taught us was Hello World. For the year end test next year, we're expected to finish a fully functioning system. wat do

>the standard forces scheme implementations to include a bunch of mutable data structures, while including no efficient persistent data structures, meaning that Scheme programs written in a functional style are bog-slow
This is why it was good that Racket broke off and is no longer technically a Scheme. In Racket, cons is completely immutable, and they offer immutable and mutable variations of sets, hash tables, and arrays.

The only lisp experience I have is reading SICP. In ch. 2 they told you to make the syntax fit how you want to program, it followed to the end of the book

It might not be CL or racket taken to the extreme but I enjoyed that aspect of scheme. It's almost the only thing I really enjoyed about the book.

You write the program first, it doesn't work at the time but you write the missing parts until it works with the code you want it to.

It's design over programming(within reasonable boundaries).

>It's design over programming(within reasonable boundaries).
Developing software should be primarily about design. When you have a good design, the programming is just busywork (well, it can be fun in its own way). This applies to all languages

The immutable data structures in Racket's standard libraries are just the same as the mutable ones but const. They are not persistent. If I have an immutable vector and want a copy with one element changed, I have to change the entire vector.

To write functional code in Racket you're still very dependent on third party libraries for data structures.

Maybe so, but I lied. The scheme macros made it solid. I don't just want x component doing this and interfacing with y component.

I want what I wrote to be how it works. I wrote the "main" of the program, I just adjust the code to fit my idea of how it works on this abstract basis.

Although the abstract sometimes has to be adjusted, this language was made for this crap.

It's what I like about it, it's not the regular how do I go about this? It's how should it look in the first place.

well if you enjoy it, then by all means
just remember lisp isn't defined by that methodology, despite what the zealots may say

>They are not persistent. If I have an immutable vector and want a copy with one element changed, I have to change the entire vector.
OK, the immutable vectors are not very good, but making persistent changes to e.g. a hash is extremely easy (just (hash-set hsh k v) )
It's not that bad to pull in a single dependency for e.g. finger trees. If you know of a data structure that you'd love to have that isn't in Racket, please let me know as I'd be glad to implement it.

*copy the entire vector.

Basically, Racket is not much better than the average Scheme imho. It has the same warts as most other Schemes.

At this point I think that emulating Scheme is much more of a liability than a benefit. Anyone who wants to make a functional lisp should just make a functional lisp and break off Scheme entirely, rather than trying to achieve some kind of backwards compatibility with it.

I don't mind having mutable data structures. Forced immutability is not the point. Efficient immutability is, so that I can write immutable programs without making my linear algorithms quadratic.

>zealots
I don't see it even close to that, and I don't care about the "lisp methadology".

I read SICP, because probably memeing but there's a single thing that marked me and that's how you should go about writing software.

Almost the top-down approach but you go slightly beyond it, rewrite syntax until top code fits your needs.

>I wrote the "main" of the program, I just adjust the code to fit my idea of how it works on this abstract basis.
This is what I like about abstraction. Theoretically you can do this same thing using Java interfaces, but the syntax sucks and its way too many lines of code.
What makes Lisp powerful is the idea that a program should directly specify what it is supposed to do. Usually this specification isn't going to fit neatly into a standard variable/function/application language like C, Java, Python, so you should be able to create a DSL to better represent what your program means.

>Basically, Racket is not much better than the average Scheme imho. It has the same warts as most other Schemes.
Maybe you could point out some warts other than just "inefficient data structures".
How much have you used Racket? What I've found after working with Racket a lot is that it's a rabbit hole -- at first, it feels just like Scheme, but when you learn more and more idiomatic features, you realize it's not really the same at all. The two biggest features are for loop variations, and pattern matching. Racket also strongly emphasizes making structs when defining new data. In Scheme, this is such a low priority that define-record isn't even guarunteed to exist.

>At this point I think that emulating Scheme is much more of a liability than a benefit. Anyone who wants to make a functional lisp should just make a functional lisp and break off Scheme entirely, rather than trying to achieve some kind of backwards compatibility with it.
As I said, Racket no longer aims to keep backwards compatibility with Scheme. It retains much of the traditional terminology (cons, car, cdr, assoc, member), but as a big example, Racket's macro system, when you look beyond syntax-rules, is **completely different** than Scheme's.

>I don't mind having mutable data structures. Forced immutability is not the point. Efficient immutability is, so that I can write immutable programs without making my linear algorithms quadratic.
Slow data structures aren't a language problem. They're a library problem. Could you tell me exactly which data structures you want?

spent three hours today tracking down a singlle bug in like 50 lines of code

THREE HOURS

Did you learn something? If you did, you just gained 3 hours of knowledge that you would have spent jerking off.

Racket has good third party libraries for data structures. My main issue is with the fact that the standard library does not include them, which leads to an abuse of linked lists for everything, which is a pervasive problem in most lisps.

That means that the average Racket library will be slower, because the users of the language won't be steered into an efficient data structure by default. Ideally, you should have a small core of efficient data structures like persistent lazy lists, persistent strict vectors, and persistent strict hashmaps/hashsets, which most users of the language use as a standard to minimize the need for conversions. They should be at the top of every introductory tutorial to the language.

If you don't steer users new to the language towards efficient persistent data structures from day 1, people won't use them across the board, and the average performance of code written in the language will suffer. It can cause people to think that FP is inherently slow and/or memory inefficient, when in fact the penalty exists but is usually just a log factor or two.

My issue with the scheme standard/heritage is that it mandates standard vectors and maps as part of the standard library. Racket still has those and immutable variants of those as legacy from Scheme, where they take up valuable language real estate.

%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
| $(M4) $(M4FLAGS) -R $(M4BASE) \
| $(CC) $(CFLAGS) -o $@ -x c -c -

When the C preprocessor sucks, it's time to try some shitty fucking god damn language from the god damn 60s that sucks god damn ass that's better than the other shitty fucking 60s macro shit.

Macros are painful to program, but I think I can do something by combining m4 and cpp.

I mean yeah, I always learn something. I just wish I had gotten a formal education so I'd understand how to read other people's code

like once I learned that this module I used threaded all its data, so you could actually call it with data properly and not get any response at all for a couple of seconds.
And the one today downloaded information dynamically, like you create an object but it doesn't do anything until you actually try iterating through it and read the data

its stuff like that that takes a while for me to figure out, even though I've been programming for a few years now.

Anyways the bug today was that I had created a couple of nested loops and accidentally had two variables with the same name. Which broke everything, but only occasionally..

formal education probably wouldn't help you there

That's learning dude, there's nothing pleasant about learning how shit sucks but you NEED to know this crap.

I don't know about your specific situation but if it sucks and isn't 3rd party shit, you need to know about how much it sucks and why.

Are there any alternatives? There's this other library called amethyst, is that any good?

rn im too focused on my classes to be doing this lately but i was learning to do 3d android games with opengl.

I don't know if any other efforts have been made, I just know that Piston is stale and immaturely built.

i would suck a cock if it mean that i could just post my code somewhere and have somebody tell me about all the things which are wrong with it

So post a pastebin or github or something here and we'll tell you what's wrong with your code.

do it right now lad

do you guys ever read the code that makes up modules? I imagine it'd help you understand exactly what the module does. I generally don't because its just so complex but I don't feel like documentation always tells me what the code does and how it works in practice

no_std Rust is comfy.

If I have some C++ code like this:
#include
#include
using namespace std;

any f() {
vector a;
a.push_back(1234);
vector b;
b.push_back(a);
return b;
}

int main() {
auto x = any_cast(f());
vector y;
for (auto z : x) {
y.push_back(any_cast(z));
}
}

y will be a vector of vectors of ints, but to get that I needed to take each element of x and any_cast them to vectors of ints. I can't just do auto y = any_cast(f()); for example, it causes a bad_any_cast to be thrown, even though those are the correct types. Is there any way to just cast the type of the vectors inside of the vector to the right type without copying all the elements individually?

this is always so embarrassing but here goes nothing i guess

TButton header pastebin.com/3WiUmbFw
TButton cpp pastebin.com/HrQbEXax
TScreen header pastebin.com/QTMpZrXp
TScreen cpp pastebin.com/kPRvRqa2

i feel like i'm doing everything wrong and that i'm making a ton of unnecessary copies everywhere but I have a hard time telling because i'm new to c++. i'm overwhelmed by constructors and move semantics.
std::vector gScreens;
void initScreens(){
std::initializer_list screenOneLabels = { "Button 0", "Button 1", "Button 2", "Button 3" };
std::initializer_list screenOneCallbacks = { &testFunction, &testFunction, &testFunction,&testFunction };
std::vector screenOneButtons = TButton::GetStandardButtons(screenOneLabels, screenOneCallbacks, STANDARD_BUTTON_RECT, 50, font);
TScreen S{ screenOneButtons, { 0x00, 0x90, 0x30, 0xff } };
gScreens.push_back( S );
}

void mainLoop(){
gScreens[0].Show(gRenderer, Input, DELTA);
}

int main(){
initScreens();
//init everything else and then start main loop
}

The complexity you're imaginating is exaggerated. Sometimes you'll encounter a piece of code that seems likes wizardry incarnate. It's usually somebody writing some worthless crap who had way too much time to do so.

Just ignore everybody else, don't compare yourself to somebody who wrote a bunch of papers, some autist wrote a library or anybody else. If you want to learn, it has nothing to do with best or worst. Learn for your sake, nobody else.

Otherwise, you'll kill yourself at the thought that somebody else is better.

```
is this how you do code inserts on Sup Forums?
```
if not then how?

> explicit tail recursion
you mean implicit tail calls, right?

```just use markdown retard```

\
\

[code_on_Sup Forums]
[/code_on_Sup Forums]

check the board rules

*/like this/*
translates to

like this

From the old thread:
Someone recommend me a basic project I can put on my empty GitHub. I'm tired of being a beginner who only knows how to do data structure algorithms.

Something original. Preempting your potential.

Do you have an original idea? Can you write a working subset of that to put on your resume?

Let us try to get along.

just pick something you're interested in

want to create a 3d map of something? use google earth's elevation api

want to study posting habits? create a scraper or use a site's api

want to create a simple videogame? do that

interested in competitive strategies? analyze demos from videogames

I've done all of these things at different points, they're fun
if you don't enjoy doing it you won't invest any time in it

I want to kill cheetos for meat.

No, I mean using tail recursion to write code that is effectively imperative code with gotos, while claiming that it is FP.

It isn't. It's unstructured and easily becomes impossible to follow. Use folds, dammit.

You're doing a copy anyways in y.push_back, but you can get up to that point without a copy:

for (const any& z : x) {
y.push_back(any_cast(z));
}

You just defined your own ideal of what structure is in your post.

People have opinions, yone?

Do we all agree insecure sepple hater deserves permaban?

for (const any& z : x) {
y.push_back(any_cast(z));
}

Of course, you can also do
for (const auto& z : x)

or
for (auto& z : x) {


I don't remember what the rules are exactly, but auto by default when iterating over vector will be T, but you can force it to be a (const) reference with (const) auto&

Impossible, young anime child. When you've reached the point of being an enlightened programmer you must upkeep your reputation of sperging at everybody who is wrong.

;; [LISTOF X] -> ( -> X u 'you-fell-off-the-end)
(define (generate-one-element-at-a-time lst)

;; Hand the next item from a-list to "return" or an end-of-list marker
(define (control-state return)
(for-each
(lambda (element)
(set! return (call-with-current-continuation
(lambda (resume-here)
;; Grab the current continuation
(set! control-state resume-here)
(return element)))))
lst)
(return 'you-fell-off-the-end))

;; (-> X u 'you-fell-off-the-end)
;; This is the actual generator, producing one item from a-list at a time
(define (generator)
(call-with-current-continuation control-state))

;; Return the generator
generator)

(define generate-digit
(generate-one-element-at-a-time '(0 1 2)))

(generate-digit) ;; 0
(generate-digit) ;; 1
(generate-digit) ;; 2
(generate-digit) ;; you-fell-off-the-end


This is the kind of ugly programming that Scheme can enable. There's too much empathis on recursion without necessarily banning mutability. You can't reason functionally about the above piece of code because the recursive calls are not pure, in fact they can mutate the function that will be recursively called later.

Creating message boxes from panics in no_std Rust.

Nobody deserves that except for illegal posters.

This is the one place in anything that borders mainstream celeb 17 posting, where you can tell somebody to eat a dick or that UFOs were created by tesla and that's your opinion.

Yes, you do have the freedom in small, unknown imageboards with 1 post/day but Sup Forums does it right for the amount of traffic it gets.

Don't ban unless it's blatant shitposting, or just really bad posting.

I'm kinda bummed that that net neutrality thing will make us seem racist for the collective name of 'pajeet' we've given to Indian outsource work.
How do we distinguish the political view from the practical reality of company work?
People don't give this place respect anymore. Not even me. I wrote the above before I even thought about if I'm respecting the thread content well.
I'm all for more strong moderation now.

If you're doing this for a side project, don't worry too much about extra copies. Chances are the performance will never matter.

That being said, at least for the strings you could avoid copies by having

static constexpr char button0 = "Button 0";
...
std::vector screenOneLabels ={ button0, button1, button3, button4};

std::string_view copies are cheap, but you can easily run into trouble by using them as member variables. The underlying memory can go out of scope, and the string_view will become invalid. That is not a problem with static constexpr arrays, but something to keep in mind. Still, the optimization would not be worth it to be.

What he does is blatant shitposting though, he doesn't even read posts he responds to.

It doesn't matter, if he does it to point where it bothers everybody else a 3 day ban is plenty.

Permaban is reserved for cunts who post child porn or spam shit all the time.

Somebody you disagree with that's too drunk to read your post doesn't deserve a permaban.

I want to add ncurses graphics to my terminal application. Any tips on where to start reading?

Sup Forums has no permabans anymore

thanks, for (auto& z : x) {
makes it a lot faster

Learning to use ncurses? There's 100 tutorials and documents.

It's easy to learn but everybody fucks it up. The #1 thing you need to remember while writing a ncurses application is that a terminal is the slowest display imaginable. Do not treat it like a graphics application and refresh 60 times a second. Don't redraw the entire fucking screen if you changed a single char.

Even on powerful computers it looks choppy. Refresh when you need to, and only refresh the parts of the screen that changed.

This is a gigantic difference for OpenGL but it's necessary for ncurses/TUIs.

You could have a supercomputer as your desktop but you see it right away, that TUI application that flashes white 30x/second.

>for
ABSOLUTELY non idiomatic. There are always better options:
std::copy
std::for_each
std::transform
std::generate
std::generate_n
std::fill
std::fill_n

for(;;)

while(true)

eat shit and die anime faggot

ABSOLUTELY non idiomatic