/dpt/ - Daily Programming Thread

No time for love edition.

What are you working on Sup Forums?

Previous thread:

Other urls found in this thread:

github.com/cgati/yes/blob/master/src/main.rs
github.com/coreutils/coreutils/blob/master/src/yes.c
github.com/coreutils/coreutils/blob/master/src/true.c
reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/
matthias-endler.de/2017/yes/
github.com/freebsd/freebsd/blob/master/usr.bin/yes/yes.c
github.com/openbsd/src/blob/master/usr.bin/yes/yes.c
github.com/carllerche/mio/blob/master/src/sys/unix/epoll.rs
jvns.ca/blog/2017/06/03/async-io-on-linux--select--poll--and-epoll/
github.com/coreutils/coreutils/blob/master/src/true.c#L38
wiki.installgentoo.com/index.php/Programming_resources#Python
twitter.com/SFWRedditVideos

I'm bored.

rate my rust code
github.com/cgati/yes/blob/master/src/main.rs

well suggest me an alternative then?
like the ancient irc, mailling list eh?
it's easy to use(like just click a link and you in), popular.
i can understand that there is concern about your privacy when all your chat stuff go through their server though.
so suggest a alternative pls.

Has anyone tried using Python's async tools with PyQt5? (through Quamash or otherwise)

Noticed any performance problems?

going to their house

>new thread before bump limit
Kill yourself.

>Cow
For what purpose?

sooooo you can only colaborate with people within your reasonable travel distance eh?

It was apparently at 309 when he posted, maybe someone just deleted a post afterward

>new thread exactly at bump limit
Should still kill himself.

In other news I changed the way strings are assembled in my project I posted yesterday. This removed the need to convert everything to string when appending. For example
std::string message = "unexpected type ";
message += (type->kind == TOT::TypeKind::Boolean ? "bool" : "int");
message += "["; message += std::to_string(type->dimension); message += "] ";
message += "instead of "; message += (expected->kind == TOT::TypeKind::Boolean ? "bool" : "int");
message += "["; message += std::to_string(expected->dimension); message += "] ";

becomes
std::ostringstream message;
std::string lhs = type->kind == TOT::TypeKind::Boolean ? "bool" : "int";
std::string rhs = expected->kind == TOT::TypeKind::Boolean ? "bool" : "int";
message

reposting from last thread

Can someone tell me if my English translation of

To avoid copying "y\n" in the one time setup.

AnyType needs specifically to be comparable to some supertype of AnyType.

irc is flawless

>not waiting for end of page 10

Downloaded a large C project
Copied one of the structs in a h file and edited it under a new name in the same .h file
Try to compile a C file that uses the original struct, but with the name replaced with my new struct

dereferencing pointer to incomplete type

I don't get it

> This commit increases output throughput as measured by target/release/yes | pv > /dev/null
> and target/release/yes aaaaaaaaaaaaaaaa | pv > /dev/null after 20s from (3.8 MB/s, 30.2 MB/s) to 4.5GB/s.
> As a baseline, the GNU coreutils 8.21 implementation gives (140MB/s, 769MB/s).
GNU-fags BTFO again.

jesus fucking christ, is this the power of rust?
>separate /src directory for one file
>66 lines for the program
this would be 10 lines of C

muh safety and muh control bruh

You mustn't have declared it properly.

>this would be 10 lines of C
github.com/coreutils/coreutils/blob/master/src/yes.c
>128 lines

Yes, this is the power of coreutils.
github.com/coreutils/coreutils/blob/master/src/true.c
81 lines for int main(){return 0;}.
Also, that includes documentation.

>want to use Rust
>want to use the piston_window crate
>error: Could not compile `bitflags`.

...

Both are OMG OPTIMIZED.

>OMG
kys

C is a shitty language

Is there even a decent language out there? C is too low level, C++ is a clusterfuck, Erlang and Elixir are too slow on computation and niche, Python, Ruby, Java are dogshit slow, C# has too few libraries (though I'd love to use .Net Core with GTK on Linux), dont even get me started on Rust. Does anyone know of a good language?

This would suggest you're using the type when only a forward declaration has been defined. Is your full struct defined further down the file than when you're trying to dereference it?

It's not about documentation tho, it's about speed: reddit.com/r/unix/comments/6gxduc/how_is_gnu_yes_so_fast/ , matthias-endler.de/2017/yes/ . Naive 3-lines solution would be orders of magnitude slower.

You can actually see FreeBSD using the same approach as the Rust implementation github.com/freebsd/freebsd/blob/master/usr.bin/yes/yes.c , and OpenBSD folks not only not giving a fuck about speed, but also wasting your time on useless "pledge" syscall just in case there's a vulnerability in the other 3 lines: github.com/openbsd/src/blob/master/usr.bin/yes/yes.c . I guess this is the price of "safe C".

>C# has too few libraries
wut?
how do you define a good language?

> Is there even a decent X out there?
> dont even get me started on
Every time.

I'm a cunt, I typo'd the name.

the official connect for MySQL on .Net is broken right now, and GTK doesnt even work on .Net Core, once these are fixed I'd jump shit as I love C# and .Net though
>no native polling support
>no libraries for linux system programming
>decent

Gahnoo is never optimized.
You can do it high performance without close to 100 sloc. Your approach is bloated as hell.
>c
>too low level
There are libraries for that.

38th for lisp is the most powerful programming language

>no native polling support
What are the mio and tokio crates.
>no libraries for linux system programming
What is the libc crate.

>implying mio and tokio do poll() and select() using the Linux API
>implying the libc API is sufficient
Rust is simply not ready senpai

fn fill_up_buffer

>focusing on sloc this much
It's about readability as well. But whatever way you format your code, you still have to allocate a buffer on the stack, copy the argument into the buffer as many times as possible and then call write in an infinite cycle.
>implying mio and tokio do poll() and select() using the Linux API
No one uses poll and select anymore, grandpa, mio uses epoll on linux: github.com/carllerche/mio/blob/master/src/sys/unix/epoll.rs , and tokio uses mio.
There are no generics here tho.

How so? I don't know much about Rust in general; are generics the problem here, or lifetimes?

>no one uses poll and select anymore
You just exposed your lack of experience in linux system programming, gg. Come after class so grandma can teach you how to program.

In a curses program, I have
main_win = newwin(LINES-1, COLS, 0, 0);
stat_win = newwin(1, COLS, LINES-1, 0);
but nothing is showing up when I output to main_win. stat_win works as expected.
Do I have to do anything with stdscr beforehand? At the moment I'm just writing to stdscr, but calls to clear() also clear stat_win, which deletes any status messages before I can see them unless I block with getch() or something first.

I am going to start writing a MIPS assembler. I am already familiar with the architecture and its instruction set, having worked with it in the past and programmed directly in assembly, my only question is... what's the correct layout for the .data section? Ho am I supposed to translate those declarations in binary?

Oh, right, let me correct myself - only retards use poll and select on Linux right now.

You guys appear like you know what you're talking about. Maybe you can bless me with a quick "poll vs epoll vs select" post?

Languages really exemplify the whole "worse is better".

If you ask anyone who's studied the matter reasonably for an objective worst language in general use, you'll be pointed at Javascript or PHP. But these languages run the vast majority of websites.

Answers on "best" languages would be more varied, but when people describe Haskell, oCaml, F#, or Clojure, they are talking about languages just about never used in business.

I think I'm just going to kill myself. I no longer feel motivated to do anything programming related either from lack of investment or my shitty vision making using a computer annoying. All the jobs on offer are shitty web dev or application dev with C#/java. I don't have any other interests or hobbies. Even if I got a job I'd never spend the money.

jvns.ca/blog/2017/06/03/async-io-on-linux--select--poll--and-epoll/

Just use C++ while keeping the clusterfuck to a minimum. It can get insane if untamed, I'll give you that, but it's IMHO still the most versatile language if used correctly. STL containers alone are a perfectly valid reason to use C++ over C.

Yes, and 80 lines is not needed for that. Not close.

>piston
Are you doing gamedev?

Yep

I found piston to have terrible documentation. Did this change?

/* Act like "true" by default; false.c overrides this. */
#ifndef EXIT_STATUS
# define EXIT_STATUS EXIT_SUCCESS


WTF. So "false" is just "true" with a compile option. Couldn't you just read argv[0] and work this out at runtime or something?

github.com/coreutils/coreutils/blob/master/src/true.c#L38

>Those six lines of indenting

if (STREQ (argv[1], "--help"))

Did they.. did they need a macro to replace strcmp()?


initialize_main (&argc, &argv);
set_program_name (argv[0]);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);


What are these memes?


/* Note true(1) will return EXIT_FAILURE in the
edge case where writes fail with GNU specific options. */


I'm fucking dying

look at what a comppiler shits out

>2017
>C++ does
>not
>have
>ranges

I'm not sure (since I can't even get the libraries to compile so I didn't do much with it) but so far the documentation isn't that great. I'm coming from SFML which has much better documentation so it's a bit frustrating.

C++17 on the horizon though, let me find the doc...

Why do you want a "good" language?

I mean C++20 ffs

C++20 is over-hyped.

The modules TS, currently is a joke. Better off writing old #includes instead because the C++ modules brings close to nothing new to the table.

C++ will never have a standard build system. C++ will never have a standard package management system.

Range v3? I saw what it is. If you don't adopt UFCS (which not going to adopted), there is almost no point in having ranges.

Even after that, the C++20 update will be a broken ass update and it'll take C++23 to fix all those. Remember C++11?

Why can't there be the perfect language?

because nobody cares about making a "fixed" C++ apart from the faggots who believe fixing it involves adding a GC

What's an actual, relevant piece of software I could develop in my free time using C++?

>standard build system
>standard package managing system
Cmake is the standard where I am.
It supports modules just fine, no need to involve C++ in that shit.
C++11 is a fine language, bitching about it probably means you are one of those people who claim they love science.

I think at this point, there are really only three options:
1. Use a library like boost or ranges.
2. Roll your own range code to be compatible with STL iterators (just something to emulate python's range(...)).
3. Do something like
std::array arr; std::iota(arr.begin(), arr.end(), 1);

and hope for the compiler to optimize it away (the most pajeet tier option).

I'm looking forward to/hoping that there are metaclasses. Those seem fun and interesting. C++17 really made template metaprogramming much more bearable with fold expressions and structured bindings.

>Cmake is the standard where I am.
Where in the standards does it say that CMake is the standard? Also, I'd rather start fire with rocks rather than use CMake abomination. You need a proper project manager, like cargo, pip, or dub. Bjarne wants this done but won't do anything about it. Because he knows people would rather use VS instead of shitmake.

>bitching about it probably means you are one of those people who claim they love science.
What is that supposed to establish?

>one of those people who claim they love science
This so much lol.

Any Javafags here? I want to kick your ass

I just checked a bunch of projects in my field, they all had a CMakeLists.txt in their project, you can use whatever you want.
I agree that cmake is a pain to work with, but you just need to learn how it works and then it is fine. (just like any other tool).
I also write a lot of projects that use ROS and they use catkin which is basically a nice interface for cmake.
I have never used VS, but it might be the only IDE that doesn't make it easy to use cmake.
As I see it, you can learn to write cmake in a day, then writing it manually is fine.
If anything, I would love to see improvements in cmake so it could become the standard.
There are so many ways to use cmake, so a standard way to include a library or module would be great.

>would love to see improvements in cmake so it could become the standard
Not taking years to build a new release would be a good start.

umm yes kick me daddy

What's your favourite lang?

If ISO C++ drops the new build2 system in favour of shitMake, I will quit my job and kiss C++ goodbye. Plain and simple.

FUCK Cmake.

Hope you're ready to get beat up nerds

why does this eat an entire core?
while true:
for i in ["/","-","|","\\","|"]:
print "%s\r" % i

>Python

>>no libraries for linux system programming
>systems programming
>libraries
LMAO nigger just make them syscalls yourself you fucking faggot.

Just fuck my shit up, daddy!

>why does an infinite loop without blocks on disc or network IO eats an entire core
Gee, I wonder.

>I'd love to use .Net Core with GTK on Linux)
Please. If you are planning to use .NEET don't come to linux. For good reasons, we don't want them

i made a typo, the "true" is supposed to be "True"
and yes its python 2 code taken directly from LPTHW, a somewhat Sup Forums approved tutorial book

When describing your project on a portfolio, is it ever necessary to talk about any of the actual implementations you've made?
For example would you mention the use of operator overloading in C++ as part of the design of it?

How could I go into a program that is given a name, googles for an image of that name, and stores it in my pc.

Sure, if that implementation makes it stand out in some way. So no, I wouldn't mention operator overloading, because it's C++ 102 material.
But if you can say something like "fully asynchronous backend", then definitely do.

Google probably has an api

>zed shaw
>approved on Sup Forums

You don't write about what you did, you write about what you achieved. It's a subtle difference.

>and yes its python 2 code taken directly from LPTHW, a somewhat Sup Forums approved tutorial book

HAHAHAHA

I've heard and seen those in action, but I am not sure if one should pay for it.

And I've tried checking it out and creating an account but it just.. asked me for a credit card number.
I'm not so sure..

Define relevant.

wiki.installgentoo.com/index.php/Programming_resources#Python
its on the Sup Forums programming books section. listed last and probably least but I've got a copy nonetheless and I intend to give it a read

OS, compiler, game engine.

Just don't listen to him on the subject of C.

thanks for the suggestion, i have K&R for that. plan on getting into that after i finish this

and heres something i like to do is make a simple proportion calculator. babbys first babby scripts
print "Format is a/b = c/x\n The script calculates for X"
print "integer for a:",
a = int(raw_input())
print "integer for b:",
b = int(raw_input())
print "integer for c:",
c = int(raw_input())
x = b * c / a
print "%i / %i = %i / %i" % ( a, b, c, x)
print "x = %i" % x

Is there ever a reason why C++ classes shouldn't be inherited as virtual all the time?
So for example if C1 is inherited by C2 and C3, then C4 inherits both C2 and C3, that'd cause the issue where virtual would be needed. But why isn't that always the case? Is it just a legacy issue?

Big class hierarchies are a thing of the past. Also composition over inheritance.