/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread

Other urls found in this thread:

humblebundle.com/books/functional-programming-books
en.wikipedia.org/wiki/Functional_programming
msdn.microsoft.com/en-us/library/windows/desktop/ms682411(v=vs.85).aspx
man7.org/linux/man-pages/man7/sem_overview.7.html
twitter.com/SFWRedditVideos

Threadly reminder to use #![feature(nll)].

humblebundle.com/books/functional-programming-books
>tier 15+
>Rust
Fucking Rust.
Rust is not a functional programming language.
Stop it you fucking marketeers. There's no excuse for this dishonesty.

What is a functional programming language?

A programming language that supports this programming paradigm
en.wikipedia.org/wiki/Functional_programming
Well.
More stringently it could exclusively support this paradigm. but I'll concede that.

>C++ is a functional programming language

>paradigm
Played it. Pretty cool game.

>C++ supports functional programming well
I disagree.

/dpt/-chan, daisuki~

a program that is build for and with functions (lambda calculus), not with procedures and statements (turing machine).

What makes C++ not a functional programming language?

>What makes C++ not a functional programming language?
You two can argue about labels all you want, but for a language to be a "functional programming language" in any meaningful sense, it needs to enable and encourage functional programming, which C++ does not.

Well, considering some people think Lisp is a functional PL, there's nothing wrong with C++ being a functional as well.

How come Clojure is "functional" but Rust isn't?

To the Haskell autists ITT (from a competition):

What is the shortest way (# of tokens) you can come up with to write a function that takes in 5 numbers and gives the sum of the min, max and median values among the arguments?

Best I could come up with was extracting the entries 0, 2, 4 from the sorted list of arguments and summing those.

Sepplesfags are all about const and they now have lambda. You are not even supposed to care about memory management anymore. Sepples is functional programming language.

>hurrrrr it has const and lambda so it's functional programming now
I literally just explained to you why this argument is shit. Making it possible to code in a functional style =/= making it convenient =/////////= encouraging it.

If you wrote three lines of code, A, B, and C:
A;
B;
C;

In most programming languages, A would execute first, then B, and then C.

In the ANI programming language, A, B, and C would all execute at the same time.

>(# of tokens)
Like, as in number of characters in your code?

>In most programming languages, A would execute first, then B, and then C.
Unless the optimizer reordered them.

Most programming languages have sequence points.
So they can only reorder if the steps have no dependency between each-other.

I don't know what ANI does.

No, it's alpha equivalent
aaaaaaaaaaaaaaaaaaaaaaaaa
a
same number of tokens

>extracting the entries 0, 2, 4 from the sorted list
Literally this, use sort from Data.List (it's only 5 elements)

How do you create inline objects in C++?
e.g.
aVector.push_back(new aClass(2));
This doesn't compile. Is it possible in C++? Or do you just need to create the object in a previous line, then push it?

remove the new

Won't that just create a local object on the stack? It'll just get popped when the function returns won't it?

Java is getting better and better. I can actually write good programs in Java 9, fuck off with your shitty Sup Forums memes.
Meanwhile C# is a vendor lock-in memelang that's going to die slowly.

it will move the object to memory allocated on the heap

Does Linux have an equivalent to Windows' global mutex?
msdn.microsoft.com/en-us/library/windows/desktop/ms682411(v=vs.85).aspx

No, vector will copy or move the object into its internal buffer.

Nevermind. Found it:
man7.org/linux/man-pages/man7/sem_overview.7.html

def countNeighboours(list, x, y):
neighbour_cells = [(x - 1, y - 1), (x - 1, y + 0), (x - 1, y + 1),
(x + 0, y - 1), (x + 0, y + 1),
(x + 1, y - 1), (x + 1, y + 0), (x + 1, y + 1)]
count = 0
for x, y in neighbour_cells:
if x >= 0 and y >= 0:
try:
count += list[x][y]
except:
pass
return count

#for cell in neighbour_cells:
#if XVALUE >= 0 and YVALUE >= 0


I want to rewrite the for loop with a for each. How do i get XVALUE and YVALUE of a cell in the array?

...

i'm serious

>Be me
>trying to learn Lua
>decided to practice a bit by making a simple pattern matching program

>twf found out Lua don't have switch
>tfw there is no alternative other than using tons of elseif
>tfw always having off by one error because of Lua's array start at 1

Why the fuck I decided to learn that language anyway?

what do you mean by replace the for with a foreach? the python for is a foreach

you can simulate a switch with a dict/list of functions.

Don't know if Lua supports this

Why at are some languages that support switches on strings

>comparing strings
don't do that.

How the fuck can Rust even compete?

Just use an enum. Or possibly a hash table.

i want to
i don't want to hack it

I want to ascend as a programmer.
What knowledge should I have? Discrete math, general math, theoric complexity or what?

>self.
>in 2018
board knowledge of different technologies

Literally the exact same except one has "Pythonic" syntax and no concept of "unsafe".

>I want to ascend as a programmer.
>What knowledge should I have?
Learn Rust. Everything else is irrelevant.

Is the U.S. government suppressing the development of formal methods for proving code correctness to protect their pipeline of zero-days?

Have you read your SICP?

Linear temporal logic is a type system for functional reactive programming. In other words, functional reactive programs are proofs of propositions in linear temporal logic.

>hack it
what's your requirement here, are you receiving the strings from outside, or are you defining the magic strings yourself?

If it's the latter: enums

I plan to, but I feel I need to read other things before that. Like discrete math, theory of computation and other mathematical things. What do you suggest?

k dork

>literally the exact same
>except one is literally 30% more code for the exact same steps
The absolute fucking state of Rust fanboys...

stop bloatshaming you shitlord

SICP is an introductory book, it doesn't really have any significant prerequisites.

>meme programs are meme propositions in a meme logic
Sounds about right.

Yes, that's the power of "Pythonic" syntax. Trading LoC for significant whitespace.

types
http
modular design pattern
git
memory management
CPU pipeline
CPU instructions
how caches work

>Trading LoC for significant whitespace.
This has little to do with whitespace. Look at the actual code, rustlet.

sounds interesting, write a typechecker

>theoric complexity
lol

It's virtually identical.

Doing some assembly stuff an am super lost

I have
hexval:
.dword 0x123456789ABCDEF,0x00000000FFFFFFFF

and am supposed to

put into X9: 0xFFFFFFFF0123456
put into X10: 0x0000FFFFFFFF0123
put into X14: 0x73692038766D5241

without using any literals. I have absolutely no idea what to do. Any shoves in the right direction?

No businesses are cutting corners to have an edge on the competition costwise. It's also not practical since usually the client isn't technical, and the developer doesn't have all the domain knowledge necessary to prove the solution works as intended. This is why users test

That's the goal.

Probably need to move hexval into a register and do some bitwise twiddling to get those values

Most higher-level languages do, ones like Python are an exception.

>30% more code
>i-i-it's identical
>i-it's just the curlies, man
(self.coord_idx * size_of::()) as GLsizeiptr
vs.
batch.coordIdx * sizeof(float32)

self.coord_data.as_ptr() as *const c_void
vs.
addr batch.coordData

ptr::null()
vs.
nil

use or, and, shift operators

the instruction you are looking for is called rotate

Note that it gets much worse for Rust where there is no 1-to-1 mapping.

emplace_back

Can C/C++ split strings or vectors yet?

nice b8 m8

>whitespace delimited
>compiles to JavaScript
>inferred typing

How the fuck can Nim even compete?

Those conversions could be inferred (as _) and std::ptr could be brought into scope. Otherwise, it seems like a classic situation of writing the program in language X and translating it 1:1 into language Y and then saying that X is better. This will almost always be the case.

Realistically, you'd use glium in Rust. Nim doesn't have anything of that caliber.

I'm not even a Rust "fanboy", I just don't like the wholly unfair treatment it gets from /dpt/.

So it's admitted that the Nim program came first and the Rust version is a 1:1 attempted translation. Pointless.

>>whitespace delimited
- Nim supports syntax skins, whitepace delimited is the default. You actually can use braced syntax if you just enable it
- It can compile to C/C++/LLVM/Obj-C too
- Good

RUST
U
S
T

>I just don't like the wholly unfair treatment it gets from /dpt/.
It's just a couple of autsts at most. /dpt/ is mostly indifferent.

How do I go about using this? Googling has really let me down on this. Can I manipulate the values like it's a string in python (eg to get the 0xFFFFFFFF0123456 copy parts of the two given dwords)?

Will look into these, thanks (although I'm not sure I'm allowed to use these operations yet)

lack of function

I want to write something that will swipe audio files from Quizlet to make memorization of vocabulary easier (they don't provide the files for download directly, but you can find them by inspecting a page).

What's the best way to interact with an "inspect source"? Can I find those things in the JSON or what?

(self.coord_idx * size_of::()) as GLsizeiptr

self.coord_data.as_ptr() as *const c_void
thanks to type inference, they could also be written as
(self.coord_idx * size_of::()) as _

self.coord_data.as_ptr() as _

put them in a qword and copy half into new registers after shifting

Is it just me, or does every general I frequent have this going on? You've got 2 or 3 major shitposters who just work off of each other non-stop and make it look like there's a large crowd doing it. Has this always been the norm and I'm just noticing it recently?

or rotating

>So it's admitted that the Nim program came first and the Rust version is a 1:1 attempted translation. Pointless.
The Nim program came second, actually. I just got so sick of the pile of trash that is Rust that I figured it would be less tedious to rewrite everything in Nim. I was right. Getting the same thing done in Nim took less than half the amount of code, but I just found it hilarious that even for a trivial function like this, Nim takes 30% less code, let alone all the code where all that lifetime annotation and layer upon layer of boxing (as per suggestions from Rust experts) simply disappeared.

Anyone here ever used ePrime for constraint satisfaction problems?

You just suck at Rust, then. Why weren't you using glium, for example? Or gfx-rs?

Haskoll vs Exlixir

>You just suck at Rust, then.
I guess the Rust community sucks are Rust, then, because most of that garbage came from their idioms, best practices and recommendations. Anyway, I'm long past arguing with Rust fans. Anyone with eyes can examine Rust code for themselves.

Yes user, keep blaming the tool and its community for your own failures.

Why is Rust able to achieve much better type inference than C++?

I don't know, user. Maybe there is some magical way to avoid lifetime annotations and pointless boxing, but evidently, Rust experts simply don't know of it. Keep shilling all you want. Anyone with eyes can look at Rust code for themselves.

Less computation in the type system.

That makes sense, but I'd like to hear about specific C++ features that make things like this impossible.
let foo: SomeType = some_fn();
let foo: SomeType = some_fn();

I think Rust has a Hindley-Milner type system or some variation thereof. C++ doesn't

1. Sit up straight with your shoulders back
2. Treat somebody's code like you have responsible for it
3. Befriend the sysadmin
4. Compare your current code to what you wrote in the past, not the unmaintainable piece of shit you wrote today.
5. Do not let the junior dev do anything that could get him fired
6. Set your project's buglist in order before you criticize other projects.
7. Pursue long-term stable code, not this week's hype
8. Admit you don't know how to design a program/system/database. Or at least don't pretend you do.
9. Assume the PM or the client know something you don't already know.
10. Be direct when writing documentation or comments.
11. Do not bother seniors while they are debugging.
12. Wear thigh high socks when you work from home.

some_fn where SomeDerrivedType can be a SomeType could also work, so it doesnt know what you mean.

I guess which is an example of implicit conversion, but the other main culprit is template specialization.

>Rust has a Hindley-Milner type system or some variation thereof.
Found the ignorant Rustlet... Do you even know what an HM type system is?