/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

youtube.com/watch?v=HQYsFshbkYw
twitter.com/SFWRedditGifs

Kenshin

The character's name is Kaoru

anime is not programming

real thread, faggots

Right now I've got a project where the end customer wants to deploy some compiled C code on an rpi zero. Save you the Google, it's ARM11. The first two sprints we compiled directly on a pi zero for convenience and just had nighties get over to test because the entire build takes well over an hour, but as the system gets more complex we really need real time commit checks. Schedule is tight.

So... Tonight I'm moving our build over to a klooged together docker image to cross compile on x86_64 for the chip in the zero... There are tons of resources out there for the more modern chip in the pi2/3 but support for the zero is still minimal.

Any alternatives I can recommend to my customer that match the power and weight on the zero? They investigated the chip and the vocore during requirements definition but it seemed like all the options had problems.

Evangelion

Can anyone give me a place to start for limiting execution of a Lua file to a certain amount of instructions per interval? I need it for a coding/optimization game idea I want to try

c fags will defend this

Start from here

Sorry

see

I'm currently trying to write a C program that prints a chess board. The number of pieces as well as the type and position of each piece is given as input. X coordinates goes from 1 to 8 and Y coordinates goes from A to H.
I have no clue on how to manipulate the n variable, which represents the number of pieces on the board.

Cirno from Touhou

Have you tried a loop?

Touhou isn't anime

The char isn't from an anime, retard.

Yet you answer to the question "What *anime* is this from?".

I did, but I ended up in a infinite loop. I tried to put it between the for's.
The program should stop asking for inputs as soon as the number of inputs equals n.

Hint: you should read all the input first and then draw the board.

I'm trying to do some image processing in Common Lisp using SDL to load images and draw results.

In Java how can I use methods in my main to add or alter a private arraylist in another class?

First dubs/trips/quads tell me what kind of a quick programming task I will write in Pascal.

You must implement addition/alteration methods in another class before.

have any of you actually completed SICP?

Solve the halting problem.

Quick, man, not slow.

could I get non meme answers... is D worth learning? more than rust for example?

spent whole weekend chasing WriterT leak U already knew about, cut memory usage to a fifth with it and other strictness fixes; last some speed though, need to find the time to fix that up

patching stack build tool tomorrow for day job reason

Nope.

I* lost*

thanks phone

Is there any simple, open-source, programming language that compiles into byte code and has performance the same as, or at least close to, C?

Clojure

I want to major in CS and make a lot of money. Is this realistic?

>compiles into byte code and has performance the same as, or at least close to, C?
Impossible.

>byte code
>performance the same as, or at least close to, C
Uhh, pick one.

Depends on your definition of "a lot"

worst 4 years of your life

>is D worth learning?
No. D is actually a deadlang. It lost its opportunity to be popular/relevant a LONG time ago.
>more than rust for example?
Rust still has some things going for it. I don't know whether it'll last, but it's probably worth learning learning.

Not impossible, but don't expect easy money.

Sorry, I meant just compiles into a binary and is not interpreted like python.

C, then.

see what?

Bytecode is ISA for a virtual machine. You wanted to say machine code.

Rust isn't what I would call simple (it's a hell of a lot more simple than C++ though) but other than that there's nothing that fits the bill.

Just C.
It's a language that compiles to a binary and has performance close to C.

Common Lisp

C is not simple, I spent a day writing and debugging
a 50 line program in C that simple writes to a file.

C is a good language and has it's uses, but it is not simple for
writing small to medium size programs quickly.

Why's that?
$150k I guess? Maybe more in late career
What do you do? Is there any "easier" money? I'm pretty interested in computers/programming however broad that may be.

(((((((((((too many parentheses)))))))))))

How much time and effort would go into building a rudimentary 3D engine?
Like, super super basic. Quake levels of basic.

Carmack is a genius, and I don't know how does one reach his levels of effortfulness.

Undoubtedly, and he basically was the first to make a properly usable 3d engine that didnt look like shit
But we've been working on 3d engines for 2 decades now, all the tricky shit's been figured out and we don't have to implement his rain-man level hacks to squeeze the performance out.

It shouldn't be THAT difficult now, should it?

You can do it in a dozen weekends if you use OpenGL.

Do you have any recommendations on reading material or guides to get started with? Not opposed to getting a textbook for this kind of thing.

If you already know what you're doing, not long at all. If you don't, it could take a while and a lot of restarts to be happy with it.

Game Engine Architecture
OpenGL Superbible if you want to use OpenGL

> I spent a day writing and debugging a 50 line program in C that simple writes to a file.
Don't blame C for your own incompetence.

>Game Engine Architecture
By Jason Gregory?

Yes, 2nd edition of course. It's a good high level reference for all the various subsystems but it also goes into detail about the "glue".

Godspeed. Let's see how long it takes before I want to blow my head off.

WHO THE FUCK KEEPS MERGING BROKEN CODE INTO DEVELOP
STOP BREAKING TESTS

>I am shit at C
>Therefore everybody else is
Nice projecting there.

Also keep some linear algebra textbook on your desk, it will be useful.

I love you dpt

You guys are alright, keep programming my good lads

Do you use restrict?

I'm trying to write a Python program that removes common stop words from a line of text taken from a command-specified input file.

The stop words text file has one word per line and the files I'm using it on are just normally formatted .txt files.

I can't figure out why the function to remove the stop words doesn't do anything. It's supposed to check each word in the split line from the original text against each stop word in the stopwords.txt file and if they match, remove the word from the line of text taken from the input.

For some reason

from sys import argv

def main():

infile = ""


for i in range(1, len(argv)):
if ".txt" not in argv[i]:
usage()
else:
infile = argv[i]

infile = open(infile, "r")

infileLine = infile.readline()
infileLine = stripSplit(infileLine)
infileLine = removeStopWords(infileLine)
print(infileLine)

infile.close()


def usage():
print("Usage: python3 word_count.py infile.txt")
exit(0)


# processes esch word in the line and strips punctuation
def stripSplit(infileLine):
infileLine = infileLine.rstrip("\n")
lineSplit = infileLine.split()

for i in range(len(lineSplit)):
lineSplit[i] = lineSplit[i].strip(",")
lineSplit[i] = lineSplit[i].strip(".")
lineSplit[i] = lineSplit[i].strip(":")
lineSplit[i] = lineSplit[i].strip("'")
lineSplit[i] = lineSplit[i].strip('"')
lineSplit[i] = lineSplit[i].lower()

return lineSplit

def removeStopWords(infileLine):

lineStops = infileLine

wordlist = open("stopwords.txt", "r")

line = wordlist.readline()

for line in wordlist:
line = line.rstrip("\n")
for i in range(len(lineStops)):
if str(lineStops[i]) == str(line):
lineStops.remove(lineStops[i])
else:
wordlist.close()

return lineStops


main()

Occasionally.

If you don't use it at every available opportunity then you might as well not use C.

Er det verdt å lære Idris?

Much less talk about how good or bad other people are at it.

It's usually something I chuck on functions after I've written them.
A lot of functions make sense to have aliased arguments, though.

I have no idea, but it's probably something to do with how Python """arrays""" actually work, because I know it has a lot of weird fucky stuff with it.

In either case, you should be using regex substitutions, not strip()

>Get invited to a Java house
>These doors look like all the other houses
>Some fag named JRE wont let me touch anything
>I litterally have to ask him to open the door to the bathroom to shit
>he takes forever
>I shit on the floor
>A burglar breaks in due to an unpatched hole in the wall that JRE left

>spent a day writing and debugging a 50 line C program

That first function just takes the original line of text and gets rid of all common punctuation and any capitalization in each word in the line since all of the stop words in the file are lower case, one word per line.

C without restrict is still miles above Java, C#, C++, etc

Don't kid yourself that not using restrict automatically makes your compiler retarded and not good at optimizations.

I know, that's why I'm telling you to use a regex substitution.
Then you only have one line to iterate over for each word in the array.

for line in wordlist:
line = line.rstrip("\n")
for i in range(len(lineStops)):
if str(lineStops[i]) == str(line):
lineStops.remove(lineStops[i])
else:
wordlist.close()


Please explain why there is an else there and how you are able to run your program without coming across an indentation error.

niBBa, I just copy pasted it straight out of the file I was working on. The else statement wasn't there the last time I ran it.

youtube.com/watch?v=HQYsFshbkYw have this mate

What the fuck is this autism and why is he coding in MS DOS and speaking like a monotone robot.

Does a computer read a program from top to bottom? If it has to jump to code in the middle of the file, does it go back to the top when it's done?

What exactly does restrict even do?

> MS DOS
It gives the most straight way to access hardware.
>and speaking like a monotone robot
He's finn

Currently writing an application for taking screenshots within a drawn area of the screen, can be a polygon/rectangle. Writing it in java but the issue is with Linux, it is simply painting the new frame on top of the previous so everything that was drawn before remains. Any ideas?

It has to do with aliasing. Just google it.

Declares that accesses through the pointer will be non-aliased, which enables some optimizations that nearly every other language cannot perform.

You make a contract with your compiler that says that the pointer you tacked 'restrict' onto is the only pointer that points to whatever it's pointing to.

Depends on whether you're compiling or interpreting, a compiler converts all of the code into machine code before the program is run, whereas an interpreter converts the code into machine code line by line at runtime.

why are you looping over all of the argv but only using 1 file

why are you converting lineStops and line to str?
are they not already strings?

also use re.split() to strip punctuation

also you never read in more than 1 line in your for loop.

you probably want to switch the order of the loops as well.

>why is he coding in MS DOS
wtf seriously? why are you NOT programming in msdos? what are you even doing here on Sup Forums?

Would it be top to down if it was compiled?

Actually, it's from the smallest address to the biggest address.

You only called readline() once in your main(). How is your input file structured? Do you only want to read the first line of the input file?

Same for your stopwords.txt. You only call readline() once. Does that mean you only want to read the first line of that .txt file?

He is just one of those finn jewish super autists

>why are you looping over all of the argv but only using 1 file

I'm not, it just checks to make sure the first argument is a valid .txt file, otherwise it returns a usage error and exits.

>why are you converting lineStops and line to str?
are they not already strings?

Just to be safe, I don't want anything fucky with numbers in the text.

>You only called readline() once in your main(). How is your input file structured? Do you only want to read the first line of the input file?
>Same for your stopwords.txt. You only call readline() once. Does that mean you only want to read the first line of that .txt file?

This is just testing to make sure the stripping and stopword-remove functions work correctly. I only want to read one line of the original input .txt file, but I think I did forget to iterate over each line in the stopword.txt list.

$ cat restrict.c
void f(int *a, int *b, int *x) {
*a += *x;
*b += *x;
}


void fr(int *restrict a, int *restrict b, int *restrict x) {
*a += *x;
*b += *x;
}
$ clang -S -O3 restrict.c
$ cat restrict.s
.text
.def f;
.scl 2;
.type 32;
.endef
.globl f
.p2align 4, 0x90
f: # @f
# BB#0: # %entry
movl (%r8), %eax
addl %eax, (%rcx)
movl (%r8), %eax
addl %eax, (%rdx)
retq

.def fr;
.scl 2;
.type 32;
.endef
.globl fr
.p2align 4, 0x90
fr: # @fr
# BB#0: # %entry
movl (%r8), %eax
addl %eax, (%rcx)
addl %eax, (%rdx)
retq


So this is the power of restrict?

Brainlet here, how are you supposed to represent i, aka the square root of -1 in programming?

I want to to draw one of those mandelbrot memes.

>I'm not, it just checks to make sure the first argument is a valid .txt file, otherwise it returns a usage error and exits.
then you don't need a for loop.
just check that ".txt" in argv[0]
>Just to be safe, I don't want anything fucky with numbers in the text.
what?

>I think I did forget to iterate over each line in the stopword.txt list.

Fix this and it should work. A better way to compare is to make a list of all the stopwords from your stopwords.txt and then instead of using
if str(lineStops[i]) == str(line):
]/code]

Use
if lineStops[i] in listOfWords:
[/code[

Every imaginary number is a real number multiplied by i.

Yes.

Should Windows users be banned from /dpt/?