/dpt/ - Daily Programming Thread

Daily Programming Thread
What are you working on Sup Forums?

Last thread

Other urls found in this thread:

voidspace.org.uk/python/articles/duck_typing.shtml
github.com/python/typing/issues/258
gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html
ed-thelen.org/comp-hist/CBC-Ch-02.pdf
a.4cdn.org/a/catalog.json')
stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how/
github.com/PyUserInput/PyUserInput
twitter.com/NSFWRedditVideo

First for D

>printf

Real thread made 3 minutes before this

Why do people make DSLs instead of just using Scheme?

>3 minutes before this
1: 3 minutes before this the last thread was not over the bump limit
2: It was not linked in the last thread, DPTs are a linked list thus this is the only valid one.

Python
>Python is dynamically but strongly typed

is that a correct way to think about it?

voidspace.org.uk/python/articles/duck_typing.shtml

I think I'm ready to start learning a second language.

Is Javascript really as bad as people make it out to be?

Do I need it for jobs?

EVERYONE SHOULD LEARN TO CODE!
GIRL POWER!

It's a linked list, just no doubly linked

You give me an anecdote and I give you one

ok but she made cobol

The new thread should link to the old and the old thread should link to the new. Seems like a double linked list to me.
In the past we had it so only the last thread needed to link to the new one but the double-linked system is better. However we never had it so only the new thread linked to the old one.

>posting in retarded threads

is the real new thread

It's difficult to distinguish between dynamically and statically typed languages nowadays. What some people might consider as dynamic typing might actually be a union that changes from a preselected range of types in the runtime. C and many statically typed languages have unions and could easily do that, it's just with more syntactic sugar.

1: Your thread was made long before the bump limit
2: It was not linked in the last thread, DPTs are a linked list thus this is the only valid one.

because Scheme is good for making DSLs

Sounds more like a technicality.

I would not consider it a strongly typed language, even though it may technically be one, much the same as I do not consider a cucumber a fruit when I'm cooking.

In an offtopic note: github.com/python/typing/issues/258

Guess i'll post it here too

currently working on a project, and for the first time im trying to make an accompanying design document to help me stay organized and not have tiny snippets of notes everywhere.
So far this is what i have in the design doc:
>Definitions relating to project domain
>Project goals
>Software description
>list of ux elements
>criteria for completion
>milestones

So far this is all great and has helped me stay more focused and organized, but it doesn't really go into the code(classes,hierarchies,functions), so i find myself going back to my same old disorganized way.

How would i go about documenting the code?

Write out EXACTLY what you need data-wise. Translate that to small lines/snippets of pseudocode.

Personally, I find the Agile design to be great when I'm trying to determine actual tasks that need to be done.

The basic structure is:
Feature
User Story
Task

A feature is a particular function your software should perform, while user stories make up the various possible and desired interactions with the software (both from admin and user perspective), and each "story" can be broken out into specific tasks (the actual code you'll write).

Sounds like some faggy bay area coder meme.

It probably DID come from those bay area faggots, but it has to be one of the few things they did right.

Can __builtin_apply and the rest of the extensions here gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html be used instead of libffi?

Women. Not even once.

apply :: f -> [a] -> b
apply f args =
...


fill in this definition

I once took an intro programming crouse in japan where we submitted by printing our code out on paper.

I think I want to learn R.

Anyone ever work with it?

Dunno. Tbh I feel that I could RTFM them right now while knowing nothing about them, get what both of them are for, and decide if it's close enough. That would make me feel good about showing off by answering some user's question on an ephemeral medium, but if I'm able to, why aren't you?

TL;DR: why do you need to ask?

wot

i took an intro to C++ course once where the chapter tests, midterms and the final had you writing out entire programs on paper.

Compiler error = fail.

how would you write apply in haskell
lisp can do it just fine

So?
And Ada Lovelace was the first programmer.

(not the same user by the way)

no she wasn't

stop regurgitating feminist propaganda

It's not even feminist propaganda. She literally predates feminism and so does the evidence. Not even the feminists can turn back time to change it.

>evidence
But none of that stuff ever happened.

> All but one of the programs cited in her notes had been prepared by Babbage from three to seven years earlier. The exception was prepared by Babbage for her, although she did detect a 'bug' in it. Not only is there no evidence that Ada ever prepared a program for the Analytical Engine, but her correspondence with Babbage shows that she did not have the knowledge to do so.[73]

Fuck iterations.

Program against sets.

how do you do anything with sets without iteration (^:

I'll let the machine do the iteration.

The programmers job is merely to define the sets.

yeah, its power is in the packages

learn how to work with them too

I want to be able to use R practically, and I already know how to program.

Any particular book you would recommend?

user-kun we know you are quoting conservapedia

they way I learned it myself I wouldn't recommend for everybody, I read a very information dense tutorial/ebook from cover to cover

I don't know which book is best

Has anyone here ever had experience sourcing the S-Boxes for Serpent?

I can only find optimised code for them but no specifications. DES came with it's 'supplementary material', and AES has similar, but Serpent has no such content that I have found thus far. I've read it's papers and submissions, but beyond code there is no definition or specification for any of them. I have a feeling there is a document I have missed or something. Please help.

Why do the rows get xbox hueg when one element is wider?

ed-thelen.org/comp-hist/CBC-Ch-02.pdf
Sentence is along the page break from p88 to p89.

Probably for alignment

I need some help I am fetching information from json and printing it to console as well as to a file.

but in printing it to console I have this error:
Traceback (most recent call last):
File "Threadmon.py", line 34, in
text_file.write(json[j]['threads'][i]['com'])
UnicodeEncodeError: 'cp932' codec can't encode character '\xe9' in position 687: illegal multibyte sequence


I am only just really starting out with python and this is something of a beginner project.
I am accessing json data and every time a post has Japanese in it, it throws an error, I am not sure how to deal with this.
I know my CMD is code page 932 but It has never problems deal with Japanese before and still doesn't outside of this error apparently.
I assume that one requesting the json data it gets encoded into the wrong type? or that write() assumes it is a certain type?

How bad is this for an "infinite calculations calculator"? This was my first hometask.

#include
#include

int main()
{
int inival, nextval, negnextval, dispresvaladd, calcresvaladd, dispresvalcon, calcresvalcon, dispresvalmul, calcresvalmul, dispresvaldiv, calcresvaldiv;

printf("Input your initial value ");
scanf("%d", &inival);

calcresvaladd=inival;
calcresvalcon=inival;
calcresvalmul=inival;
calcresvaldiv=inival;

loop:

printf("\nThank you. Now input your next value. Input zero to crash this plane with no survivors.\n");
scanf("%d",&nextval);

negnextval=-nextval;

dispresvaladd=calcresvaladd;
calcresvaladd=calcresvaladd+nextval;
printf("\n%d%+d=%d",dispresvaladd,nextval,calcresvaladd);

dispresvalcon=calcresvalcon;
calcresvalcon=calcresvalcon-nextval;
printf("\n%d%+d=%d",dispresvalcon,negnextval,calcresvalcon);

dispresvalmul=calcresvalmul;
calcresvalmul=calcresvalmul*nextval;
printf("\n%d*%d=%d",dispresvalmul,nextval,calcresvalmul);

dispresvaldiv=calcresvaldiv;
calcresvaldiv=calcresvaldiv/nextval;
printf("\n%d/%d=%d",dispresvaldiv,nextval,calcresvaldiv);

goto loop;

system("PAUSE");
return 0;
}

> loop: ... goto loop;

What the fuck.

I haven't been taught any other way to cycle, I'm sorry. I did leave inputting zero as an option to stop the loop.

use a while statement

>those variable names
>goto loop instead of while(1)
>system("PAUSE")
>my eyes

I promised my teacher not to use the things he hasn't told us of. He told us of the "goto" command in the context of "never do this", so it's not his fault

Pretty much as bad as it gets, which has me wondering if this was carefully crafted for fat stacks of (You)s

post the entire code block. most likely, you're opening the file with the wrong encoding.

apply _ _ = undefined
is the only """"valid"""" answer

import urllib.request
import json
import webbrowser

text_file = open("index.html", "w")
i = 0
j = 0
request = urllib.request.Request('a.4cdn.org/a/catalog.json')
response = urllib.request.urlopen(request).read().decode('utf-8')
json = json.loads(response)
threads = len(json[0]['threads'])
pages = len(json)
text_file.write("")
text_file.write("Sup Forums Catalog Python")
text_file.write("Sup Forums Catalog Python")
text_file.write("")
text_file.write("")
print(" Fetching json from Sup Forums @ Sup Forums")
while j < pages:
text_file.write("")
while i < threads:
if 'tim' not in json[j]['threads'][i]:
text_file.write("")
else:
print ("tim images parsed: "+str(json[j]['threads'][i]['tim'])+"s.jpg")
text_file.write("")" class="external" rel="nofollow" target="_blank">i.4cdn.org/a/" str(json[j]['threads'][i]['tim']) "s.jpg\">")
text_file.write("
")
text_file.write("Thread: "+str(json[j]['threads'][i]['no'])+"
")
if 'sub' in json[j]['threads'][i]:
print("Thread title: "+str(json[j]['threads'][i]['sub']))
text_file.write(""+str(json[j]['threads'][i]['sub'])+"")
else:
print("Thread OP: "+str(json[j]['threads'][i]['com']))
text_file.write(json[j]['threads'][i]['com'])
i+=1
text_file.write("")
text_file.write("")
j+=1
i=0
text_file.write("")
text_file.write("")
text_file.close()
print(" ")
print(" Number of Pages: "+str(pages)+". Number of threads: "+str(threads)+".")
print(" Sup Forums JSON fetched and written to index.html")
new = 2
url = "file:///F:/Programming/python/web/index.html"
webbrowser.open(url,new=new)

i'm learning c++ as a hobby, and thinking to learn another language. what language should i focus, after c++?

You should've started with C

BASIC and MIPS

c# or java

Java or C#.

Maybe even Javascript if you want to go full employable.

Haskell

but instead of learning another language improve your c++ skills. c++ is a very powerfull programming language

>Scalars, or individual numbers, do not really exist in R. As mentioned earlier,
what appear to be individual numbers are actually one-element vectors.

I'm okay with this.

I'm not really sure why your interpreter is trying to write with the encoding cp932. Try opening the text file with:

text_file = open('index.html', 'w', encoding='utf-8')

that's the same as with APL, J, etc.

Don't talk if you do not know the topic.

BCPL

Its what I use at work and its great! They want to start porting things to Java but im like, nuuh.

doesn't matter, it's being written fine
he's printing it to the console, except he's using windows so he has CMD which is from the stone age
stackoverflow.com/questions/388490/unicode-characters-in-windows-command-line-how/

you should
just
maybe
kys?

and include conio.h

whats conio.h?

a header of c xD

oh right - I've never had to worry about that.

In LISP's case the function is actually:
apply :: ([Dynamic] -> Dynamic) -> [Dynamic] -> Dynamic
apply f args = f argsWhich is of course perfectly valid Haskell.

Hurr. I think I forgot my / in the end code tag.

It looks like a vestige of /prog/. Makes me nostalgic.

>(or hopefully her)

Is it considered bad form to write Python scripts using a lot of subprocess.run() to basically substitute Bash scripts?

I don't want to learn proper Bash scripting and I want to write a few convenience tools.

Reposting in the interest of readability.

Tilde is an assertion that types are equal. (a ~ b) is read "type
a unifies with type b," so a and b may be substituted for one another.

Begin with unknown universal types for each subexpression.
f x = f (f x)
f x = (f :: a) ((f :: b) (x :: c) :: d) :: e
Like terms f unify, a ~ b:
f x = (f :: a) ((f :: a) (x :: c) :: d) :: e
Observe the inner subexpression:
((f :: a) (x :: c) :: d)
We see f applied to x, so it must be a function of x's type with the given
result type, i.e. a ~ (c -> d)
f x = (f :: c->d) ((f :: c->d) (x :: c) :: d) :: e
Now ignore the inner expression, but for its overall type:
f x = (f :: c->d) (_ :: d) :: e
We see f applied to an argument of type d, so c ~ d:
f x = (f :: d->d) (_ :: d) :: e
We have already proved that (f :: d -> d), but for the sake of
completeness we see that the overall result type also unifies with f's
domain, i.e. d ~ e, given the final typechecked expression:
f x = (f::d->d) ((f::d->d) (x::d) :: d) :: d

Because they have working brains

No, there is nothing wrong with that. Really is no reason to use bash especially since most distros have Python included.

And since the thread is deleted and rbt seems down, the post in question said something like this:

Prelude> :t let f x = f (f x) in f
let f x = f (f x) in f :: t -> t
>Haskellfags will defend this

apply f args = f args

monomorphism

whats better, a function that:
>returns an error code and does a side effect
>raises an exception if needed but is otherwise pure
>is 100% pure and exceptions are disabled during compilation

use pure functions with monads

That doesn't have the same type either.
apply :: Applicative f => f (a -> b) -> f a -> f b

t -> t is clearly not monomorphic. What are you even saying? I already gave the typechecking proof that f :: t -> t, and it has nothing to do with the monomorphism restriction, if that's what you're trying to say.

apply f arg = purge f arg

>is 100% pure and exceptions are disabled during compilation
This. Exceptions and side-effects should be avoided.

retval, error = function(input)

fuck
*pure

anyone here ever written any video game bots before?
id like to knock one up in a platform agnostic language like python, but as far as i can see the only library for manipulating the mouse and keyboard is windows only.

ideally id like to write it in something fairly high level, so i dont have to piss about with needless OOP and low level shit

/prog/ still exists

last one
just use Maybe for possible error
Either when you want more info

github.com/PyUserInput/PyUserInput

caveat: no keyboard input on macOS

Reverse the order and you have them ranked by best to worst.
Exceptions suck, but a sufficiently smart / paranoid compiler knows if you forgot to handle them all and can force you to (or at least raise a warning).

I'm not always 100% against side effects, but I don't want them happening during errors.

too many hasklelfags

never too many