/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

en.wikipedia.org/wiki/Fast_inverse_square_root
kianryan.co.uk/wp-content/uploads/2012/09/Screenshot-from-2012-09-02-163736.png
twitter.com/SFWRedditGifs

fuck opengl

CONVERT TO THE ONE TRUE PARADIGM

PURE STRONGLY TYPED FP

hasklet is shit

All paradigms have their appropriate uses

>It's really easy to reason about
that's another buzzshit I don't get, literally in every hn post someone talks about "reasonin about something"

what does "reason about" even mean

Didn't he say Haskell is useless, though?

>all computations are mutable

I made my first pull request to an open source Github project!

Functional programs are easier to read once you get used to it.

Compared to other programming languages, is Rust really that shit?

nice work my man, what lang?

>spend 2 months trying to fix an issue to get dat sweet pr
>some smartass faggy teenager solves it and bunch of others in a day
fuck

What is this project?

ONE GIGABYTE PER SECOND GARBAGE

s/shit/bad

no
but I like D and Go more
maybe because I am a brainlet and Rust syntax makes my head hurt

>Just
>Nothing

Evaluate these two by hand. As in with paper.

(define (fact n) (if (= n 0) 1 (* n (fact (- n 1)))))
(fact 4)


(define (fact n) (define result 1) (call/cc (lambda (rtn) (let loop () (if (= n 0) (rtn result)) (set! result (* result n)) (set! n (- n 1)) (loop)))))
(fact 4)

torque = 10 N * 5 m
energy = 5 N * 10 m
bullshit = torque + energy


Where's your typing god now?

if N :: T, m :: T, Num (T -> B) and Num B then this is well typed

Yeah, that's the problem. It shouldn't be well typed because adding torque to energy makes no fucking sense in the real world.

or m :: S and Num (S -> B)

or non-prelude * and fromInteger (rebindablesyntax/noimplicitprelude)

Then make better use of types?
There are plenty of ways to do measurement types in Haskell

dumb haskell apologist poster

New neogaf mods, remove some sexbot thread and was decent OP questions.

>Yeah, that's the problem. It shouldn't be well typed because adding torque to energy makes no fucking sense in the real world.
int number_of_times_i_fucked_your_sister = 949145858525;
int number_of_sensible_posts_by_you = 0;
int bullshit = number_of_times_i_fucked_your_sister + number_of_sensible_posts_by_you;

That makes no sense and yet I can add the two. Type systems BTFO.

a forum system

...

struct Torque { int data; };
struct Energy { int data };

In Julia. I contributed a single function to reactive.jl , which is a dependency for what is currently the most convenient GUI library.

int bullshit = torque.data + energy.data;

Static typelets B T F O.

it would be nice if C had some sort of module system so you could control exports

>doubles are a subset of integers
the state of Sup Forums

I-i-i'll just make them o-opaque. N-n-nobody will figure out a way to convert torque to energy with a tostring method or something.

en.wikipedia.org/wiki/Fast_inverse_square_root

I saw this post way too late. You should ignore all the idiots telling you to decay the array into pointers - that's how you might do it in C, but C++ has better ways. If you know the size of the array and want to keep it that way, what you want to do is pass the array by reference:
int (&a)[N]
N has to be a compile-time constant and can be a template parameter if want to be able to pass in any static array and still know its length.

P.S. You can pass pointers to arrays in C as well if you want to but the syntax for accessing those is clunkier.

It does have. They're called files.

header.h
struct Torque;
struct Energy;


code.c
struct Torque { int data; };
struct Energy { int data };

>interfaces are abstract classes
>integers are doubles
>your continued existence
The absolute state of Sup Forums.

>You can pass pointers to arrays in C as well if you want to but the syntax for accessing those is clunkier.
int *arr is a lot simpler than int (&arr)[N] senpai

>stop raping me, I'm only mentally ill
every tiem! :^)

>unironically needing two files for one declaration
the absolute state of cniles.

I didn't realise you could define types in .c files

this. can I also define typedef-structs this way?

>claims that doubles are integers
>take screenshot
>deletes the post
>spends the next days sperging out about doubles being integers
>calls others mentally ill

You actually don't. It's just nicer.
Besides, you need at least two files in any OOP language as well. Interface + implementation.

you can't forward typedef though can you?

There exist OOP languages besides C++, user.

>pretending
bwahahahaha, my dick really hurt you that much?
buckle up, nancy, I ain't stopping now ;^)

>you need at least two files in any OOP language as well.
not one with modules

Take a moment to read your own posts, you absolute autist.

typedef struct Torque Torque; in header.

C++ isn't really OOP imo. I was talking about Erlang and the likes.

Yes, but while the former could be any length, the latter is fixed-length and its length can be deduced via templates. It really depends on your use case, kouhai.

I was hoping somebody here could help me design a program in a idiomatic functional style. I'm a sysadmin in a Windows-based environment and I use powershell for most of my day-to-day programming needs. I currently have a script running that does ticket triage based on simple rules, and I'd like to convert this to a service for various reasons. I'd like to use F# because I find it interesting and I have the freedom to do so.

The current script looks something like this pseudocode:

update-ticket { //blah }
get-unassignedtickets { //blahh }
$tickets = get-unassignedtickets

foreach ($ticket in $tickets) {
if (($ticket.subject -eq "foo") -or
($ticket.author -eq "bar")) {
update-ticket $ticket -assign_to pajeet
} else if (($ticket.subject -eq "foo") -or
($ticket.author -eq "bar")) {
update-ticket $ticket -assign_to ahmed
}


Except there are many, many if statements. Frankly it's awful, but I'm not a programmer so I don't know a better design pattern for this. Now, my manager has requested that when I convert this to a service, I put the rules in a separate configuration file so that they can be edited by non-technical people. I'm not sure what markup language to use, but here's an example of what I imagine this might look like in JSON:

{
filter: {
subject: "foo",
author: "bar"
},
action: {
assign_to: "rajesh"
}
}


There are more "filters" and "actions" than those three, but I think that illustrates the point nicely. Anyway, the real question here is: what is an elegant, functional way to perform actions on an object based on the values of that object's properties? And how can I describe that in a configuration file?

thanks /dpt/

using templates for arrays seems like a lot of unnecessary bloat
why C++ can't just have an array slice like Rust is beyond me

It takes like 5 minutes to write your own.

Look into the function "map" and pattern matching.

>stop triggering me!
how does it feel when I make you foam at the mouth with a simple reminder? do you curse the moment when you clicked post too soon? you dun goofed, fucboi!
you're my slave now: I just whistle and you come running like a bitch in heat! ;^)

It's only bloat if you pass in a thousand different array lengths.

Thanks user!

I know, but it's strange that the standard library is simultaneously so bloated and so lacking

Even if I give you the benefit of the doubt and assume you weren't the one who made that post in the first place, you still just look retarded.

This.

Three quarters of the sepples standard library is generic code which is hilariously unsafe when specialized to specific format and thus completely unusable for anything.

At the same time, it lacks basic comforts like a string split function. I shouldn't need to break my workflow by writing such common functions myself.

>pretending for more damage control
we all know by now tho ;^)

>interfaces are abstract classes

I'm so fucking confused. I'm struggling through the infamous assembly "bomb lab" and in phase 2 I came across the line (AT&T syntax, not Intel)

cmp %eax 0x4(%rbp)

What the actual fucking fuck is the reasoning behind this line of code? What's the point of comparing the return value to another value 4 bytes BELOW the current base pointer ? Doesn't that take you out of the current stack frame? Aren't you supposed to do something like

cmp %eax -0x4(%rbp)

so the value you're looking at is 4 bytes ABOVE the current base pointer with regards to the stack?

What's a good graphical text editor for ubuntu? Something like notepadqq, except with proper functioning themes.

Vim

Please don't bother answering with the typical vim, emacs, etc etc. I'm a simple man, I just want an editor that's nice to look at and does syntax highlighting.

emacs

Notepad++, Sublime, VS Code

I don't want bloat

Let me be more specific: I want something like notepad++ and I want it on Ubuntu. I don't want to run wine or to have to use notepadqq, which is shitty. I don't want anything resembling an IDE, a web browser, an email client or a teletype from 1980. I want a program that I click with my mouse and that has syntax highlighting for OCaml.

Does anyone know of anything like this?

Autism
Just run N++ thru wine

If you need wine, guess it isn't bloat then user.

Also you can click with your mouse with gvim.

You can completely forget about vim's goodness if you just go into insert mode, use the mouse, and never hit escape.

How is it autism? I just want something simple. Something like this has to exist, I just don't know how to find it.

I'm not running a whole compatibility layer just to run my text editor.

except for OOP

waht is a good fp language for a brainlet?

can anyone explain this to me?
>download gimp
>open up image (2 bytes in size)
>color quantize and dither it
>save as jpeg
>18 bytes in size

wtf happened? how did it end up bigger?

kianryan.co.uk/wp-content/uploads/2012/09/Screenshot-from-2012-09-02-163736.png

This is gvim, according to google. It has an useless left panel to display part of the file system. I can already do that with nautilus or the command line. I don't want BLOAT. I want a fucking TEXT EDITOR WITH SYNTAX HIGHLIGHTING FOR OCAML.

CAN ANYONE PLEASE HELP ME. NO BLOAT. NO USELESS COMMANDS. NO CRUFT. JUST CLICK, TYPE TYPE TYPE, COLOURS POP UP. NICE TO LOOK AT, DOESN'T HURT MY EYES. ANYONE?

works for GUI programming I guess

gimp is not savin file as src? maybe

>maybe he'll go away and let my ass heal
lad...

>for a brainlet
lisp

Fukin i dont know if yall can help but this line:
smaller[where->first] = m[where->first];
is giving me an compile error that i cant interpret. smaller and m are both map and where->first is a vector

How useful/used is recursion?
Is there a benefit to using it over loops??

JPEG works by splitting the image into small parts and transforming them into frequency space to encode the image in terms of 2D detail density. It then drops layers of detail depending on the quality setting, favoring lower frequencies to preserve the overall appearance of the image.

The dithering you did just increased the detail density significantly, preventing it from truncating the quantized blocks the way it usually does.

>interfaces are abstract classes
>integers are doubles
How's that asshurt of yours going, kid?

>How useful/used is recursion?
makes a lot of problems a lot simpler
>Is there a benefit to using it over loops??
see above

>a lot
some*

>I'm bleeding
don't worry, when your ass is done I'll rape your mouth too ;^)

If the problem seems simpler to do with a loop, is it just worth using that and leaving it?
Got an exercise where I need to loop through or use recursion to go through a Lisp List (in Java) and return another LL which has the index of the number given.

i.e. list = [1, 3, 3, 4]
num = 3
new list = [1, 2]

Not allowed to add another parameter (i.e. counter) and doing it with a loop took less than a minute.
Not sure if it'd even be worth the effort to do it with recursion.

with TCO: it's a lot simpler than loops but a lot harder to debug because of no proper stack trace
without TCO: it's a bit more complex than recursion

Some people also say shit like loops are antipattern but those people just talk outta their asses, use whichever you see fit for the task at hand.

>integers are doubles
>interfaces are abstract classes
>bleeding profusely from your ravaged asshole all over the thread

What's your font of choice?

>If the problem seems simpler to do with a loop, is it just worth using that and leaving it?
yes

not really

ok i lied i guess m is a const map. im assuming it has to do with that and that smaller is not const. is the problem iterator where? or the assignment statement?

That's the return address.

sounds like you're looking for gedit

eyy, why doesn't this program work?
#include
#include

template
class slice
{
public:
template
slice(std::array *src): _data(src->data()), _size(src->size()) { };

T& operator[](size_t n) { return _data[n]; };

T* data() { return data; };
operator T*() { return data; };

size_t size() { return _size; };
private:
T *_data;
size_t _size;
};

void acceptor(slice s) {};

int main()
{
std::array arr = {10, 30, 40, 15};
acceptor(&arr);
}

gedit is too bright and hard to look at, but it's more in the vein of what I want, yes