/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

evan-tech.livejournal.com/220036.html
cs61b.ug/sp16/materials/proj/proj2/proj2.html
cs61b.ug/sp16/materials/proj/proj3/proj3.html
downloads.haskell.org/~ghc/7.2.2/docs/html/users_guide/rewrite-rules.html
twitter.com/NSFWRedditVideo

First for Haskell


pls wait until bump limit next time

First for two early post.
I'm learning about this MVVM clusterfuck.

Do it for Him(e)!

First for Lua.

>can't tell if this is elegant or spaghetti

dropEvery :: [a] -> Int -> [a]
dropEvery xs n = if length xs >= n
then (take (n - 1) xs) ++ dropEvery (drop n xs) n
else xs

Am I doing this database thing correctly?
sqlite3 *db;
sqlite3_stmt *stmt;
sqlite3_open("data.db", &db);
sqlite3_prepare_v2(db, "SELECT field FROM sample;", -1, &stmt, NULL);
while (1)
{
sqlite3_step(stmt);
int len = sqlite3_column_bytes(stmt, 0);
if (!len)
break;
char *data = (char *) malloc(sizeof(char) * len + 1);
char *col = (char *) sqlite3_column_text(stmt, 0);
strcpy(data, col);
printf("%s\n", data);
free(data);
}
sqlite3_finalize(stmt);
sqlite3_close(db);
return 0;

...

i got you senpai
dropEvery ∷ [a] → Int → [a]
dropEvery xs n | length xs >= n = take (n - 1) xs ++ dropEvery (drop n xs) n
| otherwise = xs


would look neater with a where clause

thanks
but what about the functions used? i was originally thinking of matrixifying the list and mapping butLast over them and then concat, but that doesn't work if the last list is not full.

is there a idiomatic/insightful answer here?

>mfw all this gibberish

I want to inseminate hime

here's another, dropEvery looks much nicer in this

splitAround n xs =
let (front,back) = splitAt n xs in
(take (n-1) front, back)

dropEvery ∷ [a] → Int → [a]
dropEvery xs n | length xs >= n = front ++ back `dropEvery` n
| otherwise = xs
where (front,back) = splitAround n xs


you can use backticks to infix a function

whoops
front ++ (back `dropEvery` n)
got the associativity wrong

compiler warning

What shitty compiler are you using?

not sure what you mean by this, & why would that not work for the last one

...

Why people say that Linux based oses offer great tools/environment for devs?

Can you give me an example?

using
import Data.Bifunctor (first)

splitAround n xs = dropLast `first` splitAt n xs

never programmed before and i want to get good at C, should I go bottom up by starting with assembly and then working on C or top down from Haskell or Python?

Tons of language implementations that do not suck. Tons of high quality software.
Shell, editors, compilers and terminal emulators that do not suck dicks.

You cannot fool me, you have actually programmed before!

Writing FizzBuzz 24/7!

let's see
to install a library, you just type apt-get install libwhatever and link it with -lwhatever in gcc.

To get that shit working on windows, you need to install the latest version of visual studio 2016, download outdated windows binaries for libwhatever, copy the header files into your project directory, add them to your environment PATH, and it probably won't work anyway

If you want to learn C just start with C.

>she

But they are available on Windows too.

I use VS Enterprise I have it all.

Only some of them as shitty buggy painful to use ports.

I like to do this to maintain compatibility with C++ compilers.

Might be easier to start with something like Python, C may be overwhelming for a beginner.

But that's stupid.

All of them come with compilers and relevant dev tools like GNU Make pre-installed. Library installing is a straight forward thing, just search for it with your package manager. Its just much simpler to jump into than Windows development where there's a million things you need to do to even start.
And things aren't overcomplicated. All you need is a terminal and you're ready to program. Everything from man pages to debuggers to profilers to what ever you need is there.

The best option would be to start with Scheme and SICP if he actually wants to learn.

i mean something that gives insight into the problem, possibly using haskell/ocaml-unique functionality. something like evan-tech.livejournal.com/220036.html

it would work if I just did take (n - 1) instead, I think

what's something cool I can make in java as a beginner

Also, an even better solution would be to size of the de referenced pointer instead of its data type.

cs61b.ug/sp16/materials/proj/proj2/proj2.html
cs61b.ug/sp16/materials/proj/proj3/proj3.html

I don't really see there being a particularly special implementation for this specific problem

What if the result has a null terminator in it? Then strcpy will stop prematurely.

and yes it's possible the length check is redundant

I actually want to learn, so whats the complete path I should take? Scheme and SICP -> Python -> C?

better to terminate early than to cause a segfault

Scheme and SICP -> C -> asm/Haskell

fair enough, thanks.

Might as well use strdup then instead of doing the malloc and all that yourself.

Someone else answered the other day and said
"first learn haskell
then learn python
then learn c#
then learn c++
then learn x86 asm
then you might be ready to learn c"

You could always index the items in the list and then check modulo n

He was clearly trolling as C is easier than (and mostly a subset of) C++. It's also much easier than x86 assembly.
Moreover, nobody would suggest Haskell to someone who just started.

>She

Who the hell are you quoting?

here's a very inefficient example


import Data.Bifunctor (first)

indexed ∷ [a] → [(Int,a)]
indexed [] = []
indexed (x:xs) = (0,x) : (first (+1) indexed xs)
-- extremely inefficient

dropEvery' ∷ Int → [(Int,a)] → [(Int,a)]
dropEvery' n = filter (\(i,_) → i `mod` n /= 0)
-- ((/= 0).(`mod` n). first)
dropEvery n = (snd ) . (dropEvery' n)

>C is easier than C++

(snd ) . (dropEvery' n) . indexed

When should I use references as arguments for functions in C++?

When should I return them?

Why don't I just always accept/return objects?

I'm so confused ;_;

never

use & whenever you want to pass a local variable as a pointer to another function

returning objects is wasteful, especially once you start dealing with structs that hold non-trivial amounts of data.

and they usually have pointers to pointers inside of them, so good luck returning a struct by value and not by reference.

Whenever you don't want to copy them

>When should I use references as arguments for functions in C++?
When
a) The structure is so big you don't want to copy it for the argument as it would take too long
b) When you want to manipulate the referenced object in the function.

>When should I return them?
Depends. If you want to provide, say, access to a private class member, you can make a function that returns a reference to it. If you want to make it a read-only thing, make the function return a const reference.

>Why don't I just always accept/return objects?
I don't understand.

any way to ssh without opening a port via your router?

ssh localhost

Toolchain integration with the OS.
Everything runs in the terminal emulator, vim/emacs, git, gdb, valgrind, C programmers have access to POSIX and manual pages for everything all without leaving the terminal, and the only build system worth a shit relies on gnu code so that would involve cygwin if you wanted to have that on windows.

For C# and other .NET stack stuff windows is a must, but C and C++ programmers will have better workflow under linux.
Interpreted languages work fine on any system in my experience.

But really if you're writing C or C++ that does not compile under linux then you're doing it wrong.

C is simpler, but for this very reason it is harder to use.
A bit of a dark art as they say.
First rule of C is that if you don't already know the first rule of C then you're retarded and should kill yourself.

Easier to learn, simpler to use.

If I want to create a cross-platform program (Android, iOS, Win, Linux), would I have to write the backend for it in C++? Or are there other options? (besides rewriting from the ground up for each platform)

Please stop posting cute anime girls. They make me want to cry. That feel when no gf.

>girl

>girl
user I have some news for you..

Fucking japs literally drawing girls and calling them boys. Fucking retarded Jap homos.

>homos
The author of himegoto is actually a girl.
Checkmate

Rekt
w/ No Respekt

I find Java to be the best for cross-platform. However, this is only if you NEED to do it. I'd suggest using each platform's native language. C# for Windows and Swift for macOS. Linux is whatever you want.

Welcome to Sup Forums

Enjoy your stay

>Fucking japs literally drawing girls and calling them boys
Yes, and?

If he wants to learn C why would you direct him to asm/Haskell after C? Useless if you're not going to be using it

dropEvery :: Int -> [a] -> [a]
dropEvery n = go (n-1)
where
go :: Int -> [a] -> [a]
go _ [] = []
go 0 (x:xs) = go (n-1) xs
go k (x:xs) = x : go (k-1) xs


This one is more efficient (try to avoid ++)

How do I get a comfy C job?
Everyone wants a degree and 5 years experience for an entry level job.

so he can get good

That's pretty.

What's the point of haskell if you're just going to write obfuscated imperative code?

that's not obfuscated and definitely not imperative either

Github.com

Do some projects and believe me start-ups will spam the shit out of you. Understand what you're getting in to though. However, if you want to be with a big company, you need schooling unless you have good connections and whatnot. Be that from LinkedIn or whatever, just network in general.

ok, here's how I would do it in python.

def drop_every(xs, n):
result = []
for idx, x in enumerate(xs):
if idx % (n+1) != 0:
result.append(x)
return result


That code seems in the exact same spirit. You're iterating through the list. I realize by this definition the implementation of "map" or "filter" is iterative too, but in general why not use higher order functions?

idx + 1 % n, I mean

You can write any list operation with foldr, but adding "k" to the accumulator becomes a bit clumsy.

My version is lazy and (I believe) is a "sufficiently good consumer" so that it can be fused with other list operations. That alone is a very nice improvement over the imperative version.

What is a sufficiently good consumer?

Your function is strict in the pattern matching except for the _. Also in a situation like this a case statement is better. Pattern matching in a where clause is ugly.

what fucking idiot invented fat32

ctrl+f "good consumer" here: downloads.haskell.org/~ghc/7.2.2/docs/html/users_guide/rewrite-rules.html

It's strict in the mathematical sense, yes. In a practical sense, this just evaluates the list to WHNF for n > 0, not NF.

Can anyone else vouch for this learning path?

Some fat guy in his 30's.

got a silent giggle out of me

I think Swift is my new favorite language.
I feel kind of dirty.

Be honest with me guys, do I code like Pajeet?

Scheme / Sicp -> C was a pretty standard path for a long time in colleges. Sicp got phased out for python and C was phased out for C++ / Java / C#.

eh, looks fine
start commenting and you are on your way to being a bona fide Anglo-saxon programmer

Would I be walking on a path to extinction if I go for the Sicp -> C route as opposed to Python -> Java? If employers think it's an outdated skill set that might be a little off-putting...

>class
Full pajeet.

Sicp -> C then pickup C++ / C# / Java

By then it'll just be picking up new syntax. Your base skill set will be relatively strong.

Also get used to the common frameworks in the field you wish to pursue. Pretty much every job expects sql knowledge and the ability to use the microsoft monopoly products.

>sans serif
REEEEEEEEEEEEEEEE

depends what you want to learn/what your goal is. it can either be perfect or terrible depending