/dpt/ - Daily Programming Thread

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

Attached: 1525102272864.jpg (750x1000, 125K)

Other urls found in this thread:

youtube.com/watch?v=1vrEljMfXYo
jeffe.cs.illinois.edu/teaching/algorithms/book/03-dynprog.pdf
twitter.com/SFWRedditImages

JavaScript rocks!

Attached: javascript rocks.png (1000x494, 134K)

C++ metaprogramming is fun!

Does anyone have examples of good open source C++ programs?
Something demonstrating what the committee has in mind when they say that you should use their features.
No trivial programs or libraries please I'm looking for realistic usage code primarily.
I don't really care which standard as long as it is C++11 or up.

the only valid way to write C++ is the way I write it on my personal projects

nth for Nim!

managed to make it faster by storing the row positions in inverse order. strictness annotations didn't help though
cat backtrack.hs && time ./backtrack
module Main where

valid :: Int -> Int -> Int -> [Int] -> Bool
valid _ _ _ [] = True
valid r p c (x:xs)
| x == p || x == p + r - c || x == p - r + c = False
| otherwise = valid r p (c - 1) xs

queens :: Int -> [[Int]]
queens n = q 0 []
where q r ns
| r == n = [ns]
| otherwise = f [x | x

Check D metaprogramming

What's the highest compiletime/character program under 20loc you could make in C++?

What language is this?

Line count after preprocessor, no cheating.

Looks like Haskell to me.

you can't really write useful Haskell code before you understand state monads

JavaScript ROCKS!

Attached: js-rocks.png (1000x494, 368K)

nim PAPER!

>GC
lamo

Haskell undefined

Just started learning fucking react and I have to build up my portfolio site so I can get the fuck out of Virginia :/

Ahahahaha React wont get you no pussy!!

same notfag

youtube.com/watch?v=1vrEljMfXYo

C++ fags btfo.
Again.

Attached: Screenshot_2019-01-27 John Carmack on Twitter.png (611x545, 81K)

Yeah my CS degree doesn't either lol, but neither does living somewhere I don't know anyone kek, unless I wanna fuck randos off tinder but even thats not great here

I think the plan is
>> finish up learning react and shit on FCC
>> build up a decent-ish resume
>> quit workingn at a mid tier hosting company and get a entry level webdev gig in Philly or NY

lol

I didnt know that Cuckmack is an leftist.

Carmack is a true programmer that just loves learning new langs and doing shit.
He's gone from C to sepples to Haskell to Racket to now Rust.

I already linked you to Higan yesterday.

Whats the best way to extend a project i have on github
do i fork it and add to it there
or do i create a new folder in the repository and add there?
i am making a graphical user interface for my command line application

Attached: eeb161ed0103676b8657f90a21f519e8.png (451x619, 428K)

Why not just create a new branch?

i want my application to be able to be used as a CLI or a GUI
doesnt a branch imply im eventually gonna merge and make my thing just one?

you know what arguments are lad?
it's really not a hard concept.
cli foo
cli foo -gui

But you want a branch regardless because an optional GUI is a big feature.

depends on how you are approaching it. Is your GUI using the same underlying code? Then make it a completely new github project. Is it just an optional in your program? Then just write into the project without anything.
Is it a rewrite of the code? branch it and maintain it as a branch, releases can either be separated or maintained in parallel

hmm that makes alot of sense,
thanks user

Attached: __ruby_rose_rwby_drawn_by_ecru__ff42d126f228dde6998b6597468fc345.png (750x1022, 844K)

im envisioning it as literally a wrapper over the cli

Make it into a separate project

rust would be pretty cool if you didn't need unsafe mode for anything non trivial
and if it didn't make c++ tier bloated binaries

Is a for each the only way to avoid runtime bounds checking?

Attached: 431B807D-8247-459B-9438-00DEDA8AA4FD.png (400x400, 107K)

do you think a foreach runs on magic?

what does that even mean
the way to avoid bounds checking is not to bounds check (hopefully writing code that doesn't go out of bounds)

In what environment?
In most languages a foreach is implemented as
for(int i = 0; i

unless your question is language specific?

you actually can translate a foreach into lower-level instructions where no arbitrary array indices are queried, and thus there is need to check array indexing operations for validity since the compiler knows all the indexing operations it's generated are valid.

I don’t think you get it.
for e in list:
print(e) #no bounds checking
for i in range(len(list))
print(list[i]) #bounds checking

that's because in your language, list[i] is bounds checked. that's got nothing to do with the loop though, it's because of how it does the subscript operator (i mean _[_])

so in the sense that it doesn't use _ [ _ ], it isn't necessarily bounds checked. ofc for all we know, for each (the first one) could actually be implemented in terms of the second

Uh... the underlying code is exactly the same.
Unless the question is about semantics, in which case there's plenty of ways to avoid explicit bound checks.

>Unless the question is about semantics, in which case there's plenty of ways to avoid explicit bound checks.
How?

I've been programming for 2 years and it was pointless because I don't have any use for it.

Attached: 1516225723177.gif (320x240, 2.19M)

>so in the sense that it doesn't use _ [ _ ], it isn't necessarily bounds checked. ofc
I know.
>for all we know, for each (the first one) could actually be implemented in terms of the second
This isn’t the case.

>This isn’t the case.
In what conditions? What lang, what code, what toolchain, what environment? This statement is contingent on all these variables!

well if possible do whatever for each is doing
do you know how the list is implemented?

Depends on the language.
In most OO langs you could implement a container class that has a function that takes another function as an argument and applies it to every element using plain old fors.
In Java specifically you have the whole stream API which does that and more.
Something like Prolog doesn't have for at all and relies on its declarative nature instead.

All those examples (any foreach in any lang included) bound check beneath the hood anyway, tough.

>All those examples (any foreach in any lang included) bound check beneath the hood anyway, tough.
That’s weird. I would’ve figured they’d use C indexing in for each because it’s guaranteed to not iterate over the length of the list.

The list is a data buffer with a capacity and a length.

How does that get rid of bound checking?
You have to figure out when to stop iterating somehow. i < size() is a bound check after all.

Yeah but that’s the only one and you can use C indexing to return index i as e to the user since i is guaranteed to never be greater than the list’s length.

I can’t believe I have to try this fucking hard to explain what I mean by C indexing and bounds checked indexing to a thread of people I assume are smart enough to code.

Lisp is the most powerful programming language.

Are you ? If that's the case, it would have helped to announce the language you're talking about in the first place. Also bounds checking as a term might not be exclusive to array indexing. Explains a lot of the confusion, the rest is people rushing to give you advice when they don't even know what you're talking about.

If I do
gcc -c main.c
and then I try
ld -o test main.o
why do I get an error that _start cannot be found?

Just in case I'll say this happens when I tried the most basic code void main(){} so it's not the code it's something else.

*int main That's your problem right here

You're not supposed to call ld directly, you're supposed to call it through gcc. gcc will invoke ld with the core C runtime library, crt0.o, as an argument. This library contains _start which is the entrypoint for the program.

Wait no that's not it. I believe _start is supposed to be coming from one of the standard .a files. Gotta find it cuz ld isn't going to do it implicitly.

So which additional argument I need to pass to ld?

Just invoke the linker through gcc, don't do it directly. I don't know what the real arguments are.

idk. the ld manpage (fucking RTFM nigga) suggest "ld -o /lib/crt0.o hello.o -lc" but there's no /lib/crt0.o on my Arch system. Only crt1.o, crti.o and crtn.o (wtf?)

how long does it take for an amateur to make side money using programing skills?

crt1 is the same as crt0 but support C++ ctor/dtors.

OK. When using it tho, I get link errors:
$ ld main.o -lc /lib/crt1.o
ld: /lib/crt1.o: in function `_start':
(.text+0x16): undefined reference to `__libc_csu_fini'
ld: (.text+0x1d): undefined reference to `__libc_csu_init'

Python

Is there a way to "reset" EOFError? I have a segment in my program where you hit ctrl d to stop giving inputs and that catches the EOFError and breaks the loop. It works fine until it comes to another part that asks for input. Then it gives the EOFError and exits the program.
Still very new to python so all this is new to me. Is there any way to reset the eoferror, in a sense?

look just use gcc. Don't fuck around with the internals like this.

Yes I know but I'm curious.

Don't respond. I'll look into this by myself.

I get the same thing. I tried all of them (crt[1in].o). Also, are you sure -lc argument is necessary?

It raises EOFError once and then carries on. It's your code that's dogshit and needs to be reset.

cat stdin-eof.py
while True:
try:
print(input())
except EOFError as e:
print("EOF", e)
continue
python stdin-eof.py
a
a
a
a

EOF
aa
aa

EOF

There's a lot of them, not sure which ones are required.
strace -s 100 -f -e execve gcc -o test main.o

>Carmack keeps learning languages with no new shared programs to show for it
>he even talked for hours at length about how he wants to reprogram Doom in a functional language
>this was years ago
>he still hasn't
You think he hangs out here sometimes

Well he's pretty locked down at Occulus, if you watch his keynote, he talked about how he wanted to use C and Racket for his mobile VR work. But got overruled because they went with "easier" languages.

is gnu guile any good in today's world? i'd like to use it as shell script language.

Imagine thinking you need constructors and destructors to do RAII.

sure

implemented the lis algo again, now using dynamic programming
jeffe.cs.illinois.edu/teaching/algorithms/book/03-dynprog.pdf
module DynamicProg where
import Data.Array.Unboxed

type IntArray = UArray Int Int

emptyIA :: Int -> IntArray
emptyIA n = listArray (0, n) $ take (n + 1) $ repeat 0

lis' :: IntArray -> Int -> IntArray -> IntArray
lis' ai n js = listArray (bounds js) (map g as)
where as = take n (assocs ai)
g (i, e)
| i /= 0 && e >= ai ! n = ji
| otherwise = (1 + jn) `max` ji
where ji = js ! i
jn = js ! n

lis :: [Int] -> Int
lis xs = foldr (lis' ax) (emptyIA n) [1..n] ! 0
where ax = listArray (0, n) (0:xs)
n = length xs

Anything available can be good. I prefer Perl for more complicated scripting than Bash.

>look up Guile
Oh goodness what the hell is this

Imagine wanting to catch and rethrow every exception so you can call your not-destructors yourself for some reason.

it's scheme

Literally just chain your functions with fmap or similar. Exceptions are totally unnecessary.

>exceptions

lua?

Alright wise guy, using a different error handling monad would still require you to do the same thing.

what about it

NO EXCEPTIONS

Any of you watch Jonathan Blow's coding streams?

In the language he created he can compile the game he's working on (67k sloc) in < 5 seconds.

Attached: blow.jpg (293x172, 4K)

tcc can compile C even faster

machine code can be compiled in roughly 0 seconds

this lmao

Right, but jai is a high level expressive language so that comparison doesn't really track.

no it isn't

So like C?

and C isnt?
lol

>In the language he created he can compile the game he's working on (67k sloc) in < 5 seconds.
Sokoban's like 1.6 right now, and he's even unhappy about that and wants it under 1.
As far as Jai goes though, fast compile times aren't worth using a barebones made-to-order language.

yes it is.

okay the terms are relative, so if you're going to be pedantic, it provides many more features than C while still retaining the same low level control.

also no one uses tcc

it's definitely less barebones than C, but yeah it is made-to-order for stuff like gamedev, but that's the point

alright guy if you say so.