/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

play.rust-lang.org/?gist=87182a369df135091b3fb4253e458627&version=stable&backtrace=0
iolanguage.org
gist.github.com/anonymous/2d779bef18ead25e924ceaddf1747b14
strawpoll.me/13148484
jetbrains.com/idea/
github.com/mpark/patterns
twitter.com/AnonBabble

nth for the power of .chars().next().unwrap();

>nth
How ironic, you can actually do
let c = s.chars().nth(0).unwrap();
as well, still need the iterator though.

what are some good sources to learn functional programming?

i'm a backend webdev and i need to step my game up

i'll shit on webdev any day but functional programming would honestly be a step down from backend webdev

2.0 better get a syntax overhaul.

what do you mean by this?

...

>Rust is functional programming

try ""[1] or ""[2] in your favorite shitlang and tell us what happens. For some, exceptions are an acceptable tradeoff, for arustyian herrenrasse members, not.

appending an empty char?

>webdev
>functional programming
cum on step it up

that's where the autistic let, iterator and unwrap crap comes from. pure fp languages are even worse

firstTruthy :: Monad m => (a -> Bool) -> [m a] -> m (Maybe a)
firstTruthy f = foldr
(\x r -> x >>= uncurry (bool r) . (return . Just &&& f))
(return Nothing)

i dont know what either of you are talking about and neither one of you answered my question.

just look at that shit

Indexing strings in rust
play.rust-lang.org/?gist=87182a369df135091b3fb4253e458627&version=stable&backtrace=0

its very general and useful, yes
same program would take many lines in java

What is that even doing, i can barely read simple haskell code.

i didnt say i want to learn a language that strictly follows the functional paradigm. i just want a source so i can improve at writing functions with general languages

functional programming =/= programming with functions

its not simple its very compacted and dense. i agree that its hard to read but it could be stretched out to be more explicit.
it takes a list of monadic actions and a function to accept or reject the result of those actions. it returns the first result that meets the condition supplied and stops executing the actions there. if no actions match, it returns Nothing, or null.

in pseduocode, though a little less general:
a = doFirst()
if (valid(a))
return a
b = doSecond()
if (valid(b))
return b
...
return null

>i just want a source so i can improve at writing functions with general languages
If you want to learn the functional way, limit the use of mutability, and write as many of your functions as pure, I.E. no side-effects.

so how do i actually improve at solving programming challenges?

>inb4 just do them
on codewars i cant do past a certain level of questions no matter how long i sit and sweat

ah, that helps, thanks lad.

then you ask for help with the bits you don't get until you understand

That's a good rule of thumb even if you're not writing a pure functional language.

Found my new memelang /dpt/. So abstract I cant relate any pic. So far-fetched you cant joke about it.

iolanguage.org

>codewars
oh wow, never heard of this before. cool.

whats your point here?

Yeah, also severely limiting the use of POO exceptions ani try-catch as well.

> a language that puts irrational minimalism over functionality
my heart, too bad mines still gonna be better

exceptions are fine if they actually represent exceptional conditions.
they have a place, and that place is not general purpose error handling

BOYS WE DID IT. NOW JUST TWO MORE NUMBERS.

Steps afterwards:
designing pcb
programming a countdown controlled via local webserver

Is its name going to be an obscure pun in italian tho? If not kys

looks like shit

>Woplangs
Absolutely not.

this

va fanculo

ravio.li

nice pasta

>everything is an object
>everyrhing is a message
W E W
L
A
D

I need to make a Counting Bloom Filter in C and i dont know where to start.

In a nutshell, a function needs to read a file with "tweets" in the format "user,tag1,tag2,..." and print the users in order of amount of tags used.

So far I made a split function to work with the tags but I cannot get the rest

how do i turn a lamp on with my phone? i'll need a special type of lamp right?

gist.github.com/anonymous/2d779bef18ead25e924ceaddf1747b14

>working with strings in C
why would you do this?

>So far I made a split function to work with the tags
strtok

>print the users in order of amount of tags used
Store the users in an array and either sort it as you parse the tags or qsort the array after all users are parsed. Then iterate over the list and print.

OMG I just jizzed my pants

1. special lamp: they sell lightbulbs with IoT crap integrated. They connect to wifi and you can control them using (((apps)))
2. special device: replace your switch with a relay, connect that to a mini-pc board (arudino, raspi, cubieboard etc) and you can control those over network.

is that subtle form of bullying

Kek

>150 lines of code
>already had to use 6 globals
>just realized I will have to add one more
FUCKING INTERRUPTS REEEEE

>What are you working on, Sup Forums?

Homework :(

Is there anyway for getting a C++ iterator to stop and end at arbitrary points in a list?

use break; to terminate a loop early

Don't misuse "REEEEE" for general anger, use it against normalfags.

>Chad programms compilers in his free time while you have trouble with the interrupt homework

>Just had to add another global

>allowing globals to infect your program state
you never "have" to add a global, user

>Interrupt routine is always called without any parameters
>Only way it can get access to program state is with globals
How else would I change my programs state

Globals are haram.

ASM? What kind of interrupts?

>he still has to worry about global scope

Timer and Button interrupts
Language is C, Chip is from atmel

>inb4 oop a shit
strawpoll.me/13148484

the anti-globals meme is just something that is taught as an almost absolute to beginners to force them to learn how to properly maintain state and pass it between functions

if you think globals are haram still you need to throw off your training wheels kiddo

You could try using an array, struct or bitfield to organize your global flag variables.

in that case you're fucked

Have fun making a global state riddled program concurrent.

>what is a semaphore

clearly something you never need because global state is verboten!

everything that is evil has a use case, and should be used when it is the least evil of the options

globals are evil does not imply never use globals

Stop using so many abstractions
Stick to the basics
Learn how TTL/CMOS works
guise

If you're worried about that, you aren't Enterprise Software-ing hard enough

Z E R O C O S T
E
R
O
C
O
S
T

Where should I focus learning?

Android, iPhone, web, or games development?

Esoteric Fizz Buzz

>global state is verboten
Most use cases don't require the use of global state. You should only use it when you absolutely have to. Lisps have a good balance between state and stateless code.
>semaphores
They destroy performance.

Start by learning how to learn

Learn to weld.

your choice
this though

Is Netbeans shit? I'm learning Java (school requirement) on Mac and I'm running into a lot of buggy menus and compiler errors. Whats a good compiler for Mac?

Netbrains isnt a compiler user.
Edit your files with vi and compile with javac

I use Netbeans for Java and C but I'm also a pseudo Pajeet so take that as you wish

It's shit

jetbrains.com/idea/

also, not a compiler

Is Rust without the borrow checker the perfect language?

isn't the borrow checker the whole point?

see also, the syntax is shit

Rust without the borrow checker would be C++ with worse syntax

Originally, but Rust has tons of good features that stand out on their own, but the borrow checker really gets in the way of good design sometimes.

For example?

al-Qurʾān, brother

I can't segfault anymore :(

Wait, so C++ has tagged unions, pattern matching, traits, modules, a good build system, and a good standard library?
Well shit, C++ must have really changed since the last time I used C++14 half a year ago.

> tagged unions
I'm pretty sure this is in C++17 as std::variant.

>pattern matching
Can be implemented
github.com/mpark/patterns

Try calling a method that takes a &mut self and returns a &mut T within a method that takes mut self while self is immutably/mutably borrowed.
You'll get the borrow checker screeching at you for perfectly fine code.
It's unnecessary, and only stops retard programmers.

Sorry, I'll also add with half-assed FP

Get/index the first character of a rust string.

And they're trash.
Can't even pattern match against them.

I'd rather have native UTF-8 encoded strings.

"niggers".as_bytes()[0];

It even explicitly states that you're assuming the string to be an ASCII string.

>O(n)
this should be an O(1) operation user