[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: 324
Thread images: 29

File: 1489604059286.jpg (86KB, 1280x720px) Image search: [Google]
1489604059286.jpg
86KB, 1280x720px
What are you working on, /g/?

Old thread: >>59459347
>>
>>59464779
"The most powerful programming language is Lisp. If you don't know Lisp (or its variant, Scheme), you don't know what it means for a programming language to be powerful and elegant. Once you learn Lisp, you will see what is lacking in most other languages." -Richard Stallman
>>
>>59464807
>Richard Stallman
Stopped reading there.
>>
File: parametric.png (616KB, 680x954px) Image search: [Google]
parametric.png
616KB, 680x954px
>>
>>59464810
>stopped reading at end of post
>>
>>59464807
Fact: Haskellers are the most powerful programmers.
>>
>>59464807
>Richard Stallman
That's where I stopped reading.
>>
File: 1489796058953.jpg (107KB, 790x798px) Image search: [Google]
1489796058953.jpg
107KB, 790x798px
>>59464807
mit cia nigger
>>
>>59464822
Where did he say that?
>>
Working through HtDP. It's pretty good tbqf.
>>
>>59464821
How are templates stupider than void * generics?
>>
>>59464828
See >>59464822

>>59464840
"Richard Stallman" is the last thing in the post. Nothing comes after it.
>>
>>59464854
Because they're templates
>>
>>59464858
So? How did you determine his reading order just based on that?
>>
>>59464854
Because they require additional code to be generated, and create wonky situations where you have to include the template method implementations in the header file.
>>
>>59464875
I'm assuming it goes left-to-right, one line at a time, then beginning at the left of the next line down.
>>
>>59464877
>Because they require additional code to be generated
Executable size vs. speed tradeoff.

>and create wonky situations where you have to include the template method implementations in the header file.
Okay well that's a C++ specific problem. Rust for example has generics that are monomorphized (i.e templates) and it doesn't require that.
>>
>>59464877
Templates produce specialized code, which can be much more performant than code that uses void* pointers.
>>
Fact: OCaml programmers are the most powerful race in the world
>>
>>59464893
What makes you think this assumption is correct?
>>
>>59464896
>>59464900
I'd rather have a slow binary than a big one. Computers these days are fast enough that performance is a non-issue, but storage capacity hasn't kept up with improvements in processor speed.
>>
>>59464912
enjoy your only one existing implementation and GIL
>>
>>59464923
>storage capacity hasn't kept up with improvements in processor speed
Is this a joke?
>>
>>59464920
Because it's the only way posts can be read in a coherent way.
>>
>>59464938
No. Forcing many more instruction cache misses is more costly than making a few more data cache misses.
>>
>>59464938
My Windows 7 computer has only twice the hard drive capacity as my old XP machine.
>>
>>59464952
What does that have to do with what he said?

In any case, with templates you can choose when to use pointers instead. Without templates you have no choice.
>>
Fact: Facts can be made up.
>>
>>59464945
That's wrong though. You can do multiple passes and still have the same level of coherence.
>>
>>59464952
>>59464976
Also, it's not as simple as "templates mean more i-cache misses". What if you call the same instantation over a large collection of values (this seems pretty common)? Templates will destroy void * generics.
>>
>>59464978
I agree. This one is indeed made up.
>>
http://www.swi-prolog.org/packages/xpce/examples.html
oop x logic programming best combination
>>
>>59465053
>poo
stopped reading right there.
>>
>>59465059
>opo sucks in my java therefore it sucks everywhere else
>>
>>59464810
>EOF
Stopped reading there.
>>
>>59465082
The hatred to OOP is a meme.
>>
I want someone to tell me why OOP is good without resorting to fallacies like "industry standard so it must be good" and whatnot.
>>
>>59465099
Hatred is a meme.
>>
>>59465082
where did I mention j*va? and why did you say "my java"? I obviously despise it since it's one of the worst examples of POO in practice.
>>
>>59465099
So? How does that make it invalid? Or does your plebbit mind simply not know the definition of "meme"?
>>
>>59465110
>I want someone to tell me why OOP is good
Are you retarded? Serious question here.
>>
File: 1470651966642.jpg (130KB, 1280x720px) Image search: [Google]
1470651966642.jpg
130KB, 1280x720px
>>59464779
I'm thinking of porting oss for gahnoo+hurd but there is some serious spaghetti in that code.
>>
>>59465184
>gahnoo
stopped reading right there.
>>
>>59465181
Are you saying that OOP is so obviously good that I'm a retard for not getting it? If so, surely you could throw me a bone here.
>>
>>59465192
No, you are retarded for demanding an answer to self-evidently unanswerable questions.
>>
>>59464983
Yes but that's inefficient, there's no reason why you would do it that way?

>>59465110
Member functions.

>>59465184
wtf is oss
>>
>waste time on obscure languages
>fail basic job interview in main stream ones
>>
>>59465220
Ever heard of a rhetorical question?

>>59465235
x.f() is just syntax for f(x).
>>
>>59465245
>programming as a profession
>>
>>59465235
>wtf is oss
Open Sound System, it's a cross platform sound system for unix-like systems. It is used by BSDs and available for Linux as an alternate to ALSA.
>>
>>59465257
Yes, that's why I can tell that your post wasn't one.
>>
>>59465257
>x.f() is just syntax for f(x).
or f x if you aren't using a shit language.
>>
File: pajeet rust.jpg (579KB, 2048x2048px) Image search: [Google]
pajeet rust.jpg
579KB, 2048x2048px
>even pajeets are switching to Rust
What are you waiting for?
>>
>>59465311
yet another reason not to use bust
>>
>>59465245
>>59465264
>>59465311
who said this???
>>
>>59465471
They did
>>
>>59465110
Suppose I were to make a game (like pacman), I'd want pacman and each ghost to have x,y properties and I'd end up with something that is either oop or "close enough" to oop (doing the same thing but with structs instead of objects).
>>
>>59465540
>I'd end up with something that is either oop or "close enough" to oop
only if you were mentally challenged. which you seem to be.
>>
>>59465540
No you wouldn't, not unless you were deliberately trying to use OOP.
>>
Anyone have that massive chart of programming projects to post numbers? I need a way to relearn some syntax

>>59464952
There are a million other things that can be modified to eliminate cache misses before templates start becoming a problem. Besides if you don't even know what object you're using in a performance critical portion of code than you have bigger problems than what type of parameter to use
>>
>>59465574
>>59465592
>make something with x,y properties that represents an entity
>"hmm no way this could be an object, I'm to smart for oop"
>>
>>59465647
It's called a record.

https://en.wikipedia.org/wiki/Record_%28computer_science%29
>>
>>59465647
>product types are now OOP
>structs are OOP
>tuples are OOP
>defining multiple pieces of data? obviously OOP
>folders are OOP

wake me up
>>
In ASM, is it normal that I can't far call a function that I can near call?
>>
>>59465693
When you went to a Java school, everything looks like an object.
>>
File: checkmato.jpg (100KB, 636x466px) Image search: [Google]
checkmato.jpg
100KB, 636x466px
>>59465654
>use record to represent entity
>suddenly you realize you are doing prototype-based oop
>your life is now a lie
checkmate
>>
File: halp.png (17KB, 715x315px) Image search: [Google]
halp.png
17KB, 715x315px
why this doesn't work?
>>
>>59465719
Nope. That's not OOP.
>>
>>59465540
In simple games translating everything to OOP can work. When it gets more complex it's a hell of a lot better to separate the data from the code that works on it. Then you can use composition to increase reuse far more than you can accomplish with inheritance.
>>
>>59465704
that explains how indians react to women
>>
>>59465721
Dynamic typing.
>>
>>59465762
what?
>>
>>59465778
This doesn't work because of dynamic typing. With static typing you wouldn't be able to construct heterogenus list in the first place.
>>
>>59465721
You're not using list-ref correctly.
>>
>>59465813
>intentionally limiting your lists
>>
>>59465818
how do I get the value of a position in a list?

I'm tired of this racket BS.
>>
>>59465813
>With static typing you wouldn't be able to construct heterogenus list in the first place.
data HList ts where
Null :: HList '[]
(:>) :: t -> HList ts -> HList (t ': ts)
>>
>>59465833
You're trying to index a list with a string.
>>59465842
You know what I mean.
>>
d = {1:'abc', 2:'def', 3:'ghi'}

for key in d:
for letter in d[key]:
print letter


How can I partially iterate trough items in value part?
I.E. I want to print only first and second letter in each key, but not the third.
>>
>>59465842
That's not a list, though, that's a record.
>>
>>59465813
Heterogeneous lists work fine with static typing.

sealed trait HList

final case object HNil extends HList
final case class HCons[H, T <: HList](h: H, t: T) extends HList

type HNil = HNil.type
type ::[H, T <: HList] = HCons[H, T]

val thing: String :: Int :: Bool :: HNil = HCons("foo", HCons(3, HCons(false, HNil)))
>>
>>59465848
I'm trying to return the value of the iterator of the loop.

should I invert the two values?

(list-ref i a)?

then why the documentation lie?
>>
>>59465721
What ugly language is that?
>>
>>59465878
The documentation isn't lying.
>be a language designer
>intentionally lie to your language's users through the documentation
>>
>>59465891
Racket.

my intro to programming class uses this piece of shit.
>>
>>59465878
No, you're using the elements of the list as indices yet the list itself contains strings in it, so eventually you end up with indexing a list by a string, which is meaningless.
>>
>>59465906
Oh man..
>>
File: wrong.gif (1MB, 480x287px) Image search: [Google]
wrong.gif
1MB, 480x287px
>>59465863
>>
>>59465910
I'm trying to return the content of the list.

I gave the function the list (a) and the iterator position (i)

what else I'm supposed to do?
>>
>>59465923
More like a tuple, I guess.
HList [Int, String, IO ()]

(Int, String, IO ())

What's the difference?
>>
>>59465905
Are you quoting someone? Please stop typing in such a retarded manner if you aren't.
>>
>>59465949
Nothing. An HList is a tuple that's easier to write library functions for.
>>
>decide to get some GitHub contributions
>start proposing some Licenses to random projects I find
>either get ignored or flamed
Should I do COC pull requests instead so they stop being mean?
>>
>>59465954
Nope, and you can't make me stop!
>he thinks he can stop someone from typing on the internet
>>
>>59465959
So you admit it's not a heterogeneous list.
>>
>>59465960
who said that?
>>
>>59465969
What is a list other than a tuple in which all the elements have the same type?
>>
>>59465954
Just fucking kill yourself already, you're not half as smart and witty as you think. Even forum banners use green text.
>>
>>59465966
Why would I force you to stop? I just asked nicely.
Well then, continue being retarded.
>>
>>59465987
Variable length.
>>
>>59465959
I hope they replace tuples with a GADT version
>>
>>59465960
pls be bait
>>
>>59465999
A list doesn't have a variable length. It's immutable.
>>
>>59465987
Tuple's length is known at compile time.
>>
>>59466021
You know what I mean.
>>
>>59465990
I don't think I'm "smart" or "witty" and I don't know what makes you think that I do. I just asked someone to stop being retarded. Merely not being a retard can hardly be called "smart".
>Even forum banners use green text.
How is that relevant?
>>
>>59465948
You need to make one small change, but I'm not going to reveal it to you.
>>
How awkward would it be if pointers in C pointed to the last element of an array instead of on the first?

in practice it wouldn't make a difference right
>>
>>59466037
Not that awkward. It would just mean a[i] = *(a - i) instead of *(a + i).
>>
>>59466023
An HList's isn't necessarily. It depends on how precise the type is.

For example, a head function for HLists knows only that its argument's length is nonzero.
>>
>>59466035
can you give me a tip?
>>
>>59466055
I'm not homosexual.
>>
>>59466049
The length is still known at compile time.

You could argue that with dependent types you could have (ts : [Type]) * (HList ts) but you then have an arbitrary list of types.
>>
File: 1488915116571.jpg (749KB, 850x1200px) Image search: [Google]
1488915116571.jpg
749KB, 850x1200px
>>59465852
Please, respond
>>
>>59466055
(for [(i a)])
is the wrong way to solve the problem. list-ref needs an index, which is a non-negative integer.
>>
>>59466059
come on bro.

if it were java I already would have solved this piece of shit.
>>
>>59466094
t. pajeeta, the prince of all indians
>>
>>59466047
Actually a +/- (size of *a) * i
>>
>>59466074
The length of (3 :: 4 :: 7 :: Nil) is also known at compile time, the compiler just chooses to forget it.
>>
>>59466091
I would. If you didn't post those ugly chest tumors.
>>
>>59466093
yeah, but I'm giving list-ref an integer, which is i.

am I missing something?

wait a second, is this a foreach?
>>
>>59466116
Wrong.
>>
>>59466116
Dereferenced of course
>>
>>59465257
>x.f() is just syntax for f(x).
The former also provides namespace resolution, so you can have multiple types with methods of the same name. So rather than having to define separate functions cat_feed() and dog_feed(), you can simply define a member function feed() in both the cat and dog classes.
>>
>>59466124
Now you're just shitposting.
>>
>>59466091
something like this? print d[key][:2]
>>
>>59466132
>is this a foreach?
YES you got it.
>>
>>59466140
>what are type classes (traits) [concepts]
>>
>I.E. I want to print only first and second letter in each key, but not the third.
for key in d:
for letter in d[key]:
print substring(letter, 0, 2)

?
>>
File: 1489778597371.png (11KB, 211x246px) Image search: [Google]
1489778597371.png
11KB, 211x246px
>>59466147
this language sucks.
>>
>>59465654
And at what point does using functions to manipulate records become OOP? Is
ghost_move(ghost *g, int direction)
OOP?
>>
I have to write a lexer, I have the option to use either C or C#, which one would you use?
>>
C# == JAVA
>>
>>59466184
When they can be seen as sending messages to an opaque actor that reacts by mutating itself and/or sending more messages.
>>
>>59466200
flex
>>
>>59465852
>>59466091
print([val[:2] for _,val in {1:'abc', 2:'def', 3:'ghi'}.items()])
>>
>>59466180
Keep in mind you still need to use ``for", but not using just 'a'.
>>
>>59466216
>>59465852
>>59466091
This works as well :
d = {1:'abc', 2:'def', 3:'ghi'}
print([d[key][:2] for key in d])
>>
>>59466202
It's not 2002 anymore, dad.
>>
>>59466153
And how exact would that be different from x.f() syntax? Either way requires the compiler to look up the type of an object and select the appropriate function.
>>
Can someone explain why this haskell code runs on on the shell, but won't compile?
>>
>>59466262
It's not, but OOP is a hell of a lot more than just ad hoc polymorphism.
>>
>>59466200
It's as dumb as implementing a finite automaton. Pick whichever you prefer.
>>
>>59466274
because monoid of covariadic endofunctors needs to be enabled in the compiler, you basically need an extension
>>
>>59466274
remove the let.
>>
File: dafuq am i reading.jpg (104KB, 613x533px) Image search: [Google]
dafuq am i reading.jpg
104KB, 613x533px
>>59466293
What?
>>
>>59466146
>>59466216
>>59466246

What if those were numbers? Well, I should have made it up for numbers, I need them to be separate elements. Cause you still don't 'iterate', you just print a slice.

I.E. I want to create a new dictionary with summed up 2nd and 3rd number
d = {1: [1,2,3,4], 2:[5,6,7,8], 3:[9,10,11,12]}
--->
d_new = {1:5, 2:13, 3:21}


Also, nice 666.
>>
>>59466274
>>59466298
This.
>>
>>59466293
That is part of Haskell2010, you retard.
>>
>>59466298
This worked, thanks!
>>
well, got it working.
many thanks.

(define (eliminar a) (
for ([i (length a)])
(if (number? (list-ref a i)) (set! l_mexcla_new (flatten (list l_mexcla_new (list-ref a i)))) 0 ))
)
>>
>>59466274
>>59466298
>>59466317

in actual Haskell code
let x = y
doesn't make any sense - let requires a context

let x = y in e

in the REPL it does make sense, you're defining it in the context of the REPL session
I think since GHC 8 or something you can just do this in the repl:
x = y

That's much better
>>
File: 321.jpg (96KB, 1280x720px) Image search: [Google]
321.jpg
96KB, 1280x720px
So I think I should make a C-to-algol or C-to-something compiler. Is there any practical course/guide/helper since all the basic resources only focus on the theory? Will I have to do it all alone and hope it ends up good?
>>
>C
>external library 1 that uses external library 2 encapsulates struct data so I can't access it
>external library 2 requires data that external library 1 hides
Wat do
>>
Suppose I have something like this
data Lit = LInt Int | LDouble Double
Is it possible to add a Haskell list here without explicitly passing any arguments to Lit?
>>
>>59466351
c-to-assembly or you are a faggot
>>
>>59465852
letter[0:1]
>>
>>59466351
i want to masturbate to this image while programming.
>>
>>59466361
>Is it possible to add a Haskell list here
Where?

>without explicitly passing any arguments to Lit?
Lit doesn't take any arguments.
>>
>>59466361
What do you mean "add a haskell list"?
>>
>>59466351
> C-to-algol
For what purpose tho, it's basically 1:1 translation, or even easier, since C is more low-level than Algol.
>>
>>59466305
d = {1: [1,2,3,4], 2:[5,6,7,8], 3:[9,10,11,12]}

def func(dict, start, end):
return [sum(val[start:end]) for _,val in dict.items()]

print(func(d, 1, 3)) # [5,13,21]
>>
>>59466351
Just make a brainfuck compiler.
>>
Does anyone know an illustrative proof of the fact that the geometric walk (0, 1, 1 + 2, 1 + 2 + 3, ..., 1 + 2 + ... + 2^N-1) is injective in \Z/(2^N\Z)?
>>
how do I code in a big easy language for noobs but then compile my code to C++ and then compile to binary for speed?
>>
>>59466421
Could you please explain me all of these syntax things?
Why return[]?
What is 'for _,'?
>>
>>59466394
>Where?
Anywhere so that Lit can represent a list.
>Lit doesn't take any arguments.
Yes, that's clear and my post heavily implies that.

>>59466402
I mean it in the same way that LDouble holds a haskell double.
>>
>>59466405
Wait hang on, I'm messing up the compiler stuff. The languages I was looking at for reference were Python/Prolog/Lua/Icon/Io. So really I'd like to make a VM in C.
>>59466424
Wouldn't that be too basic? But yeah, maybe I should try that.
>>
>>59466360
Don't use external libraries.
>>
>>59466466
Well, you have to decide the type of the elements of the list somehow. You could do this:
data Lit
= LInt Int
| LDouble Double
| LList (forall a. [a])

but you won't really be able to do anything with the list elements. If you want to be able to use the list elements, you have to have a type class for the operations and bound it like so:
data Lit
= LInt Int
| LDouble Double
| LList (forall a. Class a => [a])

For instance, if Class was Show, you would be able to "show" all of the elements. You could also do this if it's appropriate:
data Lit
= LInt Int
| LDouble Double
| LList [Lit]
>>
>>59466533
>You could also do this if it's appropriate:
Fuck, I'm retarded. That's what I needed. Thanks.
>>
>>59466592
>Fuck, I'm retarded.
t. haskell programmer
>>
>>59466457
If you want to return a dict rather than a list :
d = {1: [1,2,3,4], 2:[5,6,7,8], 3:[9,10,11,12]}

def func(dict, start, end):
return [sum(val[start:end]) for _,val in dict.items()]

def to_dict(l):
return dict(zip(range(1,len(l)+1), l)) # not sure if it's the most pythonic way to do it though.

print(func(d, 1, 3)) # [5,13,21]
print(to_dict(func(d, 1, 3))) # {1: 5, 2: 13, 3: 21}


The
return [...]
returns a list comprehension. Basic example :

[x*2 for x in range(1, 11)] == [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]


You can read it as so : for each value from 1 to 11 (11 being not included), multiply each member by 2 and make a list out of all the results. Alternatively, you could write that :

lst = []
for x in range(1, 11):
lst.append(x*2)


About the
for _,val
that's something you can split in two elements the term right after the "in". Basically here, the underscore will store a key, and "val" the value of each item of your dictionary.
>>
>>59466592
keep in mind that allows

LList [LList [ LList ... ] ]
>>
>>59466636
Thanks! Saved!
>>
>>59466638
Yeah, that's what I intend.
>>
>>59464821
Retard. 4th isn't even generic.
I think you meant:
<Type>(a: Type) ->
>>
>>59466782
What?
>>
>>59466808
I assume the 4th panel is Rust code.
If it is, then it's not generic.
>>
File: 1478838811226.png (165KB, 327x316px) Image search: [Google]
1478838811226.png
165KB, 327x316px
>>59466782
>>59466833
>>
File: 1483369485134.gif (995KB, 280x201px) Image search: [Google]
1483369485134.gif
995KB, 280x201px
>>59466833
>I assume the 4th panel is Rust code.
>>
>>59466863
>>59466874
Ok what is it then.
>>
>>59466886
Dependent function type.
>>
>>59466886
Looks like Idris.
>>
>>59466893
I mean what language is it you retarded fuck.
>>
Does any of you know how to make my exe make a UAC dialog pop up to escalate my privileges on Windows?
Since I don't use windows I have no clue how to make it work.
>>
>>59466909
Could be almost any dependently typed language.
>>
>>59466909
Most languages with dependent functions
>>
>>59466910
just bypass it
>>
>>59466286
You mean in terms of complexity or is a lexer just a finite automata? because I already made a universal fda
>>
>>59466910
stackoverflow.
>>
Should I give my project a code of conduct?
>>
>>59467293
yes, but only if you first post it here
>>
>>59467293
Only if you want to see your project die.
>>
Why do programmers tend to bully webdevs?
>>
>>59467293
What would your code of conduct look like?
>>
>>59467372
Notice how you just made a distinction between programmers and webdevs.
>>
>>59467293
Depends on the target audience.
>>
What's the best C compiler?
>>
>>59467413
None.
>>
>>59465184
I find this picture funny because anime girls can't read
>>
>>59467355
>>59467385
http://contributor-covenant.org/
>>
File: yodabait.jpg (147KB, 500x378px) Image search: [Google]
yodabait.jpg
147KB, 500x378px
>>59467441
>>
Made an honest placebo benchmark, As a D fag I will admit the performance is pretty slow. However D code still looks the most elegant one.
>>
Hey guys, I really fell in love with Nier: Automata and was thinking about making my own multiplayer port.

Does anyone know what language it's in?
>>
>>59467413
The ones written in C++.
>>
>>59467494
Ask the developer.
>>
>>59467441
Why? Why the fuck do you need a code of conduct?
>>
>>59467486
(((elegant)))
arr ~= i;
>>
>>59467527
Easy to ban edgy teenagers
>>
>>59467539
ints.push_back(i) was pretty elegant no?
>>
>>59467428
Wait, what?!
>>
>>59467441
>Fuck my code up code of conduct
>>
>>59467486
Why do you even compare such primitive stuff? The main difference is GC and you have to give it time and garbage to kick in.
Also
>foreach(element; arr)
>elegant
>>
>>59467554
At least it's better than using ~= as an operator.
>>
>>59467574
foreach is much more nicer than for()
>>
>>59467606
You do realize I can use arr[i] = i if I just wanted to, right?
>>
>>59467606
What's wrong with that?
~ is used for concatenation
>>
>The use of sexualized language or imagery and unwelcome sexual attention or advances
>Trolling, insulting/derogatory comments, and personal or political attacks
>Public or private harassment
>Publishing others' private information, such as a physical or electronic address, without explicit permission
>Other conduct which could reasonably be considered inappropriate in a professional setting
Why is this a bad thing to enforce, exactly?
>>
File: halp.png (170KB, 1440x900px) Image search: [Google]
halp.png
170KB, 1440x900px
pls rate.
>>
>>59467655
Suppose you're making a VN or dating simulator.
>>
>>59467655
source?
>>
>>59467681
>>59467441
>>
>>59467666
porque é que estás a perder tempo com Racket?
>>
>>59467621
Not when written as a singe word. Also ; makes no sense as a separator.
>>59467666
Why are you trying to write C code in Racket?
>>
>>59467486
A benchmark should take at least one second in C before it should be even mentioned.
>>
Anons how do you post the white box used to separate code here?
>>
Autonomous robotics sucks man, and so does the code I'm writing
>>
>>59467441
https://forum.dlang.org/post/[email protected]

they tried to pull that at D lang

>Maybe we could have something similar in D community
>No. People who need to be told what decent behavior is won't pay attention to such a document.
>>
>>59467719
>>59467720
is my intro to program class, have to take that shit.

>C code
I dunno, is how I think.

what am I doing that is considered C code?
>>
>>59467486
The c++ version terminates when the number is found, the D and Rust version do not.
Both need a
return;
after the println to be equivalent to c++.
>>
>>59467752
Seems like they're trying to do it everywhere. Those who can't code, try to add a CoC to get people who actually contribute banned.
>>
>>59467734
People like you make me believe that we are not going to have machine rebelion because the code would be shitty as fuck
>>
>>59467655
You don't need a code of conduct to enforce that.
>>
>>59467734
What type of robot, what language?
>>
>>59467753
Formatting of Lisp code is different from the formatting of C code.
>>
>>59467802
yeah, fuck you too m8.
>>
File: rng.png (579KB, 1920x1080px) Image search: [Google]
rng.png
579KB, 1920x1080px
>>59464779

r8 my RNG

you can do it in <10 assembly instructions per bit on a machine with a population instruction
>>
>>59467825
You seem a tad emotional. Good luck with your homework.
>>
>>59467838
I can see a pattern.
>>
>>59467753
> what am I doing that is considered C code?
The formatting is wrong, but also the code isn't functional, it's typical imperative code with assignments and loops, written in Racket for some reason.
>>
>>59467838
Doesn't seem very random. I can see streaks.
>>
>>59467838
>RNG
no such thing.
you mean
PRNG
>>
>>59467845

you can see a pattern in the primes too

doesn't mean anybody can predict them
>>
>>59467860
teach me what are the diferences between functional, imperative and OOP.
>>
>>59467878
>no such thing.
Oh that's awesome, you've proof that the universe is deterministic?
>>
>>59467893
Why don't you close the browser and go read a book instead?
>>
>>59467845
diagonal lines right
>>
>>59467913
I just need to know if I'm going to get bad grades because of writing C code in Racket.
>>
>>59467893
imperative code is about state - functional is not.
>>
File: 145593.jpg (242KB, 2519x2012px) Image search: [Google]
145593.jpg
242KB, 2519x2012px
>>59467838
You can do it in 1 assembly instruction (If you have Ivy Bridge or latter).
>>
>>59467940
You'd get an F in my book.
>>
>>59467884
I can though.
>>
>>59467902
i have proof your program is not RNG, kiddo. It's PRNG
>>
>>59467940
>implying the teacher will care
>>
>>59467893
This is a malformed question since one thing here is a subset of the other two.
>>
>>59467981
>>59467871
>>59467878

yeah but these are NIST certified 3ghz random numbers from an unstable clock. nigger
>>
File: 1489771403744.jpg (6KB, 245x205px) Image search: [Google]
1489771403744.jpg
6KB, 245x205px
>>59467984
NOOOOOOOOOOOOOOOOOOOOOOO

I just want this stupid class to finish so maybe I can get a class about a real language like C.
>>
>>59467967
>declarative is not
ftfy
You can program functionally with imperative language
>>
>>59465540
Holy shit you're fucking retarded. Learn the difference between a structure in a non-OOP language and an object in an OOP language please.
>>
>>59468017
>C
>real language
More like trash language.
>>
>>59468017
racket > c young friend
you better write racket right, it's a much more beautiful language than c

yes it's slower and not for systems, still
>>
>>59468051
please tell me what a real language this
>>
>>59468063

haskell
>>
>>59468017
>a real language like C.
You mean C++
>>
>>59464779
Thank you for using an anime image.
>>
File: checkmated again.jpg (133KB, 1280x720px) Image search: [Google]
checkmated again.jpg
133KB, 1280x720px
>>59468029
>implying you aren't doing the same shit whether you use a struct, record or object for the ghost
>implying an object doesn't have an implementation of hash underlying it
>javascript literally has a record they call Object
>>
File: 1455749649222.gif (148KB, 340x340px) Image search: [Google]
1455749649222.gif
148KB, 340x340px
>mfw waiting for my book in the mail
>>
>>59468138
Dumb animu poster
I bet you can't even read.
>>
>>59468138
>2010+7
>buying dead trees corpses
Why is this even allowed?
>>
>>59468164
Take your pills
>>
>>59468137
>unrealistic chess positions
why is there nobody that can play the game in media
>>
>>59468179
Superior reading ergonomics.
Doesn't need power.
>>
>>59468187
Not until you're mom take the birth control one
>>
>>59468232
Oh, look at him, he swears like a big boy!
>>
>>59468255
you jelly because I'm stylin on yo ass
>>
File: 1488906206376.png (666KB, 666x666px) Image search: [Google]
1488906206376.png
666KB, 666x666px
>>59468278
What an argument!
I'm not going to post anime after such words!
>>
File: 161093861073.jpg (24KB, 227x173px) Image search: [Google]
161093861073.jpg
24KB, 227x173px
>>59468300
you jelly, you jelly, you jelly jelly
you are a jelly weeb
>>
>cristian
>>
working on my shitty compiler
decided to add pointer to characters, hassle to do it isn't that big
have to add couple a more things and do more testing, but IO is almost complete

i really wonder if i'm doing something stupid and making my life incredibly miserable for when i have to write a memory allocator for it
allocator seems simpler than a garbage collector
>>
>>59468138
which one, anon?
>>
File: programming-in-d-front.jpg (186KB, 1800x1412px) Image search: [Google]
programming-in-d-front.jpg
186KB, 1800x1412px
>>59468427
>>
>>59467606
~= is pretty elegent as it's used in Lua instead of !=. And Lua is a masterpiece, so it's elegent.
>>
In C, how is the tilde applied:
int a = 0;
a = ~0 << 4; // This is negative 16


I don't understand why the above statement is different than:
a = 1 << 4; // Positive 16.


I understand twos complement, I just don't understand how the tilde is working. Because to me ~0 << 4, means give me the opposite of zero and shift it left 4 bits (.....001_0000), not invert all bits starting from the fourth bit (....111_0000).
>>
>>59468492
>Because to me ~0 << 4, means give me the opposite of zero and shift it left 4 bits (.....001_0000),
~ is the one's complement, so 'opposite' of 0 is all ones, i.e 0xFFFFFFFF for a 32 bit int.
Although you should note that left shifting a negative value is undefined behavior in C.
>>
>>59468537
Ahh, thank you.
>>
File: unnamed.gif (681KB, 401x367px) Image search: [Google]
unnamed.gif
681KB, 401x367px
Can you guys give me some simple to hard gui and event handling exercises pls ??
>>
How do I use undefined behavior to optimize my program? I just want it to run fast, I don't care about portability.
>>
Is D faster than Java?
>>
>>59468765
It's the compiler's job to optimise based on that, not yours.
Optimise your algorithms and cache usage. Maybe provide some annotations for the compiler to help it generate better shit.
>>
>>59468734
An efficient progress bar (you'd be surprised of how many gui toolkits have a terrible one where the displaying of the progress bar actually takes a non-significant amount of cpu time, sometimes to the detriment of the underlying operation its measuring).
>>
>>59468786
Definitely yes.
>>
>>59468765
>Too retarded to come up with a good algorithm
>" How do I use undefined behavior to optimize my program? I just want it to run fast, I don't care about portability."
>>
>>59468492
Are you trying to obfuscate your code?
>>
>>59468788
>It's the compiler's job to optimise based on that, not yours.
Sure, but I could help it by using more undefined behavior.
>Optimise your algorithms and cache usage.
Yeah, I'm doing that too but I want to harness some of the power UB can give.
>Maybe provide some annotations for the compiler to help it generate better shit.
What do you mean by this?

>>59468799
My algorithm is already pretty good though.
>>
>>59468765
Your question makes no sense unless you're writing a compiler.
>>
>>59468829
>My algorithm is already pretty good though.
If it was you wouldn't have have to ask this question
>>
>>59468829
>What do you mean by this?
Use compiler builltins like __builtin_expect. Use compiler attributes like __attribute__((nonnull)) or whatever. Use SIMD vectorisation shit.
And so on.
>>
>>59468838
I am, but it's not self-hosting yet so I have to cause some UB in the other compiler too.

>>59468839
Rude...

>>59468863
Is that all? I need maximum performance, I don't care if I have to purposely overuse undefined behavior.
>>
I'm messing with a deep learning library for C++. I'm having some trouble finding an efficient way to solve this problem: I have a vector that represents the image and I want to add some statistics I computed from it. So I end up making a vector of vectors, like this:

void process_features(vector<vec_t> data_in, vector<tensor_t> &dout) {
unsigned int max = data_in.size();
dout.resize(max);
for (unsigned int i = 0; i < max; i++) {
dout[i] = {data_in[i], get_feat_vec(data_in[i])};
}
}


Problem is: this is kinda inneficient. It takes 22s for a 50.000 dataset for a trivial O(1) get_feat_vec function. It seems to be linear.

I'm not very good in C++ so I don't know if I'm making something wrong here, but is there a way to optimize this?
>>
>>59469028
>deep """""""""learning"""""""""
>>>/r/ibbit
>>
>>59469039
>he doesn't learn deeply
>>
>>59469028
Yes, use undefined behavior.
>>
>>59469039
well yeah it's a dumb name for optimization + stats but you could do it anywhere
>Machine """"""learning"""""
>Artificial """"""intelligence"""""
>"""""nonlinear""""" programming
the list could go on
>>
>>59469059
how?

Also should I go to /sqt/? I don't know how stupid this question may be
I already considered multithreading too, just wanted to know if there's something else
>>
>>59469120
>you could do it anywhere
yes, which you absolutely should.
>>
>can't write android applications in pure C
>must have java project
How did google fuck up so bad?
>>
>>59468960
>I am, but it's not self-hosting yet so I have to cause some UB in the other compiler too.
You still seem somewhat confused about what UB is.
You can't 'use it' in your programs because if you do, you can't even be sure of the correctness of the program anymore - and that isn't just about portability,, changing compiler flags or just moving some code around (say swapping the order of two functions) can break your program.

If you're wondering about how to select the optimal instruction sequences you look at the standard, see what the required semantics are then make sure you meet that, and if something is left undefined you can leverage that by for example picking an instruction which relies on some specific assumption.
A concrete example:
Overflowing a signed int is undefined behavior.
You've chosen int to be 32 bits, but pointers are 64 bit and the architecture you've implementing for has various complex addressing mode you'd like to use, so when you generate code for a[i+1] = b[i+2], where i is an int you would like to just use an indirect register + immediate and not care about potential wrap around for i, so you just emit instructions assuming i never overflows.
>>
>>59469207
actually it should be possible with android ndk, but you'll have to make some simple java layer
>>
>>59468960
>undefined behavior
No that's something you always wish to avoid.
You could be aware of UB and appreciate the narrow contract that's given for say integer vs unsigned integer.
For indexing its faster because the compiler is allowed to assume no overflow.

Optimization is always about other things. Managing your i$, l1 & l2 cache. Ensuring your algorithms are fast. Avoiding virtual functions anywhere you can. Making small changes to code where you'd think the compiler would figure it out (i.e move conditions out of loops where possible).
There's tons to do. But to understand where to put your effort is usually an experience thing. You have to be intimate with the constraints of the language to a degree where reasoning about what small changes would result in is natural for you.
The option to that is writing many different versions of the same thing and profiling. But even when you do that you eventually need to understand your code.

Tools like IACA help a lot.

Watch these talks for a quick introduction to making code that performs well.
In order of simple to proper:
https://youtu.be/fHNmRkzxHWs
https://youtu.be/nXaxk27zwlk
https://youtu.be/vElZc6zSIXM (mostly applicable to large code bases you don't control entirely yourself)
https://youtu.be/rX0ItVEVjHc (fairly general advice, maybe should be watched second)
https://youtu.be/GPpD4BBtA1Y (adapting new algorithms to the real world, practical example)

They are all very good and ordering them is hard but I say this order should be good for someone who knows nothing about computers.
Oh and on the topic of UB, https://youtu.be/yG1OZ69H_-o
A more healthy perspective on UB.
>>
>>59469181
try deferencing invalid memory addresses before this piece of code. i heard that can make things more fast.
>>
New thread:

>>59469243
>>59469243
>>59469243
>>
>>59469203
do you make air quotes when you talk mouse because its not actually a mouse
>>
>>59469028
Impossible to answer without knowing more about the problem and what kind of data you have/need.
>>
>>59469292
Even for the case described where get_feat_vec is just "return 0" (kinda)?

data_in is a vector of vectors of float (each one being an image)
dout is the same thing except instead of an image you have a vector where [0] is the image and [1] is the features (in this case, a bunch of zeros)
>>
>>59469403
If get_feat_vec() is trivial (and you have measure this) then the slowness comes from the data structure layout, i.e how it gets allocated and accessed.
I would need to see full definitions of vec_t and tensor_t (recursively, including any subtypes they contain) to make any useful suggestions.
>>
>>59468765

that's not really a valid tradeoff unless you like self modifying code and saving those clockcycles by assuming malloc didn't fail
>>
>>59467772
Rust doesn't use 'return'.
>>
>>59468029
Literally the only difference is that objects have a this/self pointer.
>>
>>59468051
>>59468086
What's your kernel written in?
>>
>>59468137
Objects only use hashes in scripting languages. In compiled languages they use name mangling instead.
>>
>>59469477
Shit I thought it was just an alias for a float vector, but it's actually quite complicated
typedef std::vector<float_t, aligned_allocator<float_t, 64>> vec_t;
typedef std::vector<vec_t> tensor_t;

one of the maintainers said "
tiny-dnn uses SSE/AVX, and it's performance depends on the alignment (See product.h, for example).
tiny-dnn/tiny-cnn is using 64bit-aligned types from v0.1.0 to maximize SIMD performance."

Damn this is way more complicated than I thought
>>
>>59469579
A mix of Haskell and Rust.
>>
>>59468204
>Doesn't need power
Wrong.

>>59468334
Who said that?

>>59468466
Absolute meme tier.
Thread posts: 324
Thread images: 29


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