/dpt/ - Daily Programming Thread

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

Attached: asm.png (315x320, 52K)

Other urls found in this thread:

githut.info/
twitter.com/NSFWRedditImage

day of rope for webshitters when

it was yesterday, you must have missed it

auto main() -> int {
auto car = new Car();

return 42;
}

> () -> {}

Attached: 1547386568007.gif (450x450, 1.99M)

What do you use Docker for?
Feel like I should pick it up since it seems to be used everywhere but don't know how I'd integrate it into a personal project.

Holy shit is that C++? It looks so much better these days. When do you think we can just remove 'auto' and the compiler will just assume it?
main() {
car = new Car();
return 42;
}


Should be easy enough to infer that it's
int main() {
Car car ...
return 42;
}

>literally adds more typing to specify return type
>people will say it's an improvement

Because that would be ambiguous, how would the compiler be able to tell that it's not actually just:
main() // function call
// scope/block start
{
car = new Car();
return 42;
}

>When do you think we can just remove 'auto' and the compiler will just assume it?

but a car is an auto

I don't and my work doesn't either. I think it's more popular with startups desu. Someone on Jow Forums actually told me I was an idiot for even sshing onto servers anymore. I guess corporate america is that far behind.

Attached: 1420221860425.jpg (353x350, 29K)

Docker is for people too dumb to reproducible builds (i.e. devops and soiadmins)

>I was an idiot for even sshing onto servers anymore
w-whats the alternative?

you still ssh it's just that not into individual servers, instead you have a main server for the sole purpose of ssh session then you have it tunnel the session to actual servers via internal/private network

deploying a new docker image I believe is what he told me, or container image. Same shit I guess. I still don't understand how redeploying a new image is going to fix applications that have large databases that need maintained. It's not like you can just redeploy them every update.

>people on /dpt/ still aren't using CI/CD techniques
Lads at least sign up for something like Gitlab that you can customize to automatically build and test your code on every commit.

Attached: kid.jpg (362x346, 38K)

What if i already do the testing before i commit?

That's fine, but CI ensures nobody forgot to do their job and uploaded shit code. You'll immediately know when a commit is bad or when Rasheeh fucked up again.

>ci didn't pass
>actually an issue on their end
every fucking time

Puppet/Ansible for running scripts, etc
Docker for deployments
Splunk and other data/monitoring services for pulling logs/server stats/etc

There's honestly no real reason to ever log into a production server.

How do you find and choose libraries/frameworks? My job uses dropwizard for REST services in Java, but I haven't heard of it before or how they found it & why they use it.

Google, read, compare, choose.

the ones future employers will pay you to use

Are GUI desktop applications used now or is everything GUI related just done as a web application with front end shit

it's all webdev. even the "real" desktop gui programs are webdev now thanks to electron

A couple of Haskell related questions:

class Show x => Foo x where
foo :: (a -> x a) -> a
-- Expected kind `* -> *', but `x' has kind `*'


Compiler doesn't like it because the Show implies the "*" kindness. Is there any way to fix it?

Also, just curious, is there any way to implement something like:
class Foo x where
foo :: a -> x

GHC is fine with this signature, but is there any way to actually implement something like that? Because:
newtype Bar a = Bar a
instance Foo (Bar x) where
foo a = Bar 1

won't compile.

>is there any way to fix it
no, what are you trying to do?
>... won't compile
foo is (forall a. a -> x)
Bar 1 requires x to be Num
instance Num x => Foo (Bar x)

there's a site I can't remember the url but basically it shows number of commits, lines per language, etc
worked with github at least
what was it?

Not shorter by any means, but here is a quick-and-dirty Scheme implementation from an imperative programming pleb. I'm happy to get criticism. I have a strong feeling I can do much better than this.

; Return a list of the integer range [start, end)
(define (range start end)
(if (>= start end)
'()
(cons start (range (+ start 1) end))))

; Take every "reset" item from lst, starting at cur
(define (take cur reset lst)
(if (null? lst)
'()
(if (>= cur reset)
(cons (car lst) (take 0 reset (cdr lst)))
(take (+ cur 1) reset (cdr lst)))))

; Do the plain skips algorithm
(define (rawskips lst)
(map
(lambda (i) (take 0 i lst))
(range 0 (length lst))))

; Do the skips algorithm, mapping from and to string
(define (sskips str)
(map
(lambda (lst) (list->string lst))
(rawskips (string->list str))))

; Type check between list and string
(define (skips lst)
(if (string? lst)
(sskips lst)
(rawskips lst)))

scheme@(guile-user)> (skips "ABCD")
$23 = ("ABCD" "BD" "C" "D")
scheme@(guile-user)> (skips "hello!")
$24 = ("hello!" "el!" "l!" "l" "o" "!")
scheme@(guile-user)> (skips '(1))
$25 = ((1))
scheme@(guile-user)> (skips '(#t #f))
$26 = ((#t #f) (#f))
scheme@(guile-user)> (skips '())
$27 = ()

i'm looking for a pythonic way to generate this pattern where symbol is random number and so on
the only thing i can think of is some modulo shenanigan

Attached: dumb.png (331x197, 5K)

I have no idea what you're trying to do.

import random

MAX = 10
symbols = ['△','▭','0','X']
print ('a|b|c|d')
for i in range(MAX):
print (
random.choice(symbols),
random.choice(symbols),
random.choice(symbols),
random.choice(symbols)
)

output
a|b|c|d
▭ 0 X △
0 ▭ 0 ▭
X X X ▭
0 0 X X
▭ 0 ▭ △
△ X X 0
△ 0 X △
0 0 0 X
X ▭ X X
▭ ▭ ▭ ▭

I want to generate a dataframe where [even, 1] = [odd, 4] in high-level way
I cannot think about anything else than modulo and I dont know how this pattern is called in english

>get a job
>Most of the emails I get from other teams in the company spell my name wrong
>some of these are from people who have known me for some time now
>My name is even in my signature and shown in the email headers
Are all software companies like this?

Attached: 1416359808225.png (800x388, 116K)

it's ok, amanymoose

>scheme@(guile-user)>
>$23 =
Add this to your .guile:

(use-modules (system repl common)
(ice-9 history))

(disable-value-history!)
(repl-default-option-set! 'prompt (lambda (repl) "* "))

Attached: pdp-tan.jpg (800x1000, 96K)

Do you guys ever draw out what you plan to code or just go right at it? Not full on UML but just enough to show what needs done.

Is this Dovid?

can I not use manually raised exceptions for controls in python3?
my idea is something like
def f(x):
if x!=0:
raise Exception("CustomError")
print ("ok")

x=3
while True:
try:
f(x)
break
except CustomError:
x-=1

Fuck you and your stupid indian nigger name pajeet

spell their name wrong even if it is "John" or "Jane" , that is the only way to fix this.

Whats a good book on Powershell?

That's so passive-aggressive that it could disgust even a woman.

def f(x):
try:
if x!=0:
raise ValueError("CustomError")
except Exception as error:
print ('lmfao')
print ("ok")

x=3
while True:
try:
f(x)
break
except CustomError:
x-=1

People spell your name wrong repeatedly to show dominance over you.

Attached: Girls.png (449x401, 490K)

well, there is this guy who spelled my name wrong even after telling him billion times to correct it. got tired of telling him time and again and i didn't just spell his name wrong, I called him a completely different name. it worked and he finally corrected the spelling.

I use pencil and paper all the time.

Is there a "fun" way to learn c programing? I'm currently reading headfirst into C language and I genuinely like the book, but I'd like a more engaging way to learn C to supplement it. I've looked up programming games but I've only seen stuff for Javascript and the like.

You subcless Exception to make a custom exception. you're just passing logging text.

write emulators in C. Simple ones like chip8.

If it works, it only makes it more disgusting.
I hate normies so much. Zero empathy, they can only understand what they're subjected to.

sure

Attached: llllll.jpg (1172x894, 359K)

>foo :: (a -> x a) -> a
I dont understand this type signature. Can you explain what you're trying to do?

>GHC is fine with this signature, but is there any way to actually implement something like that?
Sure:
instance Foo Int where
foo a = 1

>wont compile
You wont be able to implement Bar as a Foo because its impossible to write a well behaved function with type x -> a where x and a can be any type. To understand what I mean, try implementing

baz :: a
baz = undefined

That actually looks pretty nice, what book?

Based op

Lisp is the most powerful programming language.

I only draw a diagram when I know what I'm dealing with a good level of complexity so I have a map I can work along. especially helps when the logic flow takes a couple of days to put into code

not the user you replied to but I think its this?

Attached: the-spirit-of-c-original-imaebewgavffqxpd.jpg (591x832, 53K)

no idea the image has
>the spirit of C
>illustrating c
maybe one of these

How would the compiler know that car isn't a global variable?

I don't quite understand why the try inside f(x) and where you define CustomError but you made me understand what wasn't working, thanks
I see, it should be something like this
def f(x):
if x0:
raise IndexError("CustomError2")
else:
return 0
x=3
while True:
try:
f(x)
break
except IndexError:
x-=1
print(x)
except TypeError:
x+=1
print(x)

it works but it bothers that I can only use already existing errors

>the spirit of c

Attached: average c programmer.jpg (852x480, 32K)

The same way it already does. Checks the current scope and sees if it conflicts with anything.

fuck you user I'm still learning programming and I figured c was a good place to start, and I'm not stopping now

open the mouth, here comes the spoon feed
>>> class CustomError(Exception):
... pass
...
>>> try:
... raise CustomError()
... except CustomError:
... print("Caught Custom")
... except Exception:
... print("Didnt Work")
...
Caught Custom

PLS HALP I REALLY NEED IT :(

class MyException(Exception):
....
try:
....
except MyException:

githut.info/

>c
>good place to start
c is nice and all, but you should really start with something high level like python instead

much appreciated

Stop using exceptions to replace what could be handled by regular error control flow.

Attached: 1453507928618.jpg (300x281, 26K)

agreed

Is OP's pic book a good resource for a retard like me to learn assembly?

Fuck you. I don't want to deal with C and Win32 API shit. CHECK RESULT IF CANCER RETURN RESULT CHECK RESULT IF CANCER RETURN RESULT CHECK RESULT IF CANCER RETURN RESULT CHECK RESULT IF CANCER RETURN RESULT CHECK RESULT IF CANCER RETURN RESULT
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

If they are zero cost who cares

>magic zero cost in the sky man

Attached: cripples.png (1140x800, 286K)

They aren't zero cost because there's cognitive overhead in reading spaghetti.

This.

>what are you trying to do?
Well, what if I have some sort type class for higher-kinded types declaring functions which would accept value constructors (y x -> x y z) and want to ensure that the instance would have implemented Show?
Technically I can constrain a function, but what about the whole type class.

>instance Num x => Foo (Bar x)
It works, indeed. But what if x is a non-numeric value?

>I dont understand this type signature.
I was thinking of something more like foo :: (y z -> x y z) -> x a b, for example. The idea is to accept a constructor. I don't have anything particular in mind, just trying to explore.

try:
print("Because")
print("Exceptions are not zero cost"[99])
catch IndexError:
print("Exceptions should not be used for control flow")
raise Exception()
catch Exception:
print("Exception control flow is hard to follow (will this print?)")
raise MyException("Dont forget to catch this :^)")
finally:
print("Dont use exceptions if you can avoid it")

The error control flow touched my penis.

Attached: DBF61618-0820-4981-8F28-C2CC694E9BD6.jpg (224x224, 7K)

if x is non numeric then you can't have 1 :: x can you?
>what if i want to ...
using quantifiedconstraints you could have (forall a. Show a => Show (x a)) => Foo x

it's like people learned that goto is bad but don't understand why
so they simply use exceptions as a goto replacement

Finally trying to get the ball rolling with my programming journey here. To start, I'm going through Automate the Boring and working on a simple text roleplaying game.

Right now all my code is in one file and I'd like to separate it and be able to call functions from another script.For example, I'd like for the battle system to be a completely different file instead of in the main one. How can this be done?

Googling this gives me rocket scientist answers, and even putting 'python' in the google search gives me C++/Java answers.

Attached: shock.png (66x126, 10K)

Im learning python give me some simple project ideas

>foo :: (y z -> x y z) -> x a b
You wont be able to implement this because, again, its impossible to generate an unconstrained "a" or "b" from nowhere.

CLI calculator

>Googling
don't use google search, ever.
>searching the web
don't search the web for programming help. Read documentation. You're just going to get stackoverflow answers anyway.
>but I searched the web once and it halped me
yeah but then one day you want to learn an actually good language like Erlang and even though it has the best documentation in the entire world you'll never find it with shittgle searches.
also organize your code into modules and import them.

It's okay, Herb is on fixing this shit.

figured out

if i have a main menu in menu.py and want to call the function in my main file, main.py

import menu


print('What would you like to do?')
menu.mainMenu()

There's nothing wrong with goto. Dijkstra's original paper was criticizing the improper use of goto, and a journalist (aka the creator of Pascal) took it, renamed the paper and ran it as a hit against goto all together.

>Exception control flow is hard to follow
Imagine being a brainlet and believing this.

why do you keep letting parts of C++ touch your penis?

then tell me, what is the output of that code, without running it (and fixing any syntax errors)

the problem with having a brain the size of a planet is that nothing is hard, no matter how bad it is. Gotos? Move semantics for trivial classes in C++? Exceptions? Dunno what you're whining about I have 300 IQ and I can't even distinguish the difficulty of such things and "hello world" in a visual lego language.

The program can't run due to an error, trick question. :^)

exceptions help you avoid branching in 8 different subroutines on the return value
it also makes code easier to write and understand, and is zero-cost outside of 1. setting up an exception handler and 2. throwing an exception

the question asked you to fix syntax errors user. looks like you're the brainlet.

I'm liking the new definition of "zero-cost" which is "there are no costs in addition to the costs".

sure, but my point is that programmers just learn
>goto bad
and then proceed to use exceptions improperly where they would have used goto improperly