/dpt/ - Daily Programming Thread

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

Other urls found in this thread:

wikipedia.org
wikipedia.org:80
docs.ruby-lang.org/en/2.0.0/Net/HTTP.html
en.wikipedia.org/wiki/Multi-armed_bandit
igoro.com/archive/fast-and-slow-if-statements-branch-prediction-in-modern-processors/
twitter.com/NSFWRedditVideo

This one has double numbers and was a post earlier. I usually post in /wdg/ but I think they're sick of me and want me to drop what I have and fuck off.

Almost finished my web framework, it runs JavaScript templating libraries in c# so all you have to do is pass the constructor a filename and an anonymous object for the templating libraries input object. I told myself it's done when I can no longer see any bugs since at this stage most bugs require obscure test conditions which I don't have a hope of finding.

Currently faster than react.net and asp.net mvc, implements every JavaScript templating library that's popular here besides razor (I personally don't like it) and vue (hard dependency on node.js).

first for javascript

Why was the other thread deleted?

learning scheme; going through sicp

(define integrate
(lambda (f a b step)
(integral-helper f a b step)))

(define integral-helper
(lambda (f n b step)
(if (or (< b n) (= b n))
0
(+ (* (f n) step) (integral-helper f (+ n step) b step)))))

(integrate (lambda (x) (* x x)) 0 4 0.0001)

it was a second too late

Today my programming professor told me multiple if statements were faster and take less processing power than using if-else if-else etc. I'm almost certain he's wrong for seemingly obvious reasons, but I need reassurance.

We are making a web browser! You are welcome to join.
Channel on Rizon: #Sup Forumsnetrunner

isn't this code beautiful?

No he's right.
That's why he's the professor and you're the student.

(no .)

>those lisp brackets
Where are the elegant braces and semicolons?

Are pathfinding algorithms "hard" to implement, or am I just retarded?

is it true that lisp implementations have no real operators?

How the fuck do you add 2 numbers and implement the (+ function?

They shouldn't be.

if-else if-else is probably a nanosecond faster; does it really matter?

I'd like to help but it seems everything "Sup Forums" makes turns into some reddit clusterfuck after a few months, can I get reassurance that no redditors are working or will be allowed to work on the project?

Do you guys have even a single line of code written yet?

>not megumeme
dropped

for i in range(i, 10000000):
print ( "if (i == %d) {" % i )
print ( "printf(\"\%d\", %d )" % i )
print ( " } " )
compile and run, compare to else if equivalent, post results im interested

To respond to from yesterday:

Sure, that's a great idea, but the intangibles usually don't end up having as much of an impact to people as money in my experience. I'm not trying to say it shouldn't happen, I'm just trying to explain the occurrence of why people aren't joining unions.

probably depends on the language and compiler, but any good compiler will optimize away any difference.

I like both desu. Either one can get a little boring after a while. I come from C/C++ so lisp to me is still completely new and exciting.

enjoy blowing out your instruction cache

My code is always perfect so he pulls comments like that all the time on me to take off points, I'm not sure why, maybe he's jealous

if (...)
(do something)
elif (...)
(do something)
else
(bla bla bla)

So in a situation like this, does it make sense to put the most common condition up at the top ('if'), the second most common in second place ('elif') and the least common at the end ('else') to save the machine some work? I'm asking about Python specifically but any language in general as well. Does it make a difference? Does the compiler (in compiled languages, of course) know how to optimize this? Are there any tools that check for this kind of thing?

Should I bother with blogging some project to build up my portfolio or it is a meme?

LISP has primitive operators.

(+ 2 3)
>5

(+ 1 2 3 4 5)
>15

Depends. if-else if-else should be faster at best, the same at worst, at least on modern compilers.

If you're comparing some variable between if statements, and it's sensible to prove it hasn't changed (e.g. it's not a reference), the code output will probably end up being the same.

What do you mean multiple if statements as being equivalent to multiple if else statements?

Compilers optimize for instruction cache too

Yeah, if the first statement evaluates to true, it won't evaluate the rest of the conditionals


Worked for me

yes. The computer goes through if/elif/else in order and stops when one of the conditions is met. Hence the more probable conditions should go first

The compiler cant optimize the order. For example, imagine:

if ( launch_the_missiles() ) { // launch_the_missles() returns true if successful
print("They ded");
} elif ( getChar() == 'y') {
retry();
} else {
print (" we ded");
} the order of the if statements is very important and its impossible to change the order without changing the program semantics.

Give it to me straight, /dpt/. Should I use C++ or Rust for new games?

C

javascript

in some rare cases, the evaluation time might vary greatly. for example, if one involves reading from file or makign an http call. in those cases putting the less common but quicker evaluation first would make more sense

No

No

No, it actually depends. For example, if the most common is a costly function call, putting it first will result in a slowdown than putting it last, where it doesn't need to be checked. This may already be obvious to you, though. And in a if..and... statement, you obviously want the least costly to come first.

Definitely C.

Depends on the game. Indie games are quite popular so Unity/C# is an option.

just use short circuit evaluation dummy

C++, unless you want to be a game engine dev too. Rust's game engines just realistically aren't ready for use yet.

Feels good man

rust is for systems programming, not application programming

I'm in love with sicp. Help me Sup Forums

(define (sqrt x)
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-iter (improve guess x) x)))
(define (improve guess x)
(average guess (/ x guess)))
(define (average x y)
(/ (+ x y) 2))
(define (good-enough? guess x)
(< (abs (- (square guess) x)) 0.001))
(define (square n)
(* n n))
(sqrt-iter 1.0 x))

Right, thanks. So are there any tools (linters, I don't know, something) that check and optimize this once the code is running?

Let's say I have a large codebase with multiple if-elif-else cases, some of them with multiple options, is there any bit of software out there that tracks the user input or whatever data I run through it, and optimizes the order of the if-else's?

that's what he's talking about.

no, as I said optimizing the order of if-else is impossible in general because it changes program semantics

C++

I'm tired of doing RAII by hand.

Unity is way too heavyweight for the games I want to make. Also I don't want to use an OOP language like C#

>2017
>developers unironically make applications with undo/redo implemented as a fucking 1D data structure

time and time again, emacs gets it right. History and undo/redo should be a tree, and going through every revision and branch in your file's history is necessary. Anything else is silly.

Why are people still making this mistake, decades later?

That's a good point. I didn't think of that.

What is RAII by hand?

you could look at the machine code (just skim it, taking note of the length); you could put break points in your IDE; you could run a bunch of unit tests to get some idea of expected performance

I get it, on some cases the order of execution is relevant. But in other cases, where the if-else are just "pick A, B or C", I guess where the if-else resembles more a switch case, things could be optimized without altering the program, right? So wouldn't it be cool to have some bit of code that logs frequency and processing time of the if-else options and then made suggestions to optimize?

Fuck my life. I'm trying to use the Ruby net/http library but it doesn't fucking work.
require 'net/http'
require 'resolv'

http = Net::HTTP.new("www.wikipedia.org", 80)
puts http.get('/')


It keeps giving me an error.

/usr/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect': Failed to open TCP connection to www.wikipedia.org:80 (getaddrinfo: Name or service not known) (SocketError)
from /usr/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /usr/lib/ruby/2.3.0/net/http.rb:1156:in `get'
from scraper.rb:5:in `'


I tried searching this shit but I can't figure out how to fix it. I don't use a firewall or anything.

>IDE

>wikipedia.org

What do you think it is?

> not using xcode on a mac

I know this can all be done by hand, my question is, isn't there some code that does this automatically? Not maybe actually optimize it for you (change the code for you) but simply point out all the places that could be potentially optimized this way. Because again, in small codebases it's easy to do it by hand, but not when the code starts growing.

stop worrying about negligible optimizations, they don't matter. pick the right architecture, the right data structures, and the right algorithms. worry about the limiting behaviors, not the order of conditionals

>code that logs frequency and processing time of the if-else options and then made suggestions to optimize?

This would be really easy to write into your software if you care that much...

>and going through every revision and branch in your file's history is necessary
How do you choose which branch to go down? What does vim use?

>a vulkanless platform
S H I T
H
I
T

Doesn't change a thing.

/usr/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect': Failed to open TCP connection to wikipedia.org:80 (getaddrinfo: Name or service not known) (SocketError)
from /usr/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /usr/lib/ruby/2.3.0/net/http.rb:1156:in `get'
from scraper.rb:5:in `'

RAII denotes an object wiping its own ass when it goes out of scope....

If you have to wipe an object's ass for it, it's not RAII....?

Unless you just mean implementing copy constructor and all of that.

try without port 80
god why am I trying I dont use in Rudy

What port would I use?

I'm just a dumb freshman trying to come up with a cool little project for my intro to comp sci course. I want something not written into my own code, but just an add-on, or maybe a wrapper or something, that people can fork and deploy into their own code. Even if it is a negligible improvement, it's just about the theoretical improvement. I don't want to code a silly blogging platform for my final project, that's all.

you see this shit???

what the FUCK

computer science was a mistake

docs indicate you dont need a port
docs.ruby-lang.org/en/2.0.0/Net/HTTP.html

you have autism, you're gonna go far lad

I have 2 days to learn C to what I can pass off as a professional level. I'm coming from a background in Pajeet-tier managed languages.

What do?

Still doesn't work...

/usr/lib/ruby/2.3.0/net/http.rb:882:in `rescue in block in connect': Failed to open TCP connection to wikipedia.org:80 (getaddrinfo: Name or service not known) (SocketError)
from /usr/lib/ruby/2.3.0/net/http.rb:879:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:1398:in `request'
from /usr/lib/ruby/2.3.0/net/http.rb:1156:in `get'
from scraper.rb:5:in `'

>you have autism, you're gonna go far lad

lol thanks, that's the first time anyone's diagnosed me with autism. I'm gonna call my mom and tell her

walk into the interview in a dress, claim you're non--binary conforming
you'll get the job immediately

afterwards, you can slowly stop dressing like a woman and claim it was just a phase

Then start writing. Can you get your program to start recording the desired statistics using print statements? Then go from there.

Working on my 3d loli MMORPG

what are some essential 3d effects in your opinion like tesselation? I want it to look as realistic and high quality as possible

So let's say I put my autistic urge to optimize if-else's to the side for a moment, what's a good source to learn about code optimization? I'm interested specifically in optimizing based on user input, if that makes any sense.

>3d loli MMORPG
>I want it to look as realistic and high quality as possible
Are you rolling your own engine?
Start with PBR.

Yes, I decided to skip libraries like Three.JS and go with an optimized engine instead. And thank you for the tip.

optimization is a dark art, as you can tell by the angry responses on /dpt/. iry a bunch of things and see what's fastest. i dont have much advice beyond that

>optimization is a dark art

>en.wikipedia.org/wiki/Multi-armed_bandit
There's many frameworks for studying resource optimization, so it shouldn't be too hard to treat processing time as a resource and apply some of these frameworks, crunch some numbers and get a result. I don't get the whole commotion.

I started learning programming a few weeks ago. I'm thinking of programming a basic 5x5 game of checkers to conclude the 1st chapter of SICP.

Should I use C or Scheme ? I'm as much of a begginer at both.

Lisp is not beginner friendly, especially for actual programs. start with c desu.

I guess this article here is sort of what I was looking for, or at least headed in the right direction:

>igoro.com/archive/fast-and-slow-if-statements-branch-prediction-in-modern-processors/

anybody got more stuff like this?

I dont know what your wikipedia link is supposed to prove. The multi-armed bandit problem is a massive annoyance in machine learning and optimization in general.

> Pic related
Making balances and tweaks to my upcoming android puzzle game.

Why does this have to be so difficult? I still don't understand modern core profile. Would it be better to use the same rectangle and just transform it a bunch of times to create other rectangles, or is it better to have each as its own entry with its own coordinates in the the array? And also I still need a lot of work to understand how to use glm to transform and get ortho setup so the rectangles can have their own coordinates and map that

read the opengl bible you fool.

Trying to compile ncurses 6.0 from source on Ubuntu. Any clue why it'd give an error like this? I'm guessing there's not actually a typo.

I'm not all that familiar with this compiling from source stuff. I downloaded the source, ran ./configure, then ran make. Is there something else I'm supposed to do, like downloading dependencies or something? Documentation seems to assume that end users know what they're doing.

Nevermind, fixed it, had to set some flags was all. Still confused as fuck by the magic involved.

Where did you get the sprites from?

>Documentation seems to assume that end users know what they're doing.
Well yes, that's the sort of person who would be compiling from source.

>what are you working on

this

I think I worked more on its flashyness than anything

am just about to finish pic related tomorrow
suggest me a new book to read, Sup Forums

When I came in here I took not at the activity, the pattern somewhat indicates that my post may have had something to do with the lack of activity after its submission I can't help but dismiss this feeling. This is quite the demotivating experience.

> ran ./configure, then ran make
if this doesn't work i just stop trying

Can I compile a C program to use two version of the same library?

Sort of. But why would you want to do that?