[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 321
Thread images: 36

File: 1490194809126.jpg (44KB, 560x560px) Image search: [Google]
1490194809126.jpg
44KB, 560x560px
What are you working on, /g/?

Old thread: >>59718594
>>
>>59725719
Kenshin

The character's name is Kaoru
>>
anime is not programming
>>
real thread, faggots
>>59725693
>>59725693
>>59725693
>>
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.
>>
>>59725785
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            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
>>
>>59724579
c fags will defend this
>>
>>59725912
Start from here
>>
>>59725785
Sorry

see >>59725812
>>
File: Screenshot.png (44KB, 478x484px) Image search: [Google]
Screenshot.png
44KB, 478x484px
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.
>>
>>59725719
Cirno from Touhou
>>
>>59725996
Have you tried a loop?
>>
>>59726018
Touhou isn't anime
>>
>>59726041
The char isn't from an anime, retard.
>>
>>59726058
Yet you answer to the question "What *anime* is this from?".
>>
>>59726037
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.
>>
>>59726077
Hint: you should read all the input first and then draw the board.
>>
File: screen3.png (548KB, 1920x1080px) Image search: [Google]
screen3.png
548KB, 1920x1080px
I'm trying to do some image processing in Common Lisp using SDL to load images and draw results.
>>
>>59725700
In Java how can I use methods in my main to add or alter a private arraylist in another class?
>>
File: 1489239202139.jpg (116KB, 363x429px) Image search: [Google]
1489239202139.jpg
116KB, 363x429px
First dubs/trips/quads tell me what kind of a quick programming task I will write in Pascal.
>>
>>59726316
You must implement addition/alteration methods in another class before.
>>
have any of you actually completed SICP?
>>
>>59726328
Solve the halting problem.
>>
>>59726359
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
>>
>>59726397
Nope.
>>
>>59726398
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?
>>
>>59726422
Clojure
>>
I want to major in CS and make a lot of money. Is this realistic?
>>
>>59726422
>compiles into byte code and has performance the same as, or at least close to, C?
Impossible.
>>
>>59726422
>byte code
>performance the same as, or at least close to, C
Uhh, pick one.
>>
>>59726443
Depends on your definition of "a lot"
>>
>>59726443
worst 4 years of your life
>>
>>59726397
>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.
>>
>>59726443
Not impossible, but don't expect easy money.
>>
>>59726453
>>59726456
Sorry, I meant just compiles into a binary and is not interpreted like python.
>>
>>59726491
C, then.
>>
>>59726499
see what?
>>
>>59726491
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.
>>
>>59726507
Just C.
It's a language that compiles to a binary and has performance close to C.
>>
>>59726491
Common Lisp
>>
>>59726499
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.
>>
>>59726472
Why's that?
>>59726463
$150k I guess? Maybe more in late career
>>59726484
What do you do? Is there any "easier" money? I'm pretty interested in computers/programming however broad that may be.
>>
>>59726531
(((((((((((too many parentheses)))))))))))
>>
How much time and effort would go into building a rudimentary 3D engine?
Like, super super basic. Quake levels of basic.
>>
>>59726579
Carmack is a genius, and I don't know how does one reach his levels of effortfulness.
>>
>>59726602
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?
>>
>>59726579
You can do it in a dozen weekends if you use OpenGL.
>>
>>59726621
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.
>>
>>59726579
>>59726618
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.

>>59726652
Game Engine Architecture
OpenGL Superbible if you want to use OpenGL
>>
>>59726551
> 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.
>>
>>59726662
>Game Engine Architecture
By Jason Gregory?
>>
>>59726683
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".
>>
File: 1490469282268.png (175KB, 581x630px) Image search: [Google]
1490469282268.png
175KB, 581x630px
>>59726708
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
>>
>>59726551
>I am shit at C
>Therefore everybody else is
Nice projecting there.
>>
>>59726652
>>59726662
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
>>
>>59726763
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()
>>
>>59726775
Occasionally.
>>
>>59726842
If you don't use it at every available opportunity then you might as well not use C.
>>
Er det verdt å lære Idris?
>>
>>59726842
>>59726858
Much less talk about how good or bad other people are at it.
>>
>>59726858
It's usually something I chuck on functions after I've written them.
A lot of functions make sense to have aliased arguments, though.
>>
>>59726776
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()
>>
>>59725948
>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
>>
>>59726551
>spent a day writing and debugging a 50 line C program
>>
>>59726928

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.
>>
>>59726858
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.
>>
>>59726985
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.
>>
>>59726776
    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.
>>
>>59727015

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.
>>
>>59726579
https://www.youtube.com/watch?v=HQYsFshbkYw have this mate
>>
>>59727081
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?
>>
>>59727001
>>59726858
>>59726775
What exactly does restrict even do?
>>
>>59727118
> 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?
>>
>>59727135
It has to do with aliasing. Just google it.
>>
>>59727135
Declares that accesses through the pointer will be non-aliased, which enables some optimizations that nearly every other language cannot perform.
>>
>>59727135
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.
>>
>>59727120
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.
>>
>>59726776
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.
>>
>>59727118
>why is he coding in MS DOS
wtf seriously? why are you NOT programming in msdos? what are you even doing here on /g/?
>>
>>59727183
Would it be top to down if it was compiled?
>>
>>59727215
Actually, it's from the smallest address to the biggest address.
>>
>>59727077
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?
>>
>>59727118
He is just one of those finn jewish super autists
>>
>>59727190

>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.

>>59727268
>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.
>>
>>59727366
>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?
>>
>>59727366
>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[
>>
>>59727406
Every imaginary number is a real number multiplied by i.
>>
>>59727405
Yes.
>>
Should Windows users be banned from /dpt/?
>>
>>59725996
Just wondering are you new to programming or have you learnt some other languages?
>>
>>59726664
I think it's about learning C properly. And doing that is very hard with C.
>>
>>59727406
In Lisp, this is just
(sqrt -1)
>>
>>59727420

Yeah true, that way I don't have to iterate through both the input file and the stopwords file a billion fucking times for everything.
>>
>>59726138

>emacs
gross.
>>
>>59727635
And here is how you strip punctuation without going through that god awful ugly looking chunk of code

import string
lineSplit[i] = lineSplit[i].translate(str.maketrans('','',string.punctuation))
>>
>>59725700
that picture is really cute
>>
File: 1437020583592.jpg (106KB, 500x500px) Image search: [Google]
1437020583592.jpg
106KB, 500x500px
>>59727802
you're cute, anon
>>
Anyone used libsoundio? It looks pretty good.
>>
>>59727816
you have more?
>>
>tfw you feel like a programming hack who doesn't really understand programming at all and just use libraries to write a program but you can't write creative math solutions to programming problems instead you just follow general solution patterns in programming
>>
Why the fuck do I need to include 30 libraries to use opencv?
>>
>>59727816
i love cirno
>>
File: 1452365789104.png (118KB, 485x500px) Image search: [Google]
1452365789104.png
118KB, 485x500px
>>59727883
and to keep this /dpt/: D is a lovely programming language that I enjoy daily
>>
File: 1470014572821.jpg (62KB, 500x500px) Image search: [Google]
1470014572821.jpg
62KB, 500x500px
>>59727968
who doesn't?
>>
File: 1477523050689.jpg (108KB, 500x500px) Image search: [Google]
1477523050689.jpg
108KB, 500x500px
>>59727768
>
>>
File: 1491036071668.png (47KB, 234x263px) Image search: [Google]
1491036071668.png
47KB, 234x263px
>>59727969
>D
>lovely
>>
File: 1477603909050.jpg (48KB, 500x500px) Image search: [Google]
1477603909050.jpg
48KB, 500x500px
>>59727465
It would reduce the shitposting from /v/
>>
File: 1477605486765.png (159KB, 500x500px) Image search: [Google]
1477605486765.png
159KB, 500x500px
>>59728016
it's called a hobby, anon. no bully
>>
File: 1491035325171.jpg (134KB, 800x800px) Image search: [Google]
1491035325171.jpg
134KB, 800x800px
>>59728042
>having such a shit hobby as D programming
>>
File: 1439789195754.png (147KB, 1130x900px) Image search: [Google]
1439789195754.png
147KB, 1130x900px
aaaaaand I'm out. probably have more in some subdirectory.
>>
File: 1448759446583.jpg (55KB, 900x900px) Image search: [Google]
1448759446583.jpg
55KB, 900x900px
>>59728061
>implying cirno-chan doesn't love (the) D
>>
File: 1490484251912.jpg (36KB, 233x215px) Image search: [Google]
1490484251912.jpg
36KB, 233x215px
>>59728065
>>
File: 1490484353990.gif (456KB, 480x360px) Image search: [Google]
1490484353990.gif
456KB, 480x360px
>>59728089
Cirno is pure and would therefore use the Haskell programming language
>>
File: 1489795725732.jpg (167KB, 500x500px) Image search: [Google]
1489795725732.jpg
167KB, 500x500px
I SPOKE TOO SOON
>mfw anons can't program in C and D
>>
>>59728109
>Haskell
Trash.
>>
File: 1490484433313.gif (59KB, 366x421px) Image search: [Google]
1490484433313.gif
59KB, 366x421px
>>59728130
>>
>tfw too lazy and stupid to program a hockey game featuring cirno and the rest of the touhous
>>
File: 1491102148491.jpg (253KB, 690x787px) Image search: [Google]
1491102148491.jpg
253KB, 690x787px
>>59728160
>tfw forgot my picture too
>>
File: 1490484812786.jpg (43KB, 500x500px) Image search: [Google]
1490484812786.jpg
43KB, 500x500px
>>59728160
>>59728173
f o r c e d
>>
File: they knew.jpg (75KB, 473x590px) Image search: [Google]
they knew.jpg
75KB, 473x590px
>mfw reading something about higher-kinded types on the Rust mailing list from 2013
>>
are there any /g/ood programming IRCs?
>>
>>59728185
#lisp on freenode
>>
File: 1475610135886.jpg (801KB, 1171x1495px) Image search: [Google]
1475610135886.jpg
801KB, 1171x1495px
>>59728178
why bulli a retard, anon-kun?
>>
>>59728181
Rust is never going to get HKTs.

They're having this much trouble deciding on syntax, imagine what a nightmare the implementation will be.
>>
>>59728189
that clique is absolutely awful, fuck you
>>
File: 1490484324331.jpg (89KB, 400x400px) Image search: [Google]
1490484324331.jpg
89KB, 400x400px
>>59728181
>>59728203

>C++ will never be ok
>Rust will never be good
>D will never be better
>C will never be great
>Java will continue to exist
>>
Tried my hand at the summing all primes under 2 million problem. Tested it with numbers up to 1 million and it worked fine. But I think when the size of isPrime[] is too high, it crashes? Am I retarded or is Visual Studio fucking me?
#include<iostream>
using namespace std;
unsigned long long primes(int);
unsigned long long primes(int n) {
unsigned long long sum = 0;
bool isPrime[2000001];
for (int i = 2; i < n + 1; i++)
isPrime[i] = true;
int p = 2;
while (p < n) {
for (int i = 2 * p; i < n; i = i + p)
isPrime[i] = false;
p++;
while ((!isPrime[p]) && (p != n))
p++;
}
for (int i = 2; i < n; i++)
if (isPrime[i])
sum += i;
return sum;
}

int main() {
cout << primes(2000000) << endl;
cout << "Answer should be 142913828922" << endl;
return 0;
}
>>
>We're looking for someone with experience in functional languages like Scala/Clojure/F#
>You'll be working in Python/Go

F U C K
Y O U
>>
>>59728226
Rust is already good, especially if you compare it to C. Performance is just behind it and it gives you so many benefits that are obtuse to implement in C or results in poor design and future bugs if anything changes or not well written.
>>
>>59728280
You can learn Python in an evening
>>
Roll: #002
Temperature converter
This is a compendium of temperature conversion formulas and comparisons among eight different temperature scales, several of which have long been obsolete.

This seems almost too easy. Whats the catch?
>>
>>59728203
>>59728226
Fuck it, I should just make a first draft of my language with Ada-ish contracts (maybe in a refinement type framework) instead of full dependent types.

>>59728296
Rust is good but there's some really egregious omissions like higher kinded types.
>>
>>59728341
Why don't you try making it and figuring it yourself
>>
>>59728369
Because I'm cleaning my room first.
>>
>>59728357
no, use full dependent types
also it better be pure
>>
>>59728388
>2017
>cleaning your room
>>
How is error handling done in C? Like say I have a big project and say maybe I have some files, sockets, etc opened that should be closed/cleaned up but at some point in my code I run into an error that will effectively kill my program or corrupt things if I let it go.

How do I ensure everything is cleaned up without stuff like try-catch-finally, etc, etc?

Does Rust solve this issue?
>>
>>59728391
I will use full dependent types when I am confident about how I want them to interact with substructural types, and when I am knowledgeable enough to formalize the theory and prove it sound.
>>
>>59728337
I don't want to use Python or Go. I have experience in non-shit languages, let me use them.
>>
>>59728415
nv is that you?
>>
>>59728422
So do I but a man has got to do what a man has got to do to put money on the table so he can continue to buy his favorite anime figurines and whack off to. You know?
>>
>>59728434
his name is invoke, not nv
>>
>>59728273
You're a retard nigger. How do you expect the stack to fit 2 fucking megabytes? Put it on the heap, CIA nigger.
>>
>>59728434
No, but we seem to share similar interests and talk about language design sometimes.
>>
>>59728405
You model your functions that can 'error' like the standard library does. Any function that has the possibility of going south should return an int that says whether or not it was successful or if something went wrong and you simply unwind and free your resources as you head up your stack communicating the error or if possible you fix the error and continue.
>>
>>59728441
>You know?
No, I don't.

I'd rather stick with my current job using Scala than go to a Python/Go shop, at least Scala doesn't insult my intelligence.
>>
>>59728405
Rust has RAII, which handles clean up error or not.
>>
>>59728446

Terry? Is that you?
>>
Is it possible to convert an int array to an SDL_Texture or SDL_Surface?

int test_tile[] = { 1's and 0's (4chan thinks it's spam) }; 


I want to include a couple pre-compiled images in my game, and I was wondering if it was possible to convert (easily). I tried various searches on google but couldn't pull up anything.

Thanks
>>
>>59728357
What really gets me about Rust is the fucking naming scheme of some stuff like try! and println!. Why the fuck was the ! required, that's an extra two key strokes.
>>
>>59728446
Thanks, didn't know about stack or heap, will have to do some reading.
>>
>>59728482
Not to break Rust containment but noticed NoStarchPress has the Rust book coming out this year in October. Hopefully all the info is in there and not 'hidden', currently you need to lurk the mailing list for months in order to get at Rust features they don't release for some stupid reason.

>>59728357
Have you read this? If not your language is probably DOA full of logic errors http://www.cs.cmu.edu/~rwh/pfpl.html
>>
>>59728536
Yes.

https://wiki.libsdl.org/SDL_CreateTexture
https://wiki.libsdl.org/SDL_UpdateTexture
https://wiki.libsdl.org/SDL_RenderCopy
>>
>>59728537
! invokes enthusiasm which you need when you are programming in Rust.
>>
>>59728446
How much data can you honestly allocate on the stack now a days anyway?
>>
>>59728538
>>>59728446 (You)
You can use http://en.cppreference.com/w/cpp/utility/bitset and it should fit.
>>
Rate my Scheme pls

(define (f a b c)
(cond ((> a b) (+ (square a)
(cond ((> b c) (square b))
(else (square c)))))
(else (+ (square b)
(cond ((> a c) (square a))
(else (square c)))))))
>>
>>59728537
It distinguishes macro calls from function calls. try! is a macro because it has to be able to early return, and println! is a macro to handle a variable number of arguments.

>>59728542
I haven't read that book in particular but I've studied a lot of type theory and related subjects.
>>
>>59728393
Well Im an adult now. I have to clean up after myself at least once a month.
>>
>>59728578
unreadable/10
>>
>>59728592
I just use my GBP to trade for cleaning services
>>
>>59728567
VS defaults to 1MB.
>>
var attackButton = document.getElementById("Attack"); 
- attackButton.addEventListener("click", function(){
2
2 die = probability(3);
- if(die != 6){
3 monster.hp -= hero.power;
3 console.log(monster.hp);
3 }
- if(monster.hp < 1){
3 alert("You defeated " + monster.name);
3 document.clear();
3 buttons.innerHTML = "";
3
3 monsterAttack(monster);
3 });


currently working on a game using javascript this keeps giving me an error.

SyntaxError: expected expression, got ')'


at the end of adding the eventlistener, and I have no idea why. I was working up until today.
>>
>>59728585
Highly, highly recommended if your designing a new language, there's a free draft on that site you def want rigorous formalism when dropping a new typed language
>>
The call stack was a mistake.
>>
>>59728604
>GBP
Pound sterling or good boy points?

They're probably going to reach parity soon anyway.
>>
>>59728567
You can set it at compile time
>>
>>59728615
Add an extra } on the last line.

You'll have '}}});' instead of '});'. You forgot to close your last if statement: if (monster.hp < 1).
>>
>>59725996
Vector
>>
>>59728566
It honestly invokes rage for me

>>59728585
Really? They couldn't just name their macros the same as functions? Also does this mean Rust has no way to handle variable arguments in _functions_ and requires you to write some macro?
>>
>>59728635
whoops, I meant }});
>>
>>59727768
kys
>>
File: 1489098255589.jpg (145KB, 670x424px) Image search: [Google]
1489098255589.jpg
145KB, 670x424px
Taught myself C# to fuck around in Unity and Visual Studio. I like object based coding.

What's a good second language to learn? Was thinking of C++.
>>
>>59728652
>>59728635

.... wowthisisembarassing.png
>>
>>59728627
Believe me, I'm all about rigorous formalism. I did a quick scan and I've seen pretty much everything in there already.
>>
>>59728667
Happens to the best of us. If you're using Atom, vim, emacs, etc. you should use a linter because it will catch these errors for you.
>>
-- both --
type Both = forall a b c. (a -> b -> c) -> a -> b -> c
and :: Both
and f x y = f x y
-- both --

-- either --
type Either = forall a b. (a -> b) -> (a -> b) -> a -> b

left, right :: Either
left f g x = f x
right f g x = g x
-- either --

-- bool --
type Bool = forall a. a -> a -> a

true, false :: Bool
true x y = x
false x y = y
-- bool --

-- nat --
type Nat = forall a. (a -> a) -> a -> a

zero :: Nat
succ :: Nat -> Nat

zero f x = x
succ n f x = f (n f x)
-- nat --
>>
>>59728645
>They couldn't just name their macros the same as functions?
I don't know why you'd want this, though. It's definitely good to distinguish them.

>Also does this mean Rust has no way to handle variable arguments in _functions_ and requires you to write some macro?
It doesn't, but honestly it's not a useful feature outside of formatted I/O and macros already handle that without adding extra complexity to the calling convention. The only clean way to do proper varargs without macros is with dependent types, really. C's varargs API is an abomination.
>>
>>59728604
I don't collect good boy points.
>>
>>59728664
C++ is the best language.
>>
>>59728634
Is there a maximum?

>>59728612
1MB seems pretty little. I was always encouraged to use the stack for allocation as needed, but with 1MB it seems like anything outside of a toy program will hit it on the head if I try to allocate the majority of my stuff there.
>>
>>59728721
By the way, the way you'd do it with C++'s variadic templates is basically identical to how it works with Rust's macros, though I believe the macros actually parse the format string (which needs to be a literal) to determine the parameters.
>>
>>59728745
What are you allocating that's more than 1MB? Maybe you should rethink your programs. In most programs the average struct isn't more than 1KB.
>>
anime and programming do not go together
>>
>>59728710

Is this Prolog you fucking space nigger?
>>
>>59728757
and 1KB is A LOT of memory. That's 128 std::uint64_ts
>>
When Making a menu for a program is it better to use a loop that returns you to the menu unless you decide to exit, or to use a function that displays the menu when called?

C#
>>
>>59728757
Well consider an environment where I'm reading in data from a file that's well defined, shouldn't I take advantage of that and allocate via stack ahead of time and load into it? Then the problem becomes if I need to load more than 1MB of data form a file which isn't hard to hit desu.
>>
>>59728779

while (running) {
display_menu();
wait_for_input();
do_thing();
}
>>
>>59728273
Allocate it on the heap or use packing with bitwise operators so that 8 consecutive elements are stored in a single byte.
>>
>>59728761
Haskell with RankNTypes
>>
>>59728785
Then you'll be a good developer and use something like ProtoBuffer which will allocate on the heap for you.
>>
>>59728801
>with RankNTypes
All your types are rank 1 and you don't need the extension (just leave the foralls out).
>>
>>59728801
>>59728813
Wait, never mind.

You could use Rank2Types instead, which doesn't break type inference.
>>
>>59728810
>heap
So I ignore the stack meme and go back to using the heap anytime I feel I could use all of my stack?
>>
>>59728836
I mean, you're already reading in a file over one megabyte from the filesystem. You've already given up on performance at that point.
>>
>>59728836
does your data have an upper bound in size?

if so just allocate a huge segment of memory on the heap and dish it out like a pretend stack as needed.
>>
>>59728594
I made it shorter:

(define (f a b c)
(cond ((> a b) (+ (square a) (square (max b c)))
(else (+ (square b) (square (max a c)))))))
>>
>>59728829
pretty sure the GHC extension Rank2Types just enables RankN
>>
C++
std::find()
or
std::search()
?
>>
>>59728883
I hope not, because type inference with rank 2 polymorphism is still decidable (though it takes doubly exponential time or something like that); it's undecidable when higher rank is possible.
>>
>>59728889

Do you want to 'find' one element or many?

One item: find
Multiple: search
>>
>>59728794
This did nothing but confuse me
I'm sorry Im stupid.

So I build a menu function
I don't know how the wait for input function would work. I was going to have the menu call functions depending on what the uses chooses. then every function the menu calls leads back to the main menu
>>
>>59728918
Is this a GUI? A command-line app? A game (you just lost xDDD)?
>>
>>59728864
Much better.
>>
>>59728930
Post your code
>>
File: r2.png (12KB, 264x291px) Image search: [Google]
r2.png
12KB, 264x291px
>>59728900
type inference eliminates most useful features
>>
>>59728950
Why are you still using Haskell?
>>
>>59728900
>>59728950
decidable, i mean

>>59728958
What's the alternative?
Please tell me you aren't seriously using Idris
>>
>>59728958
>59725700
What's a better language?
>>
>>59728964
You're doing things that require tons of extensions in Haskell and you don't care about type inference. Why would you still use Haskell over e.g. Idris?

>>59728967
Anything dependently typed.
>>
>>59728628
And what do you propose?
>>
>>59728930
command line app.
>>
>>59728970
So... my choice is Idris
>>
>>59728970
Idris has a ton of flaws like performance, convenience, documentation, usability
lack of ANY type inference (boo hoo just because you can't infer everything doesn't mean infer nothing)
>>
>>59728916
need to find a specific sequence of bytes in rom.
I guess std::search() is the way to go then, thanks.
>>
>>59728770
>std::
>>
>>59728999
Coq, Agda, Lean, cubical, the list goes on.

>>59729001
>Idris has a ton of flaws like performance, convenience, documentation, usability
Says the guy playing with Church encoding.

>lack of ANY type inference (boo hoo just because you can't infer everything doesn't mean infer nothing)
In practice, you only need to annotate at the top level. You should be doing this anyways. Idris is designed so that you write the type first and fill it out (possibly interacting with the proof assistant) to define the function.
>>
>>59729037
>Says the guy playing with Church encoding.
What's wrong with Church encoding?
I could use regular data types if I liked
Those aren't the kind of issues I was complaining about.

>In practice, you only need to annotate at the top level. You should be doing this anyways.
I disagree
>>
>>59728990
Giving the programmer the control to provide the allocator that best fits their call graph. Most of the time it will probably just be a stack since that's your typical control flow, but the reality is that control flow isn't always like that.
>>
>>59729074
>What's wrong with Church encoding?
Nothing, I just don't see why you prefer those things over a much more powerful type system when you're playing around in abstract land.

>I disagree
Why? Types are specification and documentation.
>>
If I use Cargo to make a project in Rust does it mean my code automatically gets shown publicly to everyone in some central repo or do I have to explicitly do something to make my cargo project public?
>>
>>59729095
Because of convenience.
Not everything I write is going to end up in a public library.
Especially if it's a complicated signature.

Still all the other problems
And the REPL is awful too
>>
>>59729113
You have to manually publish it to crates.io, and it's a fairly involved process so don't worry about doing it accidentally. If you really want to prevent any accidents you can write "publish = false" under [package] in your Cargo.toml.
>>
>>59729036
yeah i include <cstdint> you fuckboi.
>>
working on a guide for ricing, but no one provides feedback :(
>>
File: 1491166491575.jpg (79KB, 600x847px) Image search: [Google]
1491166491575.jpg
79KB, 600x847px
>>59729182
Enjoy your std's I guess.
Meanwhile I'll be here including stdio.h and NOT iostream in my C++ programs. Baka.
>>
>>59729182
don't feed the trolls, please
>>
File: 1491116308248.jpg (220KB, 827x1169px) Image search: [Google]
1491116308248.jpg
220KB, 827x1169px
I think I'm going to make a small game in D with SDL.

>>59729230
C U T E
>>
Actually, I think I will implement dependent types to a certain extent. Specifically, I will allow types to depend on integers. This covers a ton of useful cases by itself, such as tagged unions and arrays with pointer arithmetic. I don't need to worry about dependent and substructural types interacting in full, as integers are always free to be copied and dropped (depending on values of substructural type is a bit of a problem).
>>
>>59729230
>>59729264
>>>/c/
>>
I'm not sure if I need a "design pattern" or an "idiom" or what... I can't even figure out what to Google.

I have lots and lots of objects (OOP). They have lots of components. For example, a car has wheel components and an engine component and so on, a plane has wings and an engine, etc...

For efficiency, I want to have arrays of pointers to these objects that group them by functionality. So all cars go into the "things with wheels" group and the "things with an engine" group. This saves me from having to query every object on every frame/tick/whatever.

But things are constantly being created and destroyed. So every car that gets destroyed needs to immediately be removed from all the groups to which it was added. Obviously, I can just manually manage adding and removing every object from every group, but that is extremely error prone. So what's the more automated way to handle this kind of thing?
>>
>>59729285
Wow, I didn't know there was a whole subchan for buffer overflows!
>>
>>59729440
I would encourage you to try to have single ownership. So you would have 3 groups:
1. Wheels only
2. Engine only
3. Both
When iterating everything with wheels, you iterate 1 and 3. When iterating everything with an engine, you iterate 2 and 3.
>>
>>59729440
In the magic world of OOP done proper the car being destroyed would also destroy all the objects that are part of it
>>
                                                                                                                   Just doing some ML(:
>>
I made a "Favicon" how do I install it into my HTML now?
>>
>>59728561
yes, but from an int array? what you linked, i've already seen that.
>>
>>59729503
Yea, that may work for me in some places, but probably not all places. There are a LOT of groups involved. A more realistic list is something like this:

- Things that need to be drawn
- Things that perform collision test
- Things that have hitpoints
- Things that do damage on collision
- Things that move
- Things that animate
- ...

So there's not really any way to avoid overlap.

>>59729506
Nah, that's the opposite of my problem. The "owner" isn't being destroyed, it's child is, and the owner needs to know so that it doesn't cause an access violation by trying to do something with an object that no longer exists.
>>
>>59729528
Usually you just name it correctly (favicon.ico) and put it in your root html folder. Some hosts may require you to add some html like:

<link rel=”shortcut icon” type=”image/x-icon” href=”/favicon.ico”>


Also google it
>>
>>59729440
>>59729589
std::weak_ptr
>>
>>59729612
fugg, I named it with .png will that not work?
>>
>>59729440
mixins?
>>
>>59729538
Yes. I do that in an emulator I wrote which is on Github. I would link it here but fuck that lol
>>
>learning new language
>flipping through stuff
>see a section on style guidelines

I really hate it when a language tries to tell you how to style your code on a global stance.
>>
>>59729652
void display_draw(struct display* display,
uint32_t pixels[SCREEN_WIDTH * SCREEN_HEIGHT]) {
SDL_UpdateTexture(display->texture, NULL, pixels,
SCREEN_WIDTH * sizeof(uint32_t));
SDL_RenderCopy(display->renderer, display->texture, NULL, NULL);
SDL_RenderPresent(display->renderer);
}


Here is my code for doing that
>>
>>59729589
The same approach scales indefinitely. Consider a few things:
- Some groups may not make sense. For example, when will an object do damage on collision but not perform a collision test? When would an object be animated but invisible?
- Some groups could be combined. I'm sure you could put "does damage on collision" under a much more general group that just says "reacts to collision" and implement the different reactions as overrides of a virtual method (or have a field that holds a first class function, or some other equivalent).
- You don't need to make every group combination. If you don't have an object type that only moves and draws and does nothing else, you don't need that group.

The alternative is dealing with shared ownership, which can be error prone and additionally inefficient if you want to automate it.
>>
>>59729639
Most servers allow PNG so it should be fine. And pretty much all browsers support it now. Just try it and see if it works...
>>
>>59729693
thanks
>>
>>59729440
Games have made use of this a lot. What you're describing is an entity component system.

As for efficiency it doesn't make much sense to have large arrays of pointers.
It makes more sense to allocate the components as sets and have the entity be a more abstract concept like an index into these arrays. You'd have a bit field indicating which components are active for the object.

There's plenty of ways to save space here but usually it's not a major concern.

For performance reasons you'd like to iterate all the wheels because that provides the best cache coherency for component systems. If they have any messaging to be passed to other systems (wheels might get their turn speed form the car axel) you just reference them through the index (or equivalent).
>things are constantly being created and destroyed
See here's where the aos nature of this system really helps you. Deletion is just setting the corresponding bit in the bit field. Creation is the same (except there's an initialisation step too). You never have to worry about communicating all this information in clever ways because it's all available in the bit field.

The trouble you might run into is entity-entity references. You wish to ensure that an entity doesn't reference the wrong object most likely (say you have a car following another, if the followed car is deleted you wouldn't want the following car to accidentally follow a random newly created car). This is easily solved by having a generation ID. Instead of just storing an index (or equivalent) to the followed vehicle with the following vehicle you store the index and the generation ID. The generation ID is a value that's incremented every time you have a new creation.

There's tons written on this already. Look into it. Data oriented design is the recent take on this.
>>
>>59729789
This is how I initialized the texture:
display->texture =
SDL_CreateTexture(display->renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STATIC, SCREEN_WIDTH, SCREEN_HEIGHT);
>>
>>59729589
What language are you working on?
>>
>>59729800
>You'd have a bit field indicating which components are active for the object.
NO! Don't do this. It results in incredible fragmentation and thus cache thrashing and wasted iterations that do nothing but incur the overhead of a branch to check the bitmask. Instead of refactoring an array of many types of structure into a monolithic structure of arrays, have many specialized structures of arrays that aren't going to be wasteful.

Trying to put every game object under the same umbrella is going to hurt you regardless of whether you're doing it with OOP or ECS.
>>
>>59729837
It's called Jai
>>
>>59729623
Wow this is really close. But if I'm reading correctly, the idea with a weak_ptr is that the object is automatically deleted when no "strong" pointers are left pointing to it. So it's kind of like a reference count.

What I need is similar but sort of reversed. The object itself decides when it's time to die (e.g. it's hitpoints reach zero). I need everyone who holds a pointer to that object to be immediately notified so that they can remove it from their array.
>>
Is there a software book that collects short principles? Stuff like "never store what can be easily recalculated" and "functions should do one thing really well". Looking for something short, language agnostic, and preferably held in high regard.
>>
>>59729912
What do you have against >>59729503 & >>59729694?
>>
File: Helppls.png (48KB, 676x340px) Image search: [Google]
Helppls.png
48KB, 676x340px
I'm not getting any errors or warnings. I'm not sure what I'm doing wrong here, i'm probably over looking something.

Everything works fine until the program is supposed to give answers.
Pic related is result.

pastebin to see the code:
https://pastebin.com/mmr92fKy

Also yes I know I have my 1's and 0's backwards. I fixed it.
>>
>>59729948
Your fractions are using integer division. A lot of those will evaluate to zero. Write the numerator with a decimal point, e.g. 5.0/9 instead of 5/9.
>>
>>59729800
>>59729885
You guys are talking about the component system, which I already have working. Yes, it can be very inefficient if you're not careful. I came up with a pretty slick way to allocate entities that doesn't mangle memory/cache much.

But your example with the cars is exactly the problem. I'm having a hard time seeing how using IDs solves it, though. If car 123 has stored ID 456 as "car_Im_following" and suddenly car 456 is destroyed, I want an automated way to tell car 123 that 456 is now invalid.
>>
>>59729986
tyvm
>>
>>59729948
I don't use C# but is C# dynamically typed? Or uses ducktyping. You are mixing integr and double division.
>>
>>59729938
There's just too much overlap. I'd have an NxN matrix of groups I'd have to create. Yeah, there's a small amount of redundancy that would let me throw out maybe 5% of the groups. But it would still be a nightmare... I'd have groups like:

things_that_move_and_collide_and_do_damage_and_animate_and_have_hitpoints
things_that_move_and_collide_and_do_damage_and_have_hitpoints
things_that_move_and_collide_and_do_damage_and_animate_and_have_hitpoints_and_are_visible
...

Too cumbersome.
>>
>>59729912
You can do that with weak/shared_ptr. Pass the object a reference to its own shared_ptr (or the list where its shared_ptr is located) so it can delete itself. Then when iterating over the other lists, simply discard any expired weak_ptrs.
>>
>>59730015
I think you're overestimating the amount of groups you will need. In any case I don't see why it's a problem, you add groups as you need them. You also don't need such verbose names. Write "NPC" instead of "thing that moves, collides, does damage, animates, has hitpoints, has AI, etc.".
>>
>>59730073
Very clever. Thanks
>>
>>59729885
Anon I was using an array as the simple example for the explanation.
But if you have many unique components bucketing all entities without the bit field you'd have many small buckets. Without knowing the nature of the entities we're dealing with here I don't think the assumption of many like objects in a component system like this makes sense. It's built to handle diverse objects. But it may be the case that that's the right tradeoff. We don't know.

The fragmentation can be dealt with obviously. If you iterate from both ends operating from the front until you find a gap, then operate from the back and move all your result to the free entity slot you quickly compact the arrays.

This would start being an expensive system when you have a lot of deletions per frame. Maybe that's the case, but it takes a very large amount of deletions to make this a problem.
>>59729990
The process for accessing one entity from another would be that you first check if the slot you're referencing is free or not. If it isn't free we check what the generation ID of that slot is.
If it's not the same generation ID we had saved when we know that the entity we were following was deleted.

There's a few limitations. We can't reliably grab information from the deleted entity (unreliably, if we found an empty slot we could check the generation ID and see if we have a dead version of the entity available). So if you had a mortuary it would have to have saved the information of the person it's tracking. (though it makes more sense to have objects tell the mortuary that they died instead of having the mortuary check everyone).
Nothing is perfect sadly. Not when you care about performance.
>>
>>59730136
Oh and for entity to entity references it gets messy when you move them around obviously. You need a double indirection for that. Again, depends on the situation what's worth.
>>
>>59730015
>>59730083
Also I don't get what the other guy was saying about generations. If you follow my scheme, you can always eliminate fragmentation by swapping the last object with the object getting deleted. All you need to do is have a double lookup table for IDs so that the same ID can refer to different locations, to be redirected if the object is destroyed or swapped. You can define "location greater than number of objects" to mean "no object with that ID". You could also make the objects reference each other and have one notify the other if it is deleted. Each technique has different pros and cons.

>>59730136
>The fragmentation can be dealt with obviously. If you iterate from both ends operating from the front until you find a gap, then operate from the back and move all your result to the free entity slot you quickly compact the arrays.
Sure, you can keep a contiguous range of locations occupied by entities, but the components are going to be all over the place. In order to iterate all the entities with a certain component, you need to iterate every entity and check if the bitmask contains that component. That's really inefficient.

With separate buckets, you can guarantee that certain components will or will not be present, which means you reduce your iterations (i.e. cache misses) and checks (i.e. branch mispredictions). Obviously you can mix both techniques if you really have diverse objects. I guarantee you can still make massive gains by dividing them into archetypes and limiting the components that are "dynamically present".
>>
>change parameter orders in one function
>gcc takes five minutes to print all the errors
maybe this wasn't such a good idea after all.
>>
>>59729456
It overflows my buffer, if you get what I mean.
>>
>>59730270
>mix the techniques
Good. That was what I was trying to convey. Glad we agree.
As for how valid the defragmentation is. Yeah the basic explanation I gave isn't sufficient for a good defragmentation.
And I don't think iterating the bitmask is that big a problem. With how little work is done and how obvious the prefetching gets it really doesn't sound like a big deal. But I haven't measured.
>>
>>59730328
Templates?
>>
>>59730328
rewrite it in Haskell
>>
>>59730353
no just a plain constructor with multiple overloads, but it's used all over the place. the parameter order is mildly awkward, but reordering them apparently makes the call ambiguous.
>>
>>59730337
It's not additionally iterating through the bitmasks that's the problem, it's the fact that if you have the bitmask, you have fragmentation of at least one component type. If you only need to iterate through entities with that component, you still need to iterate through every entity ID and load memory throughout the whole vector in the worst case.

If the component type is uncommon enough and you don't need it more than once or twice, it wouldn't be as much of a problem I guess because you're probably going to go to main memory even less than with contiguous accesses with prefetch. Though it will always be more efficient to make a new group that is guaranteed to have that component, so it's really a tradeoff between getting more performance and writing more code at the end of the day. The great thing about this approach is that it's highly tweakable so you can always mess around and see what works empirically.

It's my opinion that by default you should split into a new group. Only sacrifice performance by bitmasking the component in a group if you feel it is worth the code savings. Hopefully you have things programmed so that it's not much work to split a group later to remove the uncertainty if you want some more performance down the line.
>>
>>59730392
Trash.
>>
>>59730404
not an argument
>>
>>59730410
anime website
>>
>>59730337
>>59730403
Also, depending on your language, this whole process could be completely automated with metaprogramming. It's very mechanical once you've decided your groups.
>>
Okay I'm all done.

https://pastebin.com/xRXp5y9s

How can I be more efficient with this program?
It already works, just want to be a better programmer.
>>
File: 1490485186177.png (3KB, 99x99px) Image search: [Google]
1490485186177.png
3KB, 99x99px
>>59730415
damn you win
>>
>>59730467
:^)
>>
>>59730435
You can't. The problem is just busywork trash.
>>
>>59730435
You have a lot of repetition. I would factor the conversion into a single function that takes the input unit & value, the output unit, and does the conversion and prints. You can associate a name to each unit and have a single print that just substitutes the appropriate names in.
>>
>>59730536
I figured I could do something like that, but I wanted to show all the conversions at once.
>>
>>59730558
Call the function multiple times.
>>
>>59730563
Then it runs into the same repetition problem.
>>
>>59730586
But it's more maintanable, if you want to make a change you just make the change in the function instead of changing all of your multiple lines

Things like that make mantaining a huge ass codebase less suicide inducing
>>
>>59730586
It doesn't. You call it multiple times, just with different output units, once you get your input unit & value. You only write this piece of code once. I suppose could go full autism and loop over the full list of units and write the function call only once (in which case you could just write it inline and get rid of the function).

Of course, instead of hardcoding NxN conversions, you convert from the input unit to a common unit and then from that to your output unit. Then you only need 2N conversions (N units to/from common unit), less 2 if your common unit is one of the input/output units.
>>
I spent like the last 3h ricing my emacs instead of learning Rust.
>>
File: 1491263491080-edit.jpg (92KB, 560x560px) Image search: [Google]
1491263491080-edit.jpg
92KB, 560x560px
>>
File: 1490484251919.jpg (614KB, 1280x960px) Image search: [Google]
1490484251919.jpg
614KB, 1280x960px
>>59730891
cirNO
>>
>>59730891
Haha, you baka
>>
File: 2dd.jpg (37KB, 600x600px) Image search: [Google]
2dd.jpg
37KB, 600x600px
How do I get rid of the code duplication?

if (A && B && C) {
if (D && E) {
functionA()
} else if (F) {
if (G) {
functionB()
} else {
functionC()
}
} else {
functionD()
}
} else {
functionA()
}


How can I rewrite this so I don't type functionA() twice?
>>
File: carl.jpg (321KB, 903x682px) Image search: [Google]
carl.jpg
321KB, 903x682px
>>59731024
are you rusing me?
>>
File: 20170404024121.jpg (469KB, 1280x720px) Image search: [Google]
20170404024121.jpg
469KB, 1280x720px
>>59731042

no
>>
>>59731024
first priority should be flattening your structure into a single if ... else if ... else if ... else if .... else statement.
>>
>>59731024
I think
if (A && B && C && !(D && E)) {
if (F) {
if (G) {
functionB();
} else {
functionC();
}
} else {
functionD();
}
} else {
functionA();
}

is equivalent, but I can't be bothered proving that right now.
>>
this is ridiculous
>>
>>59731176
Wow, you really wanted to push that 310, didn't you?
>>
File: 1490484391640.png (343KB, 900x1511px) Image search: [Google]
1490484391640.png
343KB, 900x1511px
new
>>59731178

>>59731181
desperately
>>
>>59728864
(define (f a b c)
(+ (square a) (square (max (if (> a b) b a) c)))
>>
>>59726422
> Compiles into byte code
Well, if you allow machine code?
Common Lisp with SBCL sometimes beats C. It's pretty fucking fast.

Java is usually at around 70% of C speed.
C# is usually close to Java's speed.
>>
>>59726422
LuaJIT, Java, SBCL.
>>
>>59726878
>Scandyfags
>>
>>59726878
Idris en bæsj
>>
>>59733533
>learning Scandy through memery
Idris a shit?
>>
>>59727118
For a finn his voice is overflowing with emotion and enthusiasm.
>>
>>59733925
Literally, poop, but yes.
It's the childish word for shit.
The word for shit would be dritt.
The word skitt, which is pronounced "shit" means dirt, as in dirty, not soil.
Thread posts: 321
Thread images: 36


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.