/dpt/ - Daily Programming Thread

Pair programming edition

Previous thread:

Attached: sswjTmp[1].jpg (1920x1080, 360K)

Other urls found in this thread:

en.cppreference.com/w/c/string/byte
pastebin.com/NfpT1Xs7
github.com/leblancfg/autocrop
pastebin.com/E4Emerfe
pastebin.com/jrVTcaLZ
twitter.com/NSFWRedditVideo

What do u Jow Forumsuys think about C++?

Attached: 1523540960971.png (1902x3854, 474K)

I'm constructing a dependent imperative type theory which unifies the notions of variables (resp. substitutions) and resources (resp. computations).

Nice. I've been waiting for someone to do that.

it's fine
also stop using opengl you subhumans

Attached: Capture.jpg (590x169, 38K)

r8 my fizz-a-buzz Jow Forums
(a=>((f)=>f(f))((f)=>a((x)=>(f(f))(x))))
(x=>n=>n++

what language will make me the most money?

I learned today not to listen to Jow Forums ever. Rust is great looking.

What about std::variant?

Now you're just being contrarian

I just looked over the guide portion that describes Rust's approach to GC (or lack thereof) and it seems perfectly reasonable.

The little CoC spat is all Jow Forums cared about, and their dumb fascination with using pure C for everything. Sure that brings great performance but as we can all see the ambition for performance led us into bullshit like spectre and meltdown. We need a security renaissance.

so i was studying design patterns and i found out about "the gang of four"

i looked them up and one of them passed away in 2006 from a brain tumor he had 3 kids, 1 with down syndrome and a wife

really sad desu i started to cry and shit his wife remarried and i was looking up her facebook and the kids are all grown up really sad stuff desu

anyways thanks for reading my blog but i cried a lot and wnanted to share

sql

Tip of the day, never forget the argument of make's -j parameter if you are trying to compile a project with lots of targets.
You're welcome.

mmmmm that delicious tan

Attached: stop it boner.png (298x279, 34K)

Doesn't rust just use RAII like c++?

for vim users:

setlocal makeprg=make\ j12\ -C\ build
nnoremap m :silent make\|redraw!\|cc

replace 12 with the number of parallel jobs you want.
use in combination with termdebug:

packadd termdebug

Sup Jow Forums, fp brainlet here trying to learn haskell. I wrote a program to accept input from console and output the factorial of the number. How'd I do? Anything I could fix / improve on? Sorry about the retarded definition names
chips x
| x Int
strToInt = read

stupid f = show . f . strToInt

aorta x
| (length x) > 0 = do
putStrLn $ stupid chips x
val

>trying to learn haskell
stop

>stop learning new things for no reason at all
What did he mean by this?

>x * (chips $ x - 1)
>x * chips (x - 1)
i think the latter is nicer

btw if you import control.monad, aorta x becomes

aorta x =
when (length x > 0) $ do
putStrLn $ stupid chips x
val

How do you make a custom iterator in C++?
I made a custom linked list container, but I don't know how to make the iterator.

i'm going from python to C, and since it seems theres no string data type on C i'm wondering how exactly do i use a string? It sounds awful using char arrays with predefined length

Thats what C gets, char arrays with a null byte for a delimiter at the end. Use , and pointers to make working with strings somewhat easier.

en.cppreference.com/w/c/string/byte

Why would anyone ever need any languages besides C, ASM, Java, and python?

its convenient but its the java of the C family (at least not as ugly as c#) so if it can be avoided for practical reasons i would rather write in C than sepples thx.

>need

>

why would you say java and not c#? its almost the same shit

Resources on a computer aren't finite, so Python strings also have a predefined length. The Python interpreter is just creating more/larger strings for you automatically, behind the scenes. You can do this in C as well, it's just explicit instead of implicit.

To do type-safe systems programming with zero-cost abstractions and fearless concurrency.

except java is for embedded systems and C# is not?

>GitHub issue opened by user with Anime avatar

Attached: le-anime-trashman.jpg (680x680, 99K)

stop reposting between threads thx

is that an anime about programming or anything?

So with CMake and git, should I be tracking an empty (or rather with just a .gitignore file) "build" directory? I don't see many people doing it but it just seems simpler to do

git clone, cd build, cmake .., make

instead of

git clone, mkdir build, cd build, cmake .., make

Please rate my code /dpt/:
for i in range(len(L)):
L = ['-','-','-','-','-']
L[i] = '*'
L[len(L)-i-1] = '*'
print(L, i)

it prints the following:
* - - - *
- * - * -
- - * - -
- * - * -
* - - - *

it can be extended to any length of characters, and will always print an x out of *'s.

pointless/10

its for practice dum dum

Ah in that case, I revise my score to....it's okay/10

I'm trying to fix a bug with an open source program. I have it mostly working but can't seem to exactly center my results. Given an image - detect a face on that image - then given either a height/width or a size (size=height=width) crop the image around the face to that size with the face horizontally centered in the image.

Attached are four examples done with my code: pastebin.com/NfpT1Xs7

Which is a fork of: github.com/leblancfg/autocrop

I've been dealing with trying to get these squares properly all goddamn day - but if you look at the bottom left example she's a bit too the left. I'm having problems resizing the crop to be equidistant around the face.

The bug will be in the while statements somewhere:
while fwidth > x2 - x1:
step = 0
if step == 0:
x2 = x2 + 1
step = 1
elif step == 1:
x1 = x1 - 1
step = 0

while fheight > y2 - y1:
step = 0
if step == 0:
y2 = y2 + 1
step = 1
elif step == 1:
y1 = y1 - 1
step = 0

while x2 - x1 > fwidth:
step = 0
if step == 0:
x2 = x2 - 1
step = 1
elif step == 1:
x1 = x1 - 1
step = 0

while y2 - y1 > fheight:
step = 0
if step == 0:
y2 = y2 - 1
step = 1
elif step == 1:
y1 = y1 - 1
step = 0

while x2 > width:
x2 = x2 - 1
x1 = x1 - 1
if x2 == width:
x2 = (x2 - round((x1 / 2)))
x1 = x1 - round((x1 / 2))

while y2 > height:
y2 = y2 - 1
y1 = y1 - 1

Attached: 1523583140.jpg (1902x1022, 259K)

I don't need nano, vi, vim, emacs or any other one of these editors. I just need ed.
Ed, the greatest WYGIWYG editor of all.

ED IS THE TRUE PATH TO NIRVANA! ED HAS BEEN THE CHOICE OF EDUCATED AND IGNORANT ALIKE FOR CENTURIES! ED WILL NOT CORRUPT YOUR PRECIOUS BODILY FLUIDS!! ED IS THE STANDARD TEXT EDITOR! ED MAKES THE SUN SHINE AND THE BIRDS SING AND THE GRASS GREEN!!

When I use an editor, I don't want eight extra KILOBYTES of worthless help screens and cursor positioning code! I just want an EDitor!! Not a “viitor”. Not a “emacsitor”. Those aren't even WORDS!!!! ED! ED! ED IS THE STANDARD!!!

TEXT EDITOR.

When IBM, in its ever-present omnipotence, needed to base their “edlin” on a Unix standard, did they mimic vi? No. Emacs? Surely you jest. They chose the most karmic editor of all. The standard.

Ed is for those who can remember what they are working on. If you are an idiot, you should use Emacs. If you are an Emacs, you should not be vi. If you use ED, you are on THE PATH TO REDEMPTION. THE SO-CALLED “VISUAL” EDITORS HAVE BEEN PLACED HERE BY ED TO TEMPT THE FAITHLESS. DO NOT GIVE IN!!! THE MIGHTY ED HAS SPOKEN!!!

how ot make it better senpai?

Could be better. currently, L needs to be predefined with a certain length which is cumbersome. (Also capital one letter variable names??)
Try this:
def print_x(size):
for i in range(size):
l = ['-'] * size
[l[i], l[size-i-1]] = '**'
print(' '.join(l))

r8 and hate, was too long to post
pastebin.com/E4Emerfe

>See this? you forgot to free allocated memory. This is what you get for using deprecated programming languages like C.

improved with function:
def x(L):
temp = L[:]
for i in range(len(L)):
L = temp[:]
L[i] = '*'
L[len(L)-i-1] = '*'
print(L, temp, i)


thats actually really fucking smart, i can't believe i forgot about string repitition with the * operator...

also, i was unaware you could do this:
[l[i], l[size-i-1]] = '**'

if i understand, that is declairing L[i] and L[size-i-1] to be equal to the first and last character in the string "**"?
also i am still a bit unfimiliar with the .join(x) method, pls explain.

Would it really make a difference if I used a string-output-stream or an adjustable array with character elements in which I'd vector-push-extend chars into it?

post ur qt brogramming bepers owo

Well, I did a big write up but Jow Forums thinks it's spam, lol. Here it is on pastebin:
pastebin.com/jrVTcaLZ

Can someone please tell me some math resources so that I can go through/understand Algorithm books? I am talking about understanding all the sigmas, products, sets, etc. I want to go through "Introduction to Algorithms", "Algorithm Design", "Algorithms" and "The Algorithm Design Manual" so badly, but my math is lacking. I want something to get me up and running. Thanks in advance.

Attached: me_irl.jpg (800x450, 41K)

I can't see any reason to use the latter over the former. The former does things like number-to-string conversions and formatting.

>cons '() lst
see that '?
that's your prolem, you made a whole part of the text into a string placed there invalidly.

Why this doesn't work?
(define (merge-sort lst)
(define (split lst n)
(if (= n 0)
(cons '() lst)
(let ((s (split (cdr lst) (- n 1))))
(let ((left (car s))
(right (cdr s)))
(cons (cons (car lst)
left)
right)))))
(define (merge lst1 lst2)
(cond ((null? lst1) lst2)
((null? lst2) lst1)
((

Concrete Mathematics by Knuth

Isn't that a bit too ambitious for a brainlet like me? I welcome the challenge, but anything I should polish before going into it? Thanks for the reply, btw.

>C# is ugly
what, fucking C++ makes my eyes bleed
what an ugly ass languange

I'm already using adjustable arrays to hold a custom datatype.
I might as well use it for this so that I stay consitent.
My concern is the caveats that come with it, or if it is any different from string-output-strings.

here
(define merge-sort sort)

if you are at a sophomore level, it shouldn't be a problem

>eclipse workspace fucks up AGAIN
looks like i'm on workspace7 now

have you tested the pieces? does merge work?

If you haven't procedurally generated your desktop background, you're not a real programmer.

// A Hello World! program in C#.
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}


vs

#include
using namespace std;

int main()
{
cout

If you haven't use Macbook, you're not a real person.

Thanks user, gonna go ahead, and tackle it. Hopefully my brain survives.

merge and split work as intended

So you don't have to look at ugly code.

stupid f = show . f . read why the renaming of read?

main = getLine >>= aorta

>ASM
>ugly
retard spotted!

>hello world determines how pretty a language is
If that is the case then functional languages all win

>have to write a fully fleshed out BMP space invaders clone in bare metal ARM7 on a 20 year old board
>lab """partner"""" is some 50 IQ retard that couldn't even get a grip on little endian load/store at the beginning of the semester

Im so glad I'm finishing my CompE degree after this

because all you do is hello worlds right guys?
C++ and his turboautism syntax make me sick

Is C++ worth going through all the pain to learn? I like(love) C's syntax, and I want to choose a POO language with something similar, and obviously C++ came to mind.

what's a good bit of code to show the prettiness of a language then?
Also please show functional 'hello world'?

wrong
puts 'hello world'
there exists a poolang in which this is the hello world program in its entirety

In HQ9+, this is just
H

ruby?

printfn "Hello World!"

help, google b& my program :'(
all i wanted was to be able to do google searches from the command line without a browser

[/code]
#!/usr/bin/ruby
require 'open-uri'
require 'nokogiri'
require 'socket'
pageswant = nil
if ARGV.size >= 1
x = ARGV.shift
rxm = /^-p([0-9]+)$/.match(x)
pageswant = rxm[1].to_i if rxm
if !pageswant || pageswant < 1
pageswant = nil
ARGV.unshift(x)
end
end
query = (ARGV.empty? ? STDIN.read.split : ARGV).join('+')
todo = lambda do |t|
anyresult = false
Nokogiri::HTML(
open("google.com/search?q=" + query +
'&start=' + (10*t).to_s,
&:read)).search('.g .r a').each do |a|
anyresult = true
rxm = /\/url\?q=(.+?)&/.match(a["href"])
puts rxm[1] if rxm.kind_of?(MatchData)
end
anyresult
end
begin
if pageswant
pageswant.times(&todo)
else
t = 0
t += 1 while todo.call(t)
end
rescue SocketError; puts 'offline'; end[/code]

oops, fixed:
#!/usr/bin/ruby
require 'open-uri'
require 'nokogiri'
require 'socket'
pageswant = nil
if ARGV.size >= 1
x = ARGV.shift
rxm = /^-p([0-9]+)$/.match(x)
pageswant = rxm[1].to_i if rxm
if !pageswant || pageswant < 1
pageswant = nil
ARGV.unshift(x)
end
end
query = (ARGV.empty? ? STDIN.read.split : ARGV).join('+')
todo = lambda do |t|
anyresult = false
Nokogiri::HTML(
open("google.com/search?q=" + query +
'&start=' + (10*t).to_s,
&:read)).search('.g .r a').each do |a|
anyresult = true
rxm = /\/url\?q=(.+?)&/.match(a["href"])
puts rxm[1] if rxm.kind_of?(MatchData)
end
anyresult
end
begin
if pageswant
pageswant.times(&todo)
else
t = 0
t += 1 while todo.call(t)
end
rescue SocketError; puts 'offline'; end

Not much different from F#

test
test

test

test

Dead language.

Easy fix. What happens when try to merge-sort '(1)?

do the whole thing yourself
working in groups for school will only slow you down, but you probably know that by now

fuck off anime
also, fuck off faggot that reported the 'fuck off anime' post yesterday and to the mod/janny that allowed it

fuck off anime
also, fuck off faggot that reported the 'fuck off anime' post yesterday and to the faggot mod/janny that issued the warning

Attached: ku9feaz.png (3840x2160, 403K)

your drawing is shit

thanks but didn't draw it, it's a wallpaper i found online

test
test
test

test

test test(test test) {
test(test);
}

test(test test = test; test >= test; test++){
test.test.test("test "+test)

testity test test {
test:
test test(test, test test, test) {
testy testerino(testeroony);
testerino.testosterone = the_test->test();
}
} test;

What's some practical use for zippers? I just read the chapter in learn you a hasklel and the only thing I can think of is say for the tape of a turing machine.

Maybe a tail recursive map over trees? But that's dumb.

Test test = new test( test);
test.gettest().test.settest(test);

I just finished developing an app using Swift. I’m a beginner programmer so it’s probably very brittle code. I pieced it together using stack overflow, random YouTube videos, open source examples, and my limited knowledge. It has subscriptions, makes quite a lot of database calls, supports multiple accounts. It’s a big app, and somehow it works despite how terribly put together it is. However I know there are security holes, it lags and if more than a few users get on it it’ll probably crash. My database is probably structured so badly I’ll be spending 100x more than I need to.

HOW do I take this mess and refactor it to beautiful, performing code when I have such limited knowledge?

Attached: 1411581684694.jpg (900x638, 95K)