/dpt/ - Daily Programming Thread

old thread: What are you working on, Jow Forums?

Attached: hime bullying!.jpg (1280x1389, 378K)

Other urls found in this thread:

c9x.me/x86/html/file_module_x86_id_72.html
github.com/actix/actix-web/issues/289
github.com/BurntSushi/ripgrep
github.com/jwilm/alacritty
github.com/redox-os/kernel
github.com/m-labs/smoltcp
github.com/bluejekyll/trust-dns
github.com/jwilm/alacritty/issues/289
hyper.rs/
twitter.com/SFWRedditGifs

Haskell is a nice programming language
Say something nice about Haskell

Attached: anim haskell.jpg (480x480, 56K)

I don't know enough about it to say anything nice or mean

Ah, yeah, that was it. Great fuckin' compiler error.

It's Haxe baby. Making shit for a community that somehow hasn't graduated beyond Flash games? You got two choices, you got Haxe or you got raw asshole ActionScript. It sucks.

god I want to fondle Hime's private parts

enum pathology {
PGY_DEPRESSION,
PGY_ANXIETY,
PGY_SELF_SABOTAGE,
PGY_NUMBNESS
};
for (enum pathology p = 0; 1; p = (p + 1)%4)
puts("Please help. I'm trapped in an infinite loop.");

pshh
get in line

learn Haskell

#include

int main(void)
{
for (int i = 1; i

Attached: Chitose_thinking.png (720x546, 358K)

Those modulus ops completely destroy the gain of using a jump table.

I wouldn't be caught dead using a modulus for anything, under any circumstance.

You have to use modulus to test if a number is divisible by another that's not a power of 2, user.

no you don't

Show me how to do it without it.

3*(n/3) == n

In C, a member of a struct is accessed with a syntax along the lines of struct.member. In order to access a member of a pointer to a struct one must use syntax along the lines of (*struct).member. That was a bit ugly though, so they made it possible to use struct->member instead. In Go, however, they decided that this was too complicated and decided that both struct.member and (*struct).member would be represented by struct.member by hiding the dereference and making it automatic.

In Go, a function that takes a value parameter must be passed a value and a function that takes a pointer parameter must be passed a pointer. Methods, however, are different. A method that takes a value parameter can be passed a value or a pointer and a method that takes a pointer parameter can take a pointer or a value. So functions and methods have different parameter semantics and levels of type safety, even though realistically speaking they shouldn't.

This means that the method signature is not a reliable indicator of the argument that will be passed and looking at the code that passes the argument is not a reliable way of determining what a method should take or what kind of argument is being passed. Passing a pointer to a method that expects a value and vice versa is entirely legal. Fortunately since . and -> have been combined into one operator the function can still work, though not necessarily in the way you wanted it to.

This also means that object.func() can represent:
-calling a method on a copy of a struct
-calling a method on a pointer to struct
-calling a method on a copy of a pointed to struct

Much like C++'s genius decision of using references to turn explicit deferences into implicit deferences and generate hours of fun messing around with that, Go's decision to completely break it's pointer syntax was done in the name of "convenience" and "simplicity".

Attached: 1521557266314.png (417x475, 202K)

I'm learning it now. I think it's very impressive with how well planned the features are. It feels like they had a clear vision of how programmers should do things when they designed the language.

(lambda l:l(l))(lambda s:(print("A",end=""),s(s)))

Is there any way in C++ to make a plain dumb C struct without any convoluted automatically generated stuff done by the compiler?

acktually,

c9x.me/x86/html/file_module_x86_id_72.html

at least on the x86 architecture, integer division also computes the remainder (modulus) at the same time

even if true, it isn't used in what i gave

not in FizzBuzz
#include
using namespace std;

void fizzbuzz() {
for (int i = 1, three = 1, five = 1; i

I understand all the concept of abstract classes, but I can't think of any real-world applications of an abstract class, just the toy examples to demonstrate the concept. What are some real, tangible examples where an abstract class would be the right design decision to make?

Attached: 1487564032700.jpg (750x733, 131K)

How can I just give a path to a folder without giving the full path in python? It just needs to access to the folder at the same place where the program is

Abstract classes are like interfaces. For example, if you're writing a calculator you might have Expr abstract class from which classes like AddExpr, SubExpr, MulExpr, etc., inherit. Expr should have a virtual member function called eval that AddExpr will overload to add two numbers (which might come from expressions too), SubExpr to subtract one from another, etc.

>abstract
Look at this pretentious fucker here.

>Expr should have a virtual member function called eval

Attached: bakabaka.png (782x1238, 510K)

Can you point out to me what's wrong with that besides memes?

OOL ni OOP

Abstract = pretentious.

I'm a new world American.

>besides memes

At least it's not Java.

OOP is a meme

yeah multiple ways

extern "C" is probably the easiest.

That's only for linking purposes. It doesn't change the semantics of the language. I learned that the hard way once when I tried using this as an identifier in extern "C" block.

Just give up. That auto-generated stuff in practice enables the struct to behave like in C. For example, this doesn't compile:
struct S
{
int x;
S(const S & other) = delete;
};

int main()
{
S s = {5};
S z = s;
return 0;
}

github.com/actix/actix-web/issues/289
>The fastest Rust web-framework out there
>Shines in the TechEmpower benchmarks
>Is actually full of `unsafe` and literal UB
>Public API is unsound
So much for Rust being safe.

it's safe to not use

Nothing stops you from writing Rust as if it were C, which is what these guys did.

Attached: 1526820066531.png (424x335, 177K)

I think the pic gets it right. Haskell is the tsundere who calls you baka half of the time and looks down to you for the other half

>the fastest Rust web framework is the one written like C
hmm

That's to be expected. You can't write fast anything with a "safe" and highly abstract language like Rust. 1.2-3 times the performance of optimised C/C++ is what you can realistically achieve with safe Rust in non-trivial programs.

>this specific project abuses unsafe code
>that means safe Rust is slow
This means the author is most probably a C++-fag, nothing more. People have already pointed out many of unsafe blocks could be replaced with an equivalent safe code.

Can you point me out to any same or larger sized rust project thats performant and uses purely safe code?

If you discedit actix-web as a sample, please provide some comparable non-trivial optimised C/C++ and safe Rust programs with equal or better performance for Rust. Without any real world examples we can continue arguing how safe Rust is or is not theoretically as performant as good C/C++ code till morning.

Is that even surprising?
Not being negative towards Rust, it just feels intuitive that C is pretty much as fast as you can get in some scenarios.

Nice blog.

No, really. I did find it interesting to read.

Go should have been the modern c but isn't

>purely safe code
No one says 0 lines of unsafe code is the goal here, some stuff like calling C functions can only be done within unsafe blocks, the point here is that 1% unsafe code is better than 100% usafe code you get with C/C++.
>thats performant
The fastest grep out there
github.com/BurntSushi/ripgrep
The fastest terminal emulator out there
github.com/jwilm/alacritty
An OS kernel which has only like 7% of unsafe code
github.com/redox-os/kernel
TCP/IP stack with zero unsafe code outsize shims for TAP and Raw sockets:
github.com/m-labs/smoltcp
DNS client and server with 0 unsafe code
github.com/bluejekyll/trust-dns

>some stuff like calling C functions can only be done within unsafe blocks, the point here is that 1% unsafe code is better than 100% usafe code you get with C/C++.
you could write literally any language then FFI to C/C++ if this is acceptable to you

>Those modulus ops completely destroy the gain of using a jump table.
And the syscall of printing out completely destroyes whatever gain whatever other optimization you could do

I would use Haskell, but the performance of anything but Rust is lacking. Besides, other language doesn't offer the same level of safety, even when GC is involved - Rust doesn't have nil/null references for example.

Attached: performance.png (630x358, 32K)

In fact, that's not quite right. I like Haskell but the language, while not a committee clusterfuck like C++, saw a lot of transformation over the years. Nobody ever sat down to design it in one go. The impressive thing about Haskell to me is their integrity when it comes to laziness (and therefore purity). As SPJ put it, sometimes you have to "stick to your guns," which led to the monadic IO picture we see today.

Web server is literally more useful than any of those toy projects in real life.
Let me go on a rant here, i tried rust and all i can say is that borrow checker is more annoying than anything in haskell. At least haskell has elegant syntax and not sepples wannabe monstrosity.

>github.com/BurntSushi/ripgrep
Not functionally equivalent. Not supporting multiline search in particular can create many opportunities for optimization.
>github.com/jwilm/alacritty
Inconsistently faster with no proper benchmarks. github.com/jwilm/alacritty
>github.com/redox-os/kernel
What do you propose it to be compared to?
>github.com/m-labs/smoltcp
>github.com/bluejekyll/trust-dns
Post benchmarks!

Oh look, nothing of what you posted is actually faster.

Meant to link github.com/jwilm/alacritty/issues/289 for alacrity.

Rust webservers are quite fast, even if you discard actix as "not real Rust", other, proper Rust solutions, are very close.

Attached: rust-web.png (940x342, 47K)

#include

int main()
{
#define COUNTOF(A) (int)(sizeof(A)/sizeof(*(A)))

#define LOOP(I, A, N) \
for (int I = (N); I < COUNTOF(A); I += (N))

const char * a[101] = {0};
LOOP(i, a, 3) a[i] = "Fizz";
LOOP(i, a, 5) a[i] = "Buzz";
LOOP(i, a, 15) a[i] = "FizzBuzz";
LOOP(i, a, 1) a[i] ? puts(a[i]) : printf("%d\n", i);
}

Attached: bWuU8KY.jpg (1280x720, 108K)

Except none of them are fully featured and safe by current standards. Show me one on par with Go's net/http or some other complete HTTP server of your choosing.

>moving goalposts
ripgrep doesn't have to be a functional equivalent of a 50yo tool, it's just faster than all the alternatives at the same taks. I don't have benchmarks for the rest, but the performance is reasonable enough for these projects to be actively used.

Do you know any cool APIs (besides twilio)?

I'm somebody else but I was wondering something.
Why does cmd/compile/internal/syntax/scanner.go use inefficient get/unget/unget2 instead of just next/peek/peek2? It doesn't look any more elegant and it's demonstrably slower.

>moving goalposts
>look my stripped down program is faster

What do you mean "complete HTTP server"? All these servers use hyper.rs/ for HTTP, which is fully-featured HTTP library. I don't know the Go stack, but what does net/http do that hyper can't?

Hyper does not even support HTTP/2.

n=[1..100]
f=cycle["","","Fizz"]
b=cycle["","","","","Buzz"]
fb=zipWith(++)f b
fbn=zipWith (max.show) n fb
main=mapM_ putStrLn fbn

Can you read?
hyper.rs/
>HTTP/1 and HTTP/2 support.

Fair enough, my source was outdated.

At first glance simply looks like a different algorithm was used for some reason (one without lookahead). You can probably reimplement it with lookahead, if you wanted. If that actually would yield performance requires benchmarking.

Look at this and see how Rust, Go, C++, Java and C are pretty much all in the same league. Remind me again why these meme languages exist.

Out of those only Go is almost as easy as Python to develop in.

Being primitive =/= easy to develop in.

Except it does. Not to mention Go has packages for almost anything in the stdlib.

Certainly easier than in C, C++ or Rust.

Exactly, it's time for Go and Java to go.

Jokes aside tho, the benchmark is network-bounded, so it's a poor demonstration of the relative performance of the languages, refer to for one.

Conclusion: Rust is useless. Wait for Rust++.

>he doesn't program in Rust#

Attached: smug.png (800x450, 94K)

Only if you're a brainlet, otherwise the lack of generics, pattern matching, proper error handling mechanisms, etc. is surely limiting and makes writing and maintaining non-trivial code harder.

Attached: 1504973997692.jpg (700x963, 94K)

fizz = cycle ["","","Fizz"]
buzz = cycle ["","","","","Buzz"]
nums = map show [1..]
fb = zipWith3 ((max .) . (++)) fizz buzz nums

Objective Rust is objectively superior- the best parts of Rust and classical OOP combined and no borrow checker to get in your way.

is there a function somewhere that does
(f .) . g

Idk but you can define your own (..)

user, you are missing the point. It's faster to write, faster to teach and easier to read. Sure, you end up with more code because of less expressiveness but you will produce it faster and your team will be on the same page with you almost instantly.

This, abstractions like generics or "proper" error handling mechanisms require more time to reason about and write properly. Pattern matching is just syntactic sugar.
The fewer features a language has, the faster it is to write code in it. That's why Java dominates C++ in the enterprise environment.

>unironically defend the most brainlet language out there

Attached: 1504206014556.png (185x272, 6K)

>no counterarguments
Who's the brainlet here?

Attached: 46a.png (645x729, 90K)

>actually productive
>decent performance
>easy to read, teach and maintain
Not all of us can be abandonware Rust wizards.

Is there a better algorithm to implement preference in randomness than having the same value multiple times like this:
const arr = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6]
console.log(arr[Math.floor(Math.random() * arr.length)])

So a number like 0 or 1 has double the chance of being returned than 2, 3, 4, or 5?

I hope this is clear enough. I'd like to learn how to work on algorithms in a non-brainlet manner and figure /dpt/ is a better place than babby-tier /wdg/.

Post your 3 most successful Haskell programs

>66424623
>The fewer features a language has, the faster it is to write code in it. That's why Java dominates C++ in the enterprise environment.
Wrong, otherwise C would be among the most productive languages. Expressiveness determines the speed at which you'll write code. C# has lots of fratures and sugars, still one of the easiest and fastest languages to write.

>Math has a random() function

Attached: 1529340589278.jpg (560x560, 34K)

>your
Implying I write anything other than fixzbuzz. In any language.

>babby-tier
baby-tier

Why wouldn't it? Most languages have a way to generate random numbers

It has nothing to do with maths

I'm not sure, maybe it's the best way. I mean preference in randomness isn't truly random then right? Also it seems like occupying like 32 bytes of 0 and 1 is a bit of memory going to waste

PRNG's has a lot to do with math

why does this not work?
#include "stdafx.h"
#include
using namespace std;

int drawTree(int x);
int i;

int main()
{
int treehigh;
printf("How big is the Tree?");
printf("%i",drawTree(scanf_s("%i", &treehigh)));
system("pause");
}

int drawTree(int x) {
for (i = 0; i < x; i++) {
printf("%i", x);
return i;
}
}

scanf doesn't return the value, it sets the variable.

>log, abs, min, max, random, nigger, ur mom

Because scanf_s returns the numbers of filled arguments, not whatever is read into the first one? Also, use \n.