/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?
Old thread: Functional Programming Thread:

Other urls found in this thread:

raw.githubusercontent.com/Palm-Studios/sh3redux/master/include/SH3/arc/file.hpp
raw.githubusercontent.com/Palm-Studios/sh3redux/master/source/SH3/arc/file.cpp
raw.githubusercontent.com/Palm-Studios/sh3redux/master/source/SH3/arc/types.cpp
strawpoll.me/12023125
wiki.osdev.org/Makefile
gnu.org/software/make/manual/make.html
twitter.com/SFWRedditGifs

First for D.

>Java
>C++
>Python

>D
RIP

Find the mistake in the text below? Why can't you? Why is it perfect?


Just use C and D. If you really want you can use C++ instead of/alongside D.

If you want something on a VM with support/libraries all over the place then use Java. Second winner in this category is C#.
You can write the performance critical parts in C.

Plus choose one scripting language with good C interop. Anything you like.

If you want something with FP then choose between OCaml, F# or StandardML.

Lisp/Scheme is good for the learning experience, embedding and when you know what you're doing. If you want a Scheme(-like) language then use Racket.

Anything else is domain specific bullshit.

C++ is hard only if you are a retard

Qt or wxWidgets? I heard Qt has gigantic binaries with static linking and requires you to put qml files everywhere.

Qt ofc.
>I heard Qt has gigantic binaries
All the dlls make maybe 20-30Mb total, who cares.

Also, I saw something about it faking the native theme. Does that mean if you have a custom theme on XP or Linux that it'll look messed up or does it try to look like the enduser's theme?

What are some other procedural languages that support something like goroutines?

Is pic related true

>qml
it's optional, you don't have to use qml, you can use .ui forms which are transpiled to cpp/hpp and linked or just create the widgets from within your code

alright Sup Forums I feel retarded. I'm trying to make this damn thing rotate but it just stands still.

//A simple spinning graphic of the tsukuru icon
#include
#include
#include

using namespace sf;
using namespace std;

int main()
{
RenderWindow window(VideoMode(100, 100), "SFML works!", Style::None);
Texture tsukuru;

if (!tsukuru.loadFromFile("icon.png"))
{
//error here
}

Sprite icon;
icon.setTexture(tsukuru);
icon.setOrigin(Vector2f(50, 50));
icon.setPosition(50,50);

Clock clock;
Time elapsed;
Time elapsed2;

float scale = 1;
bool flip = false;

while (window.isOpen())
{
elapsed = clock.getElapsedTime();
if(scale = -1)
{
flip = !flip;
}
else
{
if (flip == true)
{
scale = scale + 0.014;
}
else if (flip == false)
{
scale = scale - 0.014;
}

}
icon.setScale(scale, 1);
elapsed2 = clock.getElapsedTime();
cout

>IOS
>Language
What?

Is chapel the best language?
>manual memory management
>first-class concepts for concurrent and parallel computation
>type inference
>backed by DARPA
>lambdas
>oop

>oop
And it's complete garbage.

Your compiler might bitch about shit if you don't have the C++14 flag enabled, you can just rip that chrono stuff out if you want. Had to do it to get my computer to not melt.
idk wtf ur trying to do user but here
#include

#include
#include

using namespace std::chrono;
using namespace std::chrono_literals;
using namespace sf;
using namespace std;

const nanoseconds MAX_FRAME_TIME = 16666667ns;

int main()
{
RenderWindow window(VideoMode(100, 100), "SFML works!", Style::None);
Texture tsukuru;

if (!tsukuru.loadFromFile("icon.png"))
{
//error here
}

Sprite icon;
icon.setTexture(tsukuru);
icon.setOrigin(Vector2f(50, 50));
icon.setPosition(50, 50);

float rotation = 0;

while (window.isOpen())
{
high_resolution_clock::time_point start_time = high_resolution_clock::now();

rotation++;
icon.setRotation(rotation);

window.clear();
window.draw(icon);
window.display();

nanoseconds frame_time = high_resolution_clock::now() - start_time;
if (frame_time < MAX_FRAME_TIME)
std::this_thread::sleep_for(MAX_FRAME_TIME - frame_time);

}
}

I'll read about i guess. I have no idea how it works or what it's members are. I'm pretty used that the time isn't the problem though.

The cout

Is this an example of good or shit c++??

raw.githubusercontent.com/Palm-Studios/sh3redux/master/include/SH3/arc/file.hpp

raw.githubusercontent.com/Palm-Studios/sh3redux/master/source/SH3/arc/file.cpp

raw.githubusercontent.com/Palm-Studios/sh3redux/master/source/SH3/arc/types.cpp

I don't see any code that does any rotating.

Looks not too bad, but could be improved.

Looks good to me, the author knows how to use the STL and the modern C++ and the code itself is pretty clear.

icon.setScale(scale, 1); sets the scale in the x dimension. It's 3d rotation of a 2d disc along the x axis.

Your greedy regexes are probably fucking you up by consuming your slashes, along with those trailing slashes that you may or may not want. Use non-greedy regex (.*?) or at least don't have it match your slashes ([^/]+)

then this is your problem:
>float scale = 1;
>if(scale = -1)
the if statement is true, so all you do is flip the bool and never touching scale,

Thanks lads, I'm working with this dude and as a C programmer, wasn't too sure if this was good modern C++ or a clusterfuck. I usually just use cpp as C with classes haha.

As a side, could you possibly explain the benefit of a unique_ptr as opposed to a raw pointer and delete in the destructor.

Ah thank you. I'm retarded.

In that scenario it just serves the role of a separator of concerns.

> could you possibly explain the benefit of a unique_ptr as opposed to a raw pointer and delete in the destructor.
It's impossible to get a dangling pointer, to forget to delete, or to double delete it. And all this compiles to a no-op and entirely free at run-time.

Thanks again guys, I seriously need to brush up on modern C++ practices.

Oh sorry, I moved the question to but I will see what I can do with that. I'm not 100% on regex.

>C
>Rust
>Haskell

Haha thank you. I got it working now, but it's fast as all hell, but thank you for your help. I'm gonna go to sleep now, haha.

Somewhat, but not really.

>but it's fast as all hell
the chrono thing will fix that, you can use the one built into SFML too but that one is super unreliable

I already slowed it down. I changed the increment on the change of scale from 0.014 to 0.002.

You said that the SFML time methods are unreliable. Can you elaborate on that? I don't know much about them. I haven't had to use them very much.

...

>the Unix kernel
>the

Even if you only write C++ as C with classes, why not use the features of C++ such as have a destructor?
unique_ptr and shared_ptr are just classes which contains a pointer and a reference counter.
When the counter is changed, it will automatically delete.
It is like using .at() operator to access elements as you can see if the access is valid.

>I already slowed it down. I changed the increment on the change of scale from 0.014 to 0.002.
Well if you're not using sleep or something to slow it down it'll be diff speeds depending on the computer.
>You said that the SFML time methods are unreliable. Can you elaborate on that?
Yeah, you can do window.setFramerate or something like that but I've found that even on the newest versions of SFML that the timer will randomly work at half or twice the fps that you've specified. When I used to use the SFML limiter in my program it would regularly work at half speed for no discernible reason.
The chrono thing isn't perfect either but it's quick and ez. I think SDL actually has a good, consistent FPS limiter though.

Wow, you'd think one of the people working on unix since 1981 knew his shit!

>unix
There is no "Unix" anymore.

>Well if you're not using sleep or something to slow it down it'll be diff speeds depending on the computer.
That's fine. It's only for this one computer anyway.

>Yeah, you can do window.setFramerate or something like that but I've found that even on the newest versions of SFML that the timer will randomly work at half or twice the fps that you've specified. When I used to use the SFML limiter in my program it would regularly work at half speed for no discernible reason.
>The chrono thing isn't perfect either but it's quick and ez. I think SDL actually has a good, consistent FPS limiter though.
Ah good to know. Thank you for that info. I'll look into SDL.

> unique_ptr and shared_ptr are just classes which contains a pointer and a reference counter.
unique_ptr has no counter, it's just a pointer with destructor and move semantic.

>This is the person who designs Go
Well, it explains everything.

>That's fine. It's only for this one computer anyway.
Eh, it's still sketchy. It'll prob be a diff speed between release and debug builds, maybe even between one build to another if you change a bunch of code.
>Ah good to know. Thank you for that info. I'll look into SDL.
You can also use just SDL for its timer and nothing else if you want.

unique_ptr does not have a counter though, it has a free'er/dtor and move semantics.

template
struct type_pack_element_aux {
private:
template
struct indexed_type {
using type = T;
};

template
static auto make_set( std::index_sequence ) {
struct set : indexed_type... {};
return set{};
}

template
static std::enable_if impl( indexed_type );

static std::enable_if impl( ... );
public:
using type = decltype(impl(make_set(std::make_index_sequence{})));
};


Can anyone elaborate how does the inheritance mechanism in make_set works like, and later how does exactly SFINAE kick in?

Jesus fucking chirst.
How do people defend that lagnauge?

The people designing Go also designed B (and with that indirectly a large part of C), Unix, Plan 9 and UTF-8!

That's not something you'd write in your daily code, though.

No other language have an equally powerful metaprogramming capability.

Even Hasklelfags are envious of this.

But what about Lisp?

Lisp is a children's language

>rust

Thanks for your very constructive contribution, user.

It's time for this meme to stop. Yes, Ken Thompson played some role in designing Go, but he's like 80 or something and the main designer is Rob Pike, who lives in his echo-chamber for 40 years now while producing nothing of value. Also everything in this list is an obsolete shit except for UTF-8.

Nevermind, I figured it out, that's pretty neat.

C is pretty useful for what it was designed for and Plan 9 certainly brought a bunch of good ideas to the table that are being utilized now, so as a research OS it definetly succeeded.
Not even gonna start on how Unix influenced computing.
According to several sources Go was designed by Robert Griesmer, Rob Pike and Ken Thompson equally, i.e. all of them came up with ideas and would only implement them once all of them agreed on them.
This means that Ken Thompson agreed to all ideas provided by Rob "Echo-Chamber" Pike and thus contributed to every single core concept of the language.
If you've got any source showing the opposite, feel free to let me know :^^^^)

This

I mean, for fuck's sake, Rob Pike thought it was a good idea to
>include directly from github by using an url
but he forgot to add a versioning system for this, so not only is it a massive security risk it's also pants on head retarded and requires you to clone the repo yourself and then point the compiler at the actual local location

>implement generic containers
but by relying excessively on type casting, because there is no generic type specification, you essentially just throw type safety out the window and end up with a system that's similar to early day Java where every collection passes type Object around and you cast here and there

>retain C style pointer/reference semantics
but throw pointer arithmetic out the window so now you're stuck with a broken system that forces you to explicitly handle references instead of the system just doing this for you as part of type inference

>throw exceptions out the window
but still recommend that you implement exceptions using Go semantics, because guess what, exceptions are a good thing after all

Go is the perfect example of why the so-called "UNIX philosophy" is outdated and should be considered fucking harmful.

>Plan 9
>brought good ideas
No, Plan 9 reiterated old ideas that should have died with the death of UNIX.

See Go is a terrible language, and there's a reason why people only implement """microservices""" in it and abandon it for larger projects.

>According to several sources Go was designed by Robert Griesmer, Rob Pike and Ken Thompson equally, i.e. all of them came up with ideas and would only implement them once all of them agreed on them.

It shows since these old fugs would rather ignore decades of PL research.

Yes, go get was a bad idea.
Yes, lack of generics is annoying for most areas that Go is useful in, although they'd slow down compilation by a bunch.
Having references isn't such a bad thing performance wise (considering Go is designed to be a low level backend web language), because gc can allocate a lot more things on the stack (gc also has escape analysis, so *a lot* more is being allocated on the stack than in other languages that do not have explicit references).
In general, this boosts cache coherency quite a bunch.
I don't understand you argument about exceptions. Are you talking about error values being passed up the stack or panic?

I know that this argument is pretty popular, but the last few decades of PL research mostly focus on two implications:
Less state => better code
More abstraction capabilities and expressiveness => better code
I am not so sure about these two implications (and I know the Go devs aren't either), and I think it's weird that these two implications being true is taken for granted in PL research.
I've encountered problems where duplicating a bit of code or using a bit of state resulted in more understandable code, and I'm sure you have as well.
Imo, abstracting solely for the purpose of reducing syntax duplication is often a bad idea, while abstracting for the purpose of reducing the duplication of some intuitive concept is often a good idea.

>I don't understand you argument about exceptions. Are you talking about error values being passed up the stack or panic?
The defer, panic and recover semantics, which can be used to implement exceptions. I misspoke, however, because I was under the impression that the best practice is to implement an exception-like control, but it seems that it is actually the contrary.

>[UnPaid]
>looking a programmer who loves marching cubes/dual contouring,voxels,minecraft,Empyrion,7 days to die,autocraft,gearblocks etc.
>required to collaborate with me in building voxel planets inside Unity

Sure thing, buddy.

Yeah, error values are best practice and panics are rarely used.
You normally use error values for user errors or errors that cannot yet be identified as user errors and would be expensive to double-check in the caller.
You use panics for errors that have been identified as programming errors and errors that haven't been identified yet while being easy to double-check in the caller.
The idea is that exception semantics and monadic control flow are very useful when an error should bubble up a bunch of stack frames and crash the program unless otherwise caught. This is true for programming errors, but not for user errors.
For user errors or still unidentified errors the default behavior shouldn't be to crash the program.
Also, unless your language is dynamically typed and completly follows the error handling philosophy of Erlang (this especially means having supervisors) then panics/exceptions will be difficult to use in a concurrent environment, which is what most Go programs are about.

Okay, I'll retract my last complaint. My issue with lack of generics is my most vocal though. I cannot believe that anyone in modern times would design a new language from scratch and not implement some sort of generic programming.

Tensorflow

How do you come up with project ideas?

The Go's way of solving this results in "if err!=nil" in every other line while still allowing you to just ignore the error and proceed to use the value. It's like the old C way, only errno is now integrated with function call.

The proper way to handle errors without exceptions is to use Sum Types (aka ADT): you use type system to force a programmer to check for an error before he can use the value. But, again, Go's type system isn't expressive enough to allow this.

Having a job helps.

When you're playing with live, living data with a purpose, it really helps you get more ideas for personal projects that are tangentially related.

This. When the job you're at actually lets you play around with making their data do something, you start getting ideas. Just don't let non-technical superiors come up with ideas. Ever. Ever ever.

Using sum types for errors isn't too different from error values, they're merely more type safe.
You can *always* ignore the error, even with sum types, as long as you've got no totality.
Ignoring errors in Go with functions that return multiple values is explicit, not implicit, just like it'd be with sum types.
Only disadvantage here is that errors of functions which only have an error as return value can be implicitly ignored, but that's relatively rare (most prevalent case being resource closing).

>i-it doesn't count

>no generic programming
You're damned right it doesn't count.

this thread has too few anime girls to be considered a true /dpt/

pls fix

...

>complaining about the lack of generics in a language with dynamic typing
Sup Forums in a nutshell

...

>generic programming = generics
>not even knowing what metaprogramming is

I'd say your post is Sup Forums in a nutshell.

Kek

>Using sum types for errors isn't too different from error values, they're merely more type safe
No?
>You can *always* ignore the error, even with sum types, as long as you've got no totality.
You can try to "ignore" an error in Rust, by using .unwrap() on Result, but it will panic if the result is an error at the runtime, so it's actually not ignoring at all. In other words, there is no way to write something like this in safe Rust:
value, _ := maybe_error(); //ignore error but use the value
lets_use(value);

or
value, err := maybe_error();
another_value, err = maybe_error(); //overwrite the previous error without checking it

>Ignoring errors in Go with functions that return multiple values is explicit, not implicit, just like it'd be with sum types.
I don't think "value, _ := func()" is "explicit" about anything.
>Only disadvantage here is that errors of functions which only have an error as return value can be implicitly ignored, but that's relatively rare (most prevalent case being resource closing).
Don't forget about uncomposability of Go's approach. When using exceptions you can just write your code in sequential manner, having all your error-processing code in one place. With ADT you can compose error-producing code with monads in Haskell or try! macro/? operator in Rust. In Go you have to explicitly check the error every time there is a possibility for one with "if err!=nil", repeating the same error handling code, and this makes the code unnecessary verbose and hard to read.

Text editor poll continues
strawpoll.me/12023125

>Fortran
>APL
>Lisp

Sup Forumsneric

Why would you need generic programming facilities if you have a dynamic typing system ?
Btw, Racket and Clojure have optional static type systems which I'm pretty sure allow generic programming.
I don't know much shit about Lisp, but it's famous for its macros allowing metaprogramming, so I don't understand what bother you about it.

Where can I learn how to write makefiles?

Racket/Scheme and Clojure are not pure Lisps, they add additional functionality. These are decent languages, but optional statically strong typing should be mandatory static strong typing with type inference IMO.

You're right in that generic programming doesn't make a lot of sense without static typing, but it should go without saying that dynamic typing is the source of all evil in this world, even Hitler.

>Where can I learn how to write makefiles?

wiki.osdev.org/Makefile

gnu.org/software/make/manual/make.html

I don't have a job, but I want to improve and have things to show. I really don't make anything right now because I can't think of anything to do

lads I had 19,7 in 20 in the test, I'm almost there.

I did beat the cute girl, she was at 19,5.

#pwned

you should do some lifting

get outta here pajeet

What do you consider a pure Lisp ?

Of course you can. Just match and leave the case for the error empty. Yes, this isn't idiomatic, but ignoring errors in Go isn't idiomatic either.
I consider anything explicit that requires to to do *anything* to say "I am not using this error". Whether you do that via having an empty match case or via _ doesn't matter much. The important thing is that you need to explicitly write anything to ignore the error. The issue with implicitly ignoring an error is that you might forget handling the error, but as long as anything requires you to explicitly handling it, the risk of forgetting to handle the error is greatly reduced.
Yes, this is still an issue with single return value functions in Go.

Guile

Javascript.

>Java

Convenient proxy, not so convenient name.