/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Old thread:

Attached: 1565621488919.gif (244x248, 184K)

Other urls found in this thread:

github.com/well-typed/optics
github.com/Infinisil/all-hies
github.com/infinisil/all-hies/tarball/master
godbolt.org/z/tpCH3A
godbolt.org/z/uhsZsI
godbolt.org/z/UMmnFG
ieeexplore.ieee.org/document/614776
pastebin.com/xgqbZT53
twitter.com/NSFWRedditImage

>anime
wrong subreddit, retard

Ruby?

Jesus christ get some new material zoomer

Attached: 1564297929497.jpg (1152x2048, 292K)

I like C!

$ bc
2^8^8

^C
^C^C^C^C^C^C
help

Attached: no.jpg (665x574, 25K)

I'm really enjoying Ada except for cross compiling.

Reading Java Concurrency in Practice

this abomination
:- module stack.
:- interface.

:- type stack(T).
:- type stack_overflow.
:- type stack_underflow.

% init(Size, Stack)
%
% Yield a LIFO stack with a fixed upper bound length.
:- pred init(int::in, stack(T)::out) is det.

% stack(X, !Stack)
%
% Push X onto stack or pop X from the stack, depending on X.
% Throws exception on underflow or overflow.
:- pred stack(T, stack(T), stack(T)).
:- mode stack(in, in, out) is det.
:- mode stack(out, in, out) is det.

:- implementation.
:- import_module list, int, exception.

:- type stack(T)
---> stack(
depth :: int,
maxdepth :: int,
data :: list(T)
).
:- type stack_underflow ---> stack_underflow.
:- type stack_overflow ---> stack_overflow.

init(N, stack(0, N, [])).

:- pragma promise_equivalent_clauses(stack/3).
stack(X::in, stack(D, M, L)::in, stack(D + 1, M, [X | L])::out) :-
( if D + 1 > M then
throw(stack_overflow)
else true ).

stack(_::out, stack(_, _, [])::in, _::out) :- throw(stack_underflow).
stack(X::out, stack(D, M, [X | L])::in, stack(D - 1, M, L)::out).

$ pkill bc

Arduino project that detects niggers.

Attached: little tom.jpg (267x242, 25K)

Are hash tables overrated?

Only basic data structure that has a O(1) lookup routine, so it has its uses.

no, they're almost incredibly good.

started using Julia, what am I in for boys?

Pain, I suppose.

$ bc
2^8^8

^C
^C^C^C^C^C^C
^C^CTerminated
$ yes >> test.txt
thank you fren

Attached: me.jpg (410x482, 65K)

Well?

Attached: python-vs-haskell.png (2518x1024, 386K)

>yes >> test.txt
You better have ulimits user

Attached: Twisted Fucking Cycle Path.png (641x346, 399K)

>What are you working on, Jow Forums?
I'm trying to decide if I should hang it up after years, nay decades, of writing for systems with no OS and little RAM or dive back in to learning what the latest and greatest tech is for systems with few limitations.

So I'm trying to make a GUI from scratch and I'm trying to make all the widgets scale with window size. Problem is that when I draw the widgets that they need to know how big they should be which depends on a variable that changes every time the window size changes. I can't think of a reasonable way for every widget to know about this other than to just store it in every single widget and update its value from the top level container every time there's a resize.

Any thoughts? Is this a good way to do it or not?

just because haskell is better than python doesn't mean you can post this cringe

>haskell is better than python
ha

too verbose.
too wrong.
too random.

Electron is the most powerful user interface.

It amuses me at what languages programmers like. You would think they all like automation and getting things done quick (ie: good IDE, good build tools, etc) but instead people go for verbose languages like C and they use basic editors that offer no automation out of the box. Quite surprising.

there are many factors that matter, not a few.
if a good dev environment is all that mattered Smalltalk would rule the world.

Thats just the autistic fizzbuzzers here, good programmers are lazy and practical

>You better have ulimits user
ulimit? It's fine this is a WD 4TB Green.

>rust is anti-freedom!
You can still get benefits from Rust, and do whatever you want in unsafe { } blocks. This is still better than allowing all the code to have unsafe semantics like in sepples.

but does rust have 'friend constexpr's?

Rust has syntax that is worse than SEPPLES and that says a lot.

based

It's honestly a pretty nice language that would have aged a lot better than C/C++ given the same development that C++ is getting. I use VHDL (Ada for firmware) daily.

>not afraid to introduce big breaking changes
>still no extensible records because muh backwards compatibility
>prelude is a complete mess
maybe 15 years ago, it's too large now with actual industry buy in.
A lot of the other stuff is also pretty borderline. Like, it's definitely not on par with C speedwise. It's not bad, but more on the level of golang or common lisp.

>extensible records
use lenses
>extensible variants
use prisms

Could you elaborate a bit more? I'm not a lens wizard, but I haven't seen anything that could give you the same functionality. makeFields is pretty nifty and I use it a lot, but you can't (as far as I know?) just modify the record structure by e.g. adding a field.
I'd be fine with just a link to a writeup or something as I tried searching for both but couldn't find anything.

Why does FANG use Java so much?

Easy to use
Easy to train
Lots of vendor software
Easy to hook into everything
tons of IDE/build/automation tools
tons of community libraries
huge std library

-- Fields you want to use
class HasX s a | s -> a where
x :: Lens' s a

class HasY s a | s -> a where
y :: Lens' s a

-- examples operating on something with an X and Y field
mag :: (HasX p a, HasY p a, Floating a) => p -> a
mag p = sqrt (px*px + py*py)
where
px = p^.x
py = p^.y

zeroX :: (HasX p a, Num a) => p -> p
zeroX = x .~ 0

-- Concrete implementation
data MyRecord = MyRecord Double Double Bool
instance HasX MyRecord Double where
x f (MyRecord a b c) = (\a' -> MyRecord a' b c) f a
instance HasY MyRecord Double where
y f (MyRecord a b c) = (\b' -> MyRecord a b' c) f b

-- mag (MyRecord 3 4 False) -> 5.0
-- zeroX (MyRecord 8 9 True) -> MyRecord 0 9 True

Some of this can be automated, e.g. using generic lens or TH macros. Arguably for mag I should be using getters rather than lenses but you might get an ugly hierarchy. This doesn't work for polymorphic fields though. For extensible variants, e.g. exceptions, use Prisms.

It's like COBOL but not as bad

I'm porting an old eroge engine to ps vita. Currently working on a SDL-based menu to replace the GTK one.

Attached: 2019-08-18-171343.jpg (960x544, 224K)

>haskell is better than python
>hasklels actually believe this

Most programmers do not like C unless the alternative is Assembly. Like user said, it's mostly just the autistic fizzbuzzers shilling it.

Another alternative to an OOP ish out of hand hierarchy is something like well typed's optics library
github.com/well-typed/optics
Rather than Lens, Prism, etc, you have a type parameter for the things you need (e.g. getting, setting, traversing) and type families to turn those into the type of an optic. You also get type families that let you combine them, e.g. say I want both, or the type of composition. This way you can do
class HasX s a | s -> a where
type family Access s
x :: Optic' (Access s) NoIx s a

instance HasX Eg1 Ty1 where
type Access Eg1 = A_Lens

instance HasX Eg2 Ty2 where
type Access Eg2 = A_Getter

zeroX :: (HasX s a, Num a, Access s `Is` A_Setter) => s -> s

I think, at least.

It depends what you are going for. When it's your own toy project there's something special to making everything from the bottom up in C and knowing everything inside out. In practice you'd prefer some super high level language like Python that gets the shit down quickly that you don't care about.

I would like to learn haskell,but it's a nightmare to use any haskell plugin in vscode with the latest version of the language
I really wanted to learn it,but I've spent much more time recompiling it than writing
It's a shame because that elephant book is really good

use vscode-ghc-simple
it has a bug with cabal-new projects on windows, otherwise it works great out of the box and doesn't need set up

Nice user.

I'll try tomorrow or when I have time,thanks.
I really wanted to use "Haskell language server " but again, it's a fucking nightmare,do you have any suggestions with that ?

it's a pain to set up and it takes a while
if you do try to use that, make sure you have the latest stack, pull the git recursively and run the stack ./install.hs thing with whatever it is (i think it's stack-hie-8.6.5 now?)

>What are you working on, Jow Forums?
nothing because I don't actually know programming

but honestly just vscode-ghc-simple is really good considering how lightweight it is. otherwise there's ghcid (requires an exe) which just runs a REPL every time you save a file, reporting errors, and hlint (exe likewise) which can give you suggestions to improve code

What is it?

Hm, that gives you Elm like 'extensible records', but you can't actually extend them by adding fields at runtime because you'd need something like anonymous records, right? For me personally that approach suffices, but I think there are some applications where you may want that functionality. I guess you could aways have some monolithic type that essentially has a Maybe of all possible fields, but that seems like a rather ugly approach.
In the beginning you definitely spend a lot of time just staring at error messages in the console, but it gets better pretty quickly in my experience.
Are you on Linux? Use Nix with
github.com/Infinisil/all-hies
(look under cached builds for how to install Nix and Cachix)
and then just paste
nix-env -iA selection --arg selector 'p: { inherit (p) ghc865; }' -f github.com/infinisil/all-hies/tarball/master
into your terminal.
replace gh865 if you use some other ghc version than 8.6.5.
It only works with stack projects though for whatever reason.
And that's the only reliable way I've found to get it working. Everything else is just a complete crapshoot.

>>Are you on Linux ?

Yes,I am and thanks for this
I was actually searching for something like this for a while now

So I'm trying to make a thing shoot between my current object's position and the mouse click position with an upper bound on the distance it can travel.

Right now I calculate the delta by substracting the current position from the target position, and divide it by the distance, and then in the update method I'm checking it the distance between the starting position and the current position to see if it should be removed after it travelled the distance. The thing is that since I'm dividing the difference by the range, it directly affects the direction vector making things faster the smaller the distance, what am I looking for to properly normalize this shit?

Is O(n) better than O(nlogn) or is O(nlogn) better than O(n) ?

O(n) is better.

O(n) is less than O(nlogn)
"Better" depends on the context of the data.

I don't think there is any CS example where smaller isn't better.

useful output produced where n is the size of the input

I just want to make sure but this right here works because of autocasting right? Or am I unaware of some hidden properties of enums?
Also I just did that on top of my head but is there a better way to deal with directions and rotations on demand?
enum ID { North, NE, E, SE, S, SW, W, NW }
//blabla C# function
direction += clock ? 1 : -1;
if (direction == ID.North - 1) return ID.NW;
if (direction == ID.NW + 1) return ID.North;
return direction;

depends which one is more cache friendly.

Attached: dxl2ui5v2r611.jpg (900x900, 83K)

Nevermind, apparently I just had to calculate the angle in radians then assign the cosine of the radians to the x vector prop and the sine to the y vector prop.

Enums are just integers wrapped up so they're typesafe.
I think you should be able to just use modulo for the rotation, but I'm not sure how C# handles it exactly.

>thinks cache performance has no affect on computers anymore
retard alert

>nobody has ever heard of the cahce... it is my duty as one who has studied the code since a child to bestow upon anons this mighty and powerful gift... use it carefully........

How can I make a thread B stop as soon as thread A stops? thread A runs on a while loop

What language rasheen?

java bill

There's no way to do that safely. All you can do is interrupt Thread B and hope it hits something that checked for interrupted. Have a good day sirs.

godbolt.org/z/tpCH3A
I really have no idea what I was expecting

what are we supposed to be expecting

Not sure. Just wanted to compare how C and C++ handles vectors, I suppose.
Also found it mildly amusing that the assembler output on the C++ side made mention of 'void *'.

Seems like expected behavior to me. The std::vector destructor calls delete on the FILE* elements (the void* you see). The reallocator does bounds and allocation checking, which yours doesn't.

>the compiler always produces the best Assem-
godbolt.org/z/uhsZsI

-bly
godbolt.org/z/UMmnFG

That's still not optimal, stupid.

Every day I find more and more reason to start using rust but my god the language is anything but productive. If you are not following the rust way the BC will punish you harshly

Just throw random copies everywhere until the code compiles lmao

char f()
{
return true;
}

int main()
{
bool k = f();
}


Why does this C++ compile?

What's it like having 27k on Stackoverflow?

Attached: wk4vaz25msg31.jpg (676x1677, 157K)

c++ IS WEAKLY TYPED

>Every day I find more and more reason to start putting dicks up my ass

Thanks m8

A little less "what am I working on" and more, I would like to start working on. I've got some source code to a vidya, but it's written in small.

Does anyone have any knowledge on documentation or books, other than this?
ieeexplore.ieee.org/document/614776

is this supposed to be an argument

working on a tool to create normal maps for 2D art. now I need to make a GUI. is Qt worth using? am on windows here

Attached: showcase.png (480x360, 5K)

A backup with SSH and encrypt with GPG script: pastebin.com/xgqbZT53

It's fairly specific to my own needs, but it wouldn't take much to tweak to match your own. I'm not sure what else to add to it, any ideas?

Yes
How are you finding "reasons to use it" if it's a piece of shit that gets in the way with its stupid borrow checker

are you supposed to draw 4 heightmaps to generate a normal map? That seems like a pain in the ass

>is Qt worth using? am on windows here
Qt is absolutely fantastic if you're a C++ guy... even though it has some really weird C++ shit due to legacy reasons. The new Qt stuff for modern UIs (QML) is very easy to learn and use and very powerful. On the whole, Qt is the best GUI toolkit I have used amongst Android and iOS.

Only thing you need to watch out for is that the Qt license is LGPLv3, and this will fuck you over distributing on certain platforms and stuff. If you are just using it to make a sprite editor that you don't care to distribute (or you are okay being tainted by the LGPL) then go for it. Qt is really high quality robust software, has excellent documentation, and there's a great deal of people who use it (go to #qt on freenode for support)

Doesn't the LGPL simply imply that he has to distribute his binaries *dynamically* linked against Qt and there's no other restraints if he doesn't make his own modifications to the Qt codebase?

they aren't height maps, more like shading the sprite 4 different ways. the tool is for artists who definitely can't just draw a normal map
sweet, thanks for the testimonial. and this is in C++ so I think I'll use it, as it's an internal project that won't be distributed

an artist doesnt want to draw 4 different images to combine into one, you should find a way to merge them together

well, it's trivial to turn a height map into a normal map, but it's also pretty hard to draw a height map.
the shaded images can be really rough and still turn out a good result which is why I was going for it. you have a different idea?

I used to draw heightmaps to generate a normal map, but as you said it's hard to predict the results, but drawing 4 images isn't a good solution, although I can't think of a better one, 4x the workload for animating a sprite is not fun

Hey Folks, I'm wondering what kind of technique or data structure I might need to write a function that takes many types of inputs and returns many unique corresponding outputs. What I'm specifically doing is trying to use C++ to convert char data to petscii codes (Not ascii), as well as write an assembler for 6510 processors