[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: 28

File: 7cq9ygq.jpg (30KB, 400x240px) Image search: [Google]
7cq9ygq.jpg
30KB, 400x240px
old thread: >>57871217

Hello, are you making a nice code?
>>
First for C
>>
Java is good
>>
i am making rude code and there is nothing you can do to stop me
>>
>>57875383
You didn't use usual OP, please keep them consistent.
also your janny ebin
>>
>people actually think Scala has dependent types
Screaming
>>
trying to make a rock, paper, scissors game in java with a GUI. just going through pseudocode right now, any advice?
>>
>>57875498
don't use java
>>
>>57875498
>pseudocode
Why do people do this?
It's completely pointless.
>>
>>57875516
It can be helpful when the final code must be written in an extremely verbose language such as Java.
>>
>>57875467
>dependent types

?
>>
>>57875467
>people actually think it doesn't
>>
>>57875516
>>57875509

i'm still new to programming in general, i'd like to hear some more of what you guys think though.

Unfortunately I have to use java, it's for an assignment @ uni
>>
>>57875529
Γ, x:A ⊢ B:Type
――――――――――――――――
Γ ⊢ Π(x:A)B:Type


>>57875546
Feel free to go ahead and show value dependency in Scala's type system.
>>
>>57875554
have you heard of the word monad before?
>>
>>57875562
>gibberish

The fuck are you going on about faggot?
>>
>>57875565

nope, what's monad?
>>
>>57875516
>>57875523
It's just busywork garbage taught at universities.
It's equally as worthless as using UML diagrams.

Schools still teach UML unironically, they become completely unreadable as soon as you start planning programs with more than 5 functions.
>>
>>57875577
I would Google "dependent type" and copy paste some paragraphs from Wikipedia but you can do that yourself.
>>
>>57875438
linus...
>>
>>57875562
I think you mean

>Scala doesn't have this particular subset of dependent types
>>
>>57875587
>In computer science and logic, a dependent type is a type whose definition depends on a value.
>not just calling it value-dependent types

computer scientists really do suck at naming things
>>
>>57875516
>>57875523
>>57875586
It's useful if you're a pleb and can't stop yourself from using inheritance. Inheritance basically requires you to know all your classes and their relationships ahead of time or you will waste a lot of effort on going over your old code and refactoring it constantly when adding a feature that requires a new class.
>>
>>57875594
no, he meant
>scala doesn't have dependent types
>>
>>57875562
trait Wotsit {
type A
}

def bozzer(w: Wotsit)(implicit m: Monoid[w.A]): w.A = m.zero
>>
What is the hardest to master high level programming language?
Is it Haskell?
>>
>>57875644
C++
>>
>>57875594
People say it has "path-dependent types" but I've seen no evidence that it's anything that's not possible with GADTs.

>>57875609
Value depending on value - function
Type depending on type - type family
Value depending on type - overload
So there's no reason to prefix "dependent" with "value-".

>>57875643
How is this different from:
def bozzer[A](implicit m: Monoid[A]): A = m.zero

You're going to need a better example than that.
>>
>>57875691
>there's no reason to prefix "dependent" with "value-".

yeah I see you enjoy being impenetrably terse. no wonder 90% of every academic writing reads like shit.
>>
Should I learn Rust or Idris next? I want to give both a go eventually.
>>
Pseudocode, yes or no?
>>
>>57875770
gay
>>
>>57875770
I say yes.

As i'm writing code I like to have a notebook next to me, so I can keep track of what i want to do or what I think the computer is doing. I never erase anything, and I never throw out my papers
>>
>>57875768
rust
>>
File: Untitled.png (2MB, 1920x1080px) Image search: [Google]
Untitled.png
2MB, 1920x1080px
>>57875807
>>
>>57875959
Ah, yes, I had almost forgotten about that piece of software.
>>
I'm trying to embed sfml.net dlls into the exe file. According to the sfml website, "sfml.net is built on top of the C binding (csfml)", so it has some dlls in c# and others in c, I think.
I was able to easily embed some of the dlls using Costura.Fody, but embedding csfml dlls simply doesn't work.
I've tried other methods too (like https://www.codeproject.com/articles/528178/load-dll-from-embedded-resource) but it says the dll should have a manifest or something.
>>
>>57875581
A monad is just a monoid in the category of endofunctors, what's the issue?
>>
>>57875770
formal pseudocode, no not really
description of procedure in chunks of steps, yes.

Formal pseudocode is for like explaining algorithms on wikipedia, the other one is for giving yourself/ a team an idea of what happens start to finish (like take item out of fridge, use item in meal, wrap meal, store in freezer for later use).

If you can write something into pseudocode you pretty much wrote it for real.
>>
>>57875498
Use javafx, or even make it a webapp. Just dont use swing
>>
>anon posts an easily-debunked "example" for how Scala has dependent types and then fucks off when challenged to post a better one
Really makes you think.
>>
Does html have a #include tag of some sorts?

I want to make a pure html static website without dependencies on tools such as template engines but I can't figure out a good way to put something such as a page footer on a separate file and include it in every page.

HTML imports make no sense, <template> is dynamic. The closest thing to what I want seems to be <object>, <embed> and even <iframe>.

How could HTML be this fucked up? This is literally 80s technology
>>
>>57875691
So, what, a dependent type is a type that can be something else? I've never really understood that shit.
>>
>>57876123
no
>>
>>57876123
>Does html have a #include tag of some sorts?
yeah, it's called Ctrl+c, Ctrl+v

javascript can include html pages for you though
>>
>>57876030
And a monoid is just a monad in the category of endofunctors. It's beautifully symmetric.
>>
>>57876141
I want my pages to work without javascript.

>>57876133
Really?
>>
>>57876153
Template engine or bust, dipshit
>>
dragging my poor old under-caffeinated brain through writing a web application in Perl because it's the best programming language for web applications (ok, it's the only one I know. it's been ages since I wrote a web application)
>>
>>57873369
Anon OOP might be a zero overhead model in the mind of the crazies that use it but the fact of the matter is that it doesn't boil down to that in a compiler.
Sure. With a perfect compiler you'd be right. The exceptions are the issues.
But there's more to it in the real world.

And if we look at the low level situation of today I simply don't see how the programmer can reach the level of specificity that would be required to make a program go fast in a realistic scenario. You have to remember that the more potential you leave open the less the compiler can do. Using volatile variables just kills optimizations. Aliasing kills optimizations. Virtual functions (dynamic dispatch in general, but virtual functions in particular) kill optimization. If we had a more flexible OOP programming language than C++, which is very limited in its inheritance model in particular, you'd only increase these issues.

So you're absolutely correct and wrong at the same time. When I hear low level programming I'm assuming a real world scenario, with all considerations you can have. And compliers are just software. They're not magic.
>a good chunk of performance critical...
Yes. But while I haven't looked at your examples I can confidently say it's not gonna be pure OOP down at those high performance parts of the code. That's what anon requested. He wanted OOP and he wanted to be 'the best' at high performance software while using OOP.
You often find that they move away from C++ as they need more performance. An example would be Mike Acton's 2014 Cpp con talk. It gives a nice view of the rules they have for their games and surrounding tools.
Question actually comes up why they use C++ and the answer is obviously that they'd rather use lower level languages like asm or C. But there's not enough hires to make that feasible.

OOP is in direct opposition to high performance right now. It doesn't abstract in a way that gives Compilers more power/opportunity.
>>
>>57875516
It's very helpful. It's a planning step where you don't consider it supreme to your experience.
>>
>>57876123
>>57876153
>I don't want to use server smarts
>I don't want to use client smarts
>waaah why is html not smart

You may be suffering from retardation.
>>
>>57875644
No, it isn't Haskell.
You asked this before.
>>
>>57876123
if you don't want to use js or a basic cms with a template engine, write a set of scripts that will generate static HTML pages from source and template files. i can't remember the name, but there's some hyper-minimalist blogging platform where you have to manually run a program to generate all the html every time you make a new post.
>>
really neat function for python, I stole the first function from stafck overflow, but added the rest of the code to move around like a rougelike, cept its not going to be a rougelike, gonna be a text based rpg, but with map movement

import os, sys, tty, termios

def key_pressed(char_width=1):
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(char_width)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch

def print_board():
for row in range(45):
for col in range(35):
token = board[row][col]
if not token:
token = " "
print(token,end=" ")
print()

board = []

for row_num in range(45):
row = []
for col_num in range(35):
row.append(" . ")
board.append(row)


player = " @ "
empty = " . "


old_row = 0
old_col = 0
current_row = 0
current_col = 0


playing = True
while playing == True:
print("\n"*75)

board[old_row].pop(old_col) and board[old_row].insert(old_col,empty)
board[current_row].pop(current_col) and board[current_row].insert(current_col,player)


print_board()


kp = key_pressed()

old_row,old_col, = current_row,current_col

if kp == "j" or kp == "s":
current_row +=1
if kp == "k" or kp == "w":
current_row -=1
if kp == "h" or kp == "a":
current_col -=1
if kp == "l" or kp == "d":
current_col +=1


>>
>>57876125
decimal : Bool -> Type
decimal True = Float
decimal False = Int

value : (b : Bool) -> decimal b
value True = 1.5
value False = 1
>>
>>57876125
It's a type that depends on a value.

Think of an array. You have the type of the elements as well as a length. To index this array without the possibility of an error, you need an index that is less than the length. While you can do this just fine without dependent types, dependent types allow this length to be determined dynamically even though the types are static. While it's easy to see how you get an array of that length (by construction), it can be trickier to see how you get an index. One way is to enumerate all the indices from 0 to length-1, like with a for loop. Another way is to take an arbitrary natural number (unsigned integer) and check that it is less than the length.

It all works out because of immutability. The "value" only exists in the type as a placeholder. You can still operate on placeholders, though, by using identities such as x+y = y+x. If you have a value of the type "indices less than (x+y)", you can use it to index a value of the type "arrays of length (y+x)" by first coercing it using that identity (or you could coerce the array), which is a no-op at run time (unless you're in homotopy type theory, but that's another tale for another time).
>>
>>57876123
>>57876371

https://jekyllrb.com
>>
>>57876306
Yeah fuck you too.

Why is HTML unable to do something simple such as
<include href="navigation-bar.html">
? You just take that node and replace it with whatever elements are being included. Why does it need a goddamn external tool to do that, complete with its own idiotic hipster language you gotta buy into?

If anyone's retarded here, its the folks who have been standardizing HTML and still haven't added this simple feature in.

>>57876371
>write a set of scripts that will generate static HTML pages from source and template files.

Actually that's my current situation. I would prefer to write everything in HTML5 without any of these scripts if I could avoid all the stupid repetition.
>>
>>57876125
>>57876414
Specifically, it's the value depended on that's immutable. There's no way to update that length so that the types are inconsistent even though they depend on the same value. If that makes any sense. Modelling a destructive update as a new variable binding that shadows the old one is one way to do that.

If you had something like:
length = readUnsignedInteger();
array = newArray(length);
length += 1;
index = makeValidIndexLessThan(length);

what the types see is:
length = readUnsignedInteger();
array = newArray(length);
length2 += 1;
index = makeValidIndexLessThan(length2);

'index' depends on 'length2' and 'array' depends on 'length' so they are not innately compatible. But there may be an identity you can use to make them so when it is valid.
>>
>>57876414
So it's... a hybrid of static and dynamic types? You put the bounds checking code into the type system and call it dependent types?
>>
File: babbythumbs.jpg (45KB, 600x690px)
babbythumbs.jpg
45KB, 600x690px
>>57876306
>>I don't want to use client smarts
http://www.w3schools.com/howto/howto_html_include.asp
>>
>>57876469
No, not at all. There is somewhat of a relation to dynamic/static, where dependent types make it possible to make more information that is traditionally only dynamic, static.

In a fully dynamic system, both the type of elements of the array and the length of the array would be dynamic. In a more static system, the type of the elements could be static, but the length would have to remain dynamic. Dependent types allow you to make it all static.
>>
>>57875498
A friendly advice.

C and Racket are probably not the languages that will land you more jobs. But are the ones that will teach you the most. Learn them if you can.

I personally like python a lot, haskell is also good. /g/ memes a lot about the last one and that is what monads are about.
>>
>>57876509
How is dynamic information made static when the type is only determined at runtime where values actually exist?
>>
>>57876469
The type system allows you to make a type depend on a value, whether that is at runtime or compile time is completely incidental (some languages don't even have a compile time).

>>57876529
logic
you have to prove your code to the compiler
>>
>>57876490
>they don't even try to search it
Retards the lot of them. Thanks for your generosity anon.
>>
>>57876529
>>57876534
though in simple cases, e.g. >>57876387 , it can just analyse the cases
>>
>>57876538
what are you thanking him for exactly? did you look at the full example?
>>
>>57876534
>allows you to make a type depend on a value
Ahhh, I gotcha.
>>
>>57876538
... you actually think that is a good solution?
>>
>>57876529
Like I said in >>57876414, the type system doesn't know what the value exactly is if it's determined dynamically, it uses a placeholder (free variable). But it knows about relationships between these placeholders and symbolic computation is possible.
>>
>>57876457
I was thinking of bloxsom because muh perl

>>57876461
bloxsom can run either as a dynamic CGI script or it can generate a complete static HTML site. Is there any reason you don't want to use a server-side solution though? There are some very simple/powerful/flexible template engines that serve "static" HTML that was generated on the fly by the server.
>>
>>57876559
>>57876564
>good solution
It's web. It's good enough. You get the convenience.
>>
>>57876562
so for instance, C++'s std::array<T, N>
except because it's logically proven (that it works for ANY t or n)
both T and N can be decided at runtime
>>
>>57876581
you said
>I want my pages to work without javascript.
>>
>>57876566
This sounds a lot like the constraint analysis optimizers do on code

if (x > 10) {
// type of x kind of becomes "int > 10"
} else {
// type of x kind of becomes "int <= 10"
}
>>
>>57876581
>good enough
>needs JS to even load the page
>>
>>57876529
>>57876566
Honestly, I didn't fully understand dependent types until I programmed my own type checker for a simple dependently-typed lambda calculus, and I had to learn about reduction, normal/neutral forms, etc.

>>57876602
They are very closely related.
>>
>>57876123
How about you just write your own God damned preprocessor? Like any moderately ok programmer would have done already instead of complaining.
>>
>>57876602
This is something a dependent system might use, but not for constant optimisation.

Refinement types are a limited subset of dependent types, and refinement types are like this:

type T = { x : int | x < 15 }
T value = 16; // error
>>
>>57876639
if only there was already some kind of .... Hypertext Preprocessor... Maybe with a recursive acronym, since all good projects have recursive acronyms...
>>
>>57876579
Well because every templating engine sucks. They're all quirky in their own ways and just make me waste time learning them and working around their stuff. It's also a dependency that really shouldn't be necessary.

I just want to write pure HTML5 content. I have a lot of metadata encoded in pages using microformats and templating engines and their ridiculous languages basically make me revert back to XML for those anyway.

It's still better than stupid shit like PHP though. HTML should be served by the web server. If I need dynamic content, I'll have the page ask an API endpoint for it via Javascript.
>>
>>57876639
I already did. Had you actually read the post, you'd have realized that's not what I want.
>>
>>57876671
Why bother finding one it's just a single token parser and three fprintf's and an fopen.
>>
>>57876700
>without dependencies
It's a static website. When it's done it's done.
>>
>>57876654
Actually, a compiler for a dependently typed language could do a lot of optimizations with the information it gets. Or, rather, the redundant checks don't need to exist in the first place for the same reasons that they can be optimized out.

A dependently typed language can be compiled and optimized very quickly, assuming you don't expect much in the way of type inference (which involves hard problems like unification and satisfiability - optimizers for less richly-typed languages have to do this themselves).
>>
>>57876675
You're a fucking idiot m8.
>>
>>57876739
no u
>>
>>57876731
>A dependently typed language can be compiled and optimized very quickly
...unless the type signature forms an infinite loop
>>
>>57876731
>Actually, a compiler for a dependently typed language could do a lot of optimizations with the information it gets. Or, rather, the redundant checks don't need to exist in the first place for the same reasons that they can be optimized out.
That's what I mean.
It's partial application of stuff that's known at compile time.

That comes from purity
>>
>>57876461
>Why does it need a goddamn external tool to do that
It doesn't. HTML5 can do that by itself.

PS: Javascript is part of the HTML5 spec.
>>
>>57876812
>Javascript is part of the HTML5 spec.

It can also be disabled.
>>
>>57876750
I have used several different perl web templating modules over the years and in their most basic forms, none of them were more complicated than:
<% content %>
or
['footer']
or even
<link rel='stylesheet' href='<% request.uri_base %>/css/<% settings.style %>'>
but I'm sure that last one was way too fucking complicated of a hipster language for you. get fucked, idiot.
>>
>>57876731
On that note, refinement types are precisely those dependent types for which unification/satisfiability is decidable. E.g. an array of length (x+0) will automatically check as an array of length x because x+0=x is a formula in Presburger arithmetic, which is decidable.

>>57876767
Which is what totality is for.

>>57876777
Well, constant folding only requires purity and totality. Dependently typed languages are a good place to find those, for sure, and such a language could certainly have a way to fold expressions containing free variables (which is usually hard) given identity proofs.
>>
>imperative users will never know of the indexed state monad
>dynamifags will never know of the indexed state monad

>they will never understand the magic of statically checked type changing variables
>>
>>57876836
Yeah fuck you too dickface
>>
>>57876854
Linear types admit strong update, too.
>>
>>57876836
he's right though in that it can be done without them. check it out:

http://stackoverflow.com/q/9001418
http://stackoverflow.com/q/8401113

honestly sounds like a much better option if you're not actually interpolating values into the template. server side includes sounds great too but I don't really understand exactly how included pages work with the parent page. ie not sure if their browsing context is shared or not
>>
File: Screenshot+2016-12-06+10.43.55.png (415KB, 2472x1600px) Image search: [Google]
Screenshot+2016-12-06+10.43.55.png
415KB, 2472x1600px
I'm working on this programming challenge but my program will only return the count for the first term on the list, and return 0 for all other terms. How do I fix it?

This is my program:
from collections import Counter
import re

def openfile(filename):
fh = open(filename, "r+")
str = fh.read()
fh.close()
return str

def removeSpecialChara(str):
# Replace one or more non-word (non-alphanumeric) chars with a space
str = re.sub(r'\W+', ' ', str)
str = str.lower()
return str

def getCount(words,txt):
cnt=0

for word in txt:
if(word==words):
cnt = cnt + 1
return cnt

def main(filename):
txt = openfile(filename)
txt = removeSpecialChara(txt)
textList =txt.split(' ')
word = input("What words would you like to search for? " )
words =word.split(',')
for i in range(0, len(words)):
bins = getCount(words[i],textList)
print(words[i]+" "+str(bins))

fileName =input("What file would you like to open? ")
f = open(fileName)
contents = f.read()
f.close()


main(fileName)
>>
>all these type theory faggots

What's the fucking point?
>>
>>57876933
The root of his idiocy though is the whole "I want something that lets me replace a certain special tag in otherwise normal HTML with content from other files but I don't want to learn about things that do this because they use special tags and that's too complicated"
>>
>>57876977
making programs more well defined
having the compiler do more of the work
>>
>>57876977
Currently, programmers have to do certain things the computer is better at and the computer has to do certain things the programmer is better at. Richer type systems rectify this situation.
>>
>>57876981
>a certain special tag

object/iframe isn't special in any way though

>but I don't want to learn about things that do this because they use special tags and that's too complicated

said he already had a template engine setup but was looking to scrap it

honestly I learned something new today. never thought about using iframes for this purpose. I'm gonna see how well this works out
>>
>>57876977
Faster more efficient production of efficient programs.
Sounds good right?
>>
>>57877022
>Faster more efficient production of efficient programs.
Too bad the types of languages that have these types systems are much more inefficient for other reasons.
Why don't one of you fags create a language more similar to C, but with a richer type system?
>>
>>57877033
Because the processor can't care less about your type system.

The point of C is to be able to see the assembly as you write it.
>>
>>57877033
Because C isn't very good
>>
>>57877033
https://en.wikipedia.org/wiki/ATS_(programming_language)
>>
>>57877045
>Because the processor can't care less about your type system.
So? Your idris or whatever the fuck your writing has to run on a program at some point.
>The point of C is to be able to see the assembly as you write it.
No it's not. Also, with better compiler optimisations, that gets less and less true.

>>57877047
>Because C isn't very good
You can't really argue against the fact that C is one of the fastest (if not THE fastest) general purpose programming languages.
>>
>>57877033
There's absolutely nothing wrong with the type system in C.
It exists to stop basic user error, and can be bypassed entirely if you feel the need.
>>
>>57877077
>There's absolutely nothing wrong with the type system in C.
It gets the job done, but there is nothing saying that it can't be improved upon.
They're constantly adding shit to the type system to aid compiler optimisations.
>It exists to stop basic user error, and can be bypassed entirely if you feel the need.
Yes, I know C, and I know how type punning works. Although I've still yet to come up with many good reasons to type pun.
>>
>>57877045
C also happens to be shit.

>>57877075
>You can't really argue against the fact that C is one of the fastest (if not THE fastest) general purpose programming languages
Nobody wants to argue against that. Wow, a near assembly language with an ultra optimizing compiler is fast! Wow! Let's not make any progress in creating better, less error-prone languages, because C is just so amazingly fast!

>>57877077
>It exists to stop basic user error
It's actually pretty bad at even doing that. You know nothing about type systems if you think C's is even worth mentioning.
>>
>>57877104
>C also happens to be shit.

I know.
>>
Is there a fully statically-typed lisp?

I know that many lisps are optionally-typed. I mean, compiler can infer types and you can declare types too if you want.

How does that compare to haskell and shit? Can Lisp have that milner type inference thing? Can Lisp have dependent types
>>
>>57877100
>Although I've still yet to come up with many good reasons to type pun.

It allows generic typing.
Why do you think qsort only takes a callback function of type int(*)(const void *, const void *)?
>>
>>57877104
>near assembly
C is not "near assembly" though. Stop posting this stupid "portable assembler" meme.
C doesn't even have a real concept of registers, or even things like a runtime stack. All it "allows" (Although it's usually undefined behaviour) for is arbitrary memory access.
>Let's not make any progress in creating better, less error-prone languages, because C is just so amazingly fast!
I was just saying that people should create a C-like language with the "safety" of these type systems that people keep memeing about.
>>
>>57877129
I don't think there is a single lisp that can remotely compare to Haskell, let alone something like Idris, Coq or Agda

How would you type an AST?
>>
>>57877132
Because C is shit and doesn't have proper parametric polymorphism?
>>
>>57877132
That's not what type punning is.
Type punning is taking the direct bit representation of something, and then interpreting it as something else.
An example is the fast inverse square root function, although the way they do it is undefined behaviour.

Void pointers are just a "pointer to an unspecified type".
>>
>>57875383
trying to fix unity's shit so im compiling it. ive found like 5 bugs in a week
>>
File: atomica.png (140KB, 552x798px)
atomica.png
140KB, 552x798px
Back to work on this guy, finally have some time.

UI improvement suggestions?
Should I bother to implement an EQ, don't know if people actually use them.
>>
>>57877203
are the proportions of separate parts of the UI resizeable in the way that foobar allows?
>>
>>57877233
Not yet.

I would love to do this but I made the mistake of using Tkinter as my GUI programming.

It's possible but so fucking tedious and dry, I should get that done though.
>>
>>57877143
With reader macros Lisp is more powerful than any of them (since they would all become subsets of Lisp).
Although I guess you land in a semantic argument of what constitutes 'Lisp code' then.
>>
>>57877312
>Lisp is more powerful than any of them
Not really.
>>
>>57877057
I'm looking at their website at the moment.
What is the deal with functional programming languages and having such horrible syntax?
I know you'll probably say that "you're too used to C-like languages", but really, almost all programmers are used to C-like syntax at this point. It's like they went out of there way to do things that C-like languages don't do, just for the sake of it.

Logical and (&&): andalso
Logical or (||): orelse
Unary negation (-): ~
Entry point of program (main): main0

It's like they don't want any actual programmers to use their language.
>>
>>57877389
C syntax is fucking shit
I would prefer /\ and \/ to && and ||
¬ is better than both ! and ~, but ~ is better than ¬

Haskell has really malleable syntax
>>
Modifying a function to subtract 1 from a number before returning it.

>imperative programming
>add another line of code to subtract one

>functional programming
>rewrite the entire function from scratch because your stateless algorithm wasn't designed to subtract one at the end
>>
>>57877459
Here is your (You).
>>
>>57877389
Yeah, it's not a very usable language. It's more of an example of what is possible; it sits right behind C and C++ in benchmarks even though it's basically the work of one guy. He must have really tried to make it look bad, though, I mean "dataviewt@ype"? Really?
>>
File: 1477183687803.png (534KB, 1156x999px) Image search: [Google]
1477183687803.png
534KB, 1156x999px
>>57877472
>>
>>57877474
You come here, bitch about why everything isn't in the style YOU like it
>>
>>57877472

in Haskell this is just
subtract 1 $
>>
>>57877472
fun = x


fun = x - 1


Wow, that sure was a bitch to do
>>
>>57877459
whoops, I meant ~ is better than !

C or whatever C was ripping off just made shit up
>>
>>57877554
>>57877459
~ is being used for arithmetic negation, not logical negation in ATS. You're comparing it to the wrong shit.
Also, I'm not aware of any mathematicians who write negative numbers with a squiggly line.

In terms of the logical operators, if a standard keyboard had those on them, then maybe I would be for it, as it follows the classic literature more closely, but they don't.
I am certainly not going to use any symbols that require anything more than maybe holding shift and pretty 1 key.
Even then, those symbols are just as arbitrary as the ones being used in C-like languages.
>>
what's the cause when a program randomly crashes?
>>
>>57877676
What are you talking about?

¬ / and \ are all on my keyboard
>>
>>57877679
Literally anything, considering that you have provided absolutely no information.
I'm going to go with cosmic rays though.
>>
>>57877676
>those symbols are just as arbitrary as the ones being used in C-like languages.
No, not at all.
/\, \/ and ¬ are the traditional mathematical symbols for those boolean operations
>>
File: evafanart3.jpg (81KB, 600x888px) Image search: [Google]
evafanart3.jpg
81KB, 600x888px
I'm heavily considering going back to school, either for a certificate at the community college level, or just some post-grad classes.

I'm interested in digital forensics and cybersecurity as general topics. I have a solid understanding of C++, and currently figuring out if I should learn another language, if just the basics.

With that being said, I'd prefer not to be ass-fucked by even more student loan debt, so what steps can I take to better hone my skills without a formal classroom education? I wouldn't apply for the Spring 2017 semester at this point, so I mostly just want to practice and improve in my free time.
>>
>>57877700
well I've made a program in c# and it crashes from time to time. the problem is that it crashed only when I was running the release build, so I have no idea about why it crashed. there was no error message, it was just "there was a problem, windows will have to close it" or something.
>>
>>57877709
>No, not at all.
In principle, every symbol we use is completely arbitrary.
If the person who came up with them decided to use something different, we would instead be using that.
>/\, \/
If you're going to go through the effort to actually talk about those symbols, actually use them: ∧ ∨
>traditional mathematical symbols for those boolean operations
I know. I did do computer science.
But they don't appear on standard US keyboards, so they're not going to be used in programming languages.

>>57877697
>¬ on your keyboard
Liar.
>>
>>57876007
>that piece of software
>that pos
>>
>>57877752
>actually use them
are you really saying /\ is not an appropriate representation of ∧
is this the level of argument you are reduced to

/\ isn't close enough to ∧, so lets just use &&, whatever the fuck that symbol means

¬ is on UK keyboards.
~ is better than !.
>>
>>57877750
Well the specific message is rather important. If it says that the program is not responding its likely an infinite loop.
>>
Quick question, Is this a good way to read a file into a string?

char buf[4096];
int i = 0;
while((buf[i++] = getc(file)) != EOF);
>>
>>57875959
Are you browser anon? Last summer you promised to post a new version. I must have missed it. I really need an update.
>>
>>57877769
>are you really saying /\ is not an appropriate representation of ∧
Yes. On monospace fonts, there is a sizeable gap between the slashes.
>so lets just use &&, whatever the fuck that symbol means
Ampersand means "and", so it's actually pretty obvious. You certainly could have picked a better example.
With your whole "everything must be the same as it was in mathematics" logic, I suppose you think multiplication should be x, ., or the absence of an operator.
We must also write divisions on the line below.
>¬ is on UK keyboards.
I'm looking at standard British keyboard layouts (according to wikipedia) and I'm not seeing it.
>>
>>57877823
Use fgets()
>>
>>57877823
Use fgets.
What you're doing there is pointless, and can overflow your buffer.
>>
>>57877823
http://stackoverflow.com/a/174552/2390624
This.
>>
>>57876080
Bump

I'm also interested.
I want idea guys but for good ideas. Preferably free.
>>
>>57877834
>>57877835
>fgets
oh shit, thank you anons
>>
>>57877828
It's not meant to look exactly the same as the unicode symbol, it's meant to be convenient to type and to look the same, * for example.
It is fucking insane to suggest && over /\ or || over \/

>Ampersand means and
Not at all obvious.
I didn't say or imply everything should be the same as mathematics.


¬ is left of 1, where we also have ` and that third : ish one nobody knows how to use.
>>
>>57877863
>it's meant to be convenient to type
It's less convenient to type than &&. Also, it would be easy to type them in the wrong order when typing quickly, still leading to a valid program and causing subtle and hard to find bugs.
It's the same argument against the = and == operator.
>It is fucking insane to suggest && over /\ or || over \/
You seem to be the only person bothered by it.
>Not at all obvious.
It's not my fault that you're retarded.
>I didn't say or imply everything should be the same as mathematics.
Then why are you pushing for those two symbols in particular?
>>
How do I get scripts in Javascript to interact with each other?
I've got a fairly comprehensive WebGL engine meow but it gets messy writing a game inside it
>>
>>57877909
Because those are the mathematical symbols, obviously. You seem to want to complain people aren't "going with the mainstream standard (C)" but that didn't apparently apply to C.
>>
>>57877811
there was a previous version that worked without problems.
in the new version, the program creates a temporary folder, saves a dll inside that folder and loads the dll from there.
I've been running the debug mode for 10 minutes and nothing happened yet.
>>
>>57877929
>but that didn't apparently apply to C
C (and languages before it) had to do that because of necessity. Everything was based off of ASCII, so they weren't going to put a bunch of yet-to-exist unicode shit into their languages. Also, there is no point using a couple of symbols if you can't get the entire set of them.

In the case of ~, it was already being used by C for bitwise negation. Since btiwise and logical negation worked on integers, they needed different symbols.
>>
File: ferris.png (502KB, 603x783px) Image search: [Google]
ferris.png
502KB, 603x783px
Rate my AoC Day 7 pt 1!
int tls_support(char *str)
{
unsigned i, bracket = 0; /* bracket flag */
unsigned tally[2] = { 0 }; /* outside, inside */
char *tok = strtok(str, "[]");
while (tok != NULL)
{
unsigned len = strlen(tok);
for (i = 0; i < len - 3; i++)
if (tok[i] == tok[i+3] && tok[i+1] == tok[i+2]) /* 'abba' */
if (tok[i] != tok[i+1]) /* 'aaaa' */
tally[bracket]++;
bracket = !bracket; /* flip */
tok = strtok(NULL, "[]");
}
return (tally[0] && !tally[1]);
}
>>
>>57877824
http://pastebin.com/H4HUmW4R
>>
>>57878205
Thanks anon. Appreciate it.
>>
File: lerp.png (107KB, 959x1039px)
lerp.png
107KB, 959x1039px
R8


type LerpInterpolator (xD:double, yD:double) =

let Lerp (x:double, y:double, t:double) =
(x * (1.0 - t) + (y * t))

member public this.Eval(t:double) = Lerp(xD, yD, t)


type Vector5DLerpInterpolator (xD : Vector5D, yD : Vector5D) =

let xInterp = new LerpInterpolator(xD.X, yD.X)
let yInterp = new LerpInterpolator(xD.Y, yD.Y)
let zInterp = new LerpInterpolator(xD.Z, yD.Z)
let aInterp = new LerpInterpolator(xD.A, yD.A)
let bInterp = new LerpInterpolator(xD.B, yD.B)

let Vector5DLerp (t:double) =
new Vector5D(xInterp.Eval(t), yInterp.Eval(t), zInterp.Eval(t),
aInterp.Eval(t), bInterp.Eval(t))

member this.Eval(t:double) = Vector5DLerp(t)

>>
>>57878171
what does it do
>>
>>57877973
I think windows may be deleting the temporary folder sometime after I start running the release build. does this even make sense?
I load the dll right after I save it, so I thought there wouldn't any problem.
>>
Hourly reminder that if you don't use K&R style you're a degenerate.
>>
>>57878421
except { on newlines for function definitions, which is retarded
>>
var express = require('express');
var path = require('path');
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var app = express();

var port = 3000;

var dataArr = new Array;

var url = "https://boston.craigslist.org/search/sss";
var localCl = "https://boston.craigslist.org";

//fetch target page
request(url, function(err, resp, body) {
var $ = cheerio.load(body);

//going through each listing and making listing objects
$('.result-row').each(function(i, listing) {
var listingHtml = $.html(this);
var $2 = cheerio.load(listingHtml);
var listingObj = new Object;
listingObj.title = $2('.result-title').text();
listingObj.price = $2('span .result-price').text();
listingObj.pid = $2('.result-row').attr('data-pid');
listingObj.rePid = $2('.result-row').attr('data-repost-of');
listingObj.location = $2('.result-hood').text().trim().replace(/\(|\)/g, "");
listingObj.time = $2('time').attr('title');
listingObj.compTime = $2('time').attr('datetime');
listingObj.link = localCl + $2('p a').attr('href');

request(listingObj.link, function(err, resp, body) {
var $3 = cheerio.load(body);
var replyLink = localCl + $3('#replylink').attr('href');
listingObj.text = $3('#postingbody').text();

request(replyLink, function(err, resp, body) {
var $4 = cheerio.load(body);
listingObj.phone = $4('.reply-tel-number').text();
listingObj.email = $4('.anonemail').text();

console.log(listingObj);
});


});
});
});

app.listen(port);
console.log('server running on ' + port);


this code is breaking because of the nested callbacks where I'm making requests. How would I refactor this to actually work? It's a craigslist scraper
>>
>>57878465
FUCKING SYMMETRY ANON. It's a virtue in itself.
>>
Is anybody here versed in the math behind cloth/hair physics??? I understand that the physics operate on the mesh of the object, but I can't figure out how it does it independently of the animation (i.e when the character moved slightly) without calculating a velocity every frame...

For reference, this is what I'm talking about. It's only very subtle on the hair but more noticeable on the coat.

https://youtu.be/Kq3Rc9DhuUc?t=2m46s
>>
>>57878465
>except { on newlines for function definitions
There is a reason that they do that, albeit an outdated one.
It's fine that functions are treated differently though, because in C, functions are different and cannot nest.
>>
File: 1478214500707.jpg (60KB, 640x640px) Image search: [Google]
1478214500707.jpg
60KB, 640x640px
>>57878278
>>57877973

Debug your release build using PDB
>>
>>57878504
Damn, that is a horrid way to do that. There's much better NPM modules that do similar. Use them.

Requests within loops are very much frowned upon.

But cheerio is fun! I'm doing a bit of website crawling within my next React Native iOS/Android app. Implementing it has been a breeze with the module `cheerio-without-node-native`
>>
>>57876123
What is PHP
>>
>>57878504
What is new Promise
>>
>Because event processing must be performed on the main thread, all callbacks except for the error callback will only be called on that thread.

>Do not assume that callbacks will only be called through either of the above functions [glfwPollEvents, glfwWaitEvent]. While it is necessary to process events in the event queue, some window systems will send some events directly to the application, which in turn causes callbacks to be called outside of regular event processing.

YOOOOOOOOOOOOOOOOO
>>
>>57876123
Yes, but only in Chrome. http://webcomponents.org/articles/introduction-to-html-imports/
>>
>>57876639
>Don't reinvent the wheel
>Reinvent the wheel

Never change, /g/
>>
>>57878942
>reinvent the wheel
>looking for something for 10 minutes that saves you 5 minutes of work
There are limits anon. You don't need to have libraries do every piece of the code for you.
>>
File: 1448433324525.jpg (51KB, 433x436px) Image search: [Google]
1448433324525.jpg
51KB, 433x436px
> learning some framework
> coding dirtier and dirtier, drifting away from the good practice god to make the damn thing work
> mfw pushing my code to git for everyone to see how a piece of crap i am
meh, it's not like people read my shit
>>
>Working with an old codebase
>Weird bug that is massively noticeable and causes several other problems
>Can kind of work around some of the issues but the workarounds are typically kludgy and dont actually complete fix anything anyway
>Every time you find something that might be causing the bug it ends up not being that
Why.
>>
File: ferris2.jpg (45KB, 720x689px) Image search: [Google]
ferris2.jpg
45KB, 720x689px
>>57878171
And here's AoC day 7 part 2.
I'm a 3 star programmer now!

int ssl_support(char *str)
{
unsigned tally = 0, idx = 0, bracket = 0; /* bracket flag */
char *arr[2][1024] = { { 0 } }; /* outside, inside */
char *tok = strtok(str, "[]");
while (tok != NULL)
{
arr[bracket][idx] = tok;
if (bracket) idx++;
bracket = !bracket; /* flip */
tok = strtok(NULL, "[]");
}
unsigned i, j, k;
for (i = 0; arr[0][i]; i++)
{
char *a = arr[0][i];
unsigned len = strlen(a);
for (j = 0; j < len - 2; j++)
{
if (a[j] == a[j+2] && a[j] != a[j+1]) /* 'aba' */
{
char b[4] = { a[j+1], a[j], a[j+1], '\0' }; /* 'bab' */
for (k = 0; arr[1][k]; k++)
if (strstr(arr[1][k], b)) tally++;
}
}
}
return !!tally;
}
>>
>>57878661
now it's been running for 1 hour and nothing happened.
I think god is playing tricks on me.
>>
>>57876854
>monad
buzzword
>>
>>57877366
why not
have you learned lisps?
>>
>>57877136
Well, it's called rust. And it's shit. So I don't think you can compromise on these two things.
>>
>>57875383
Is there a simpler way to swap each two elements functionally, such that
'(1 2 3 4)
becomes
'(2 1 4 3)
? (That is, without using the index.)

(define (transpose-list ls)
(let l ([ls ls] [acc '()])
(match ls
[(list-rest a b tail) (l tail (cons a (cons b acc)))]
[(list) (reverse acc)])))
>>
>>57879549
>without using array indexes

why are functional programming zealots so autistic?
>>
File: 1457032047629.png (71KB, 251x251px) Image search: [Google]
1457032047629.png
71KB, 251x251px
>>57879568
Get the fuck out sperg
>>
>>57879549
I don't know the best way to do this in Lisp, but in Haskell it would be:
swapEachTwo :: [a] -> [a]
swapEachTwo (x : x' : xs) = x' : x : swapEachTwo xs
swapEachTwo xs = xs


>>57879568
Doing it with indexing would be inefficient.
>>
>>57879605
Thanks, that's essentially what I have posted in Racket, except in scheme/Racket one typically "cons" onto the front of the accumulator list, and reverses the accumulator when finished.
>>
>>57879628
>except in scheme/Racket one typically "cons" onto the front of the accumulator list, and reverses the accumulator when finished
Sounds expensive.
>>
>>57879628
>>57879639
Also, why can't you use recursion? You have a tail call modulo cons there.
>>
>>57879639
I cannot write with certainty, however, I think it's the fastest way to manipulate a list, since you'd only need to reverse once at the very end.

>>57879653
The (let loop () ... (loop)) form is a form ol recursion.
>>
>>57879660
>I cannot write with certainty, however, I think it's the fastest way to manipulate a list, since you'd only need to reverse once at the very end.
It's still going through the entire list twice for no reason.

>The (let loop () ... (loop)) form is a form ol recursion.
But why not use recursion directly, without that pointless accumulator shit?
>>
>>57879665
> It's still going through the entire list twice for no reason.

Wouldn't it not be tail-call optimized if the last call in the function body isn't the function itself?

> But why not use recursion directly, without that pointless accumulator shit?
What do you mean?
>>
>>57879628
you dumbass, you know foldr is a thing right?
>>
File: queeeee.gif (239KB, 500x419px)
queeeee.gif
239KB, 500x419px
>>57879711
Can you show me how to reimplement my procedure using foldr?
>>
>>57879705
>Wouldn't it not be tail-call optimized if the last call in the function body isn't the function itself?
That's why I said tail call modulo cons. If the recursive call is also the list parameter of a series of cons, it can still be optimized like any tail call.

>What do you mean?
Exactly as in >>57879605.

>>57879711 is also right.
>>
>>57875383
working on a console chat program using c++ and the winsock api. kind of neat so far but all i have is a basic handshake.
>>
>>57879549
(define (transpose-list lst)
(if (null? lst)
'()
(cons* (cadr lst) (car lst) (transpose-list (cddr lst)))))
>>
>>57879777
Thanks.

>>57879747
Is >>57879777 tail call modulo cons?
>>
>>57879832
Theoretically, yes, in practice, I don't know. If you wrote it as
(cons (cadr lst) (cons (car lst) (transpose-list (cddr lst))))
it would be.
>>
Making Asteroids in OpenGL. 350LoC for this desu
>>
File: 1455986423962.png (400KB, 825x713px)
1455986423962.png
400KB, 825x713px
>>57879711
>>57879737
Bumping this again, somebody want to demonstrate this? (transpose-list with foldr)

>>57879851
Ah I see. Unfortunately cons is typically limited to two arguments. I'll have to read more about tail call modulo cons... This looks very useful for simplifying some procedures.
>>
>>57879862
Forgot image
>>
Good books on general OOP best practices and whatnot?
Good books on java ? ?
tia
>>
File: meme-19.gif (80KB, 170x207px)
meme-19.gif
80KB, 170x207px
>>57879883
samefag here

>>57879851
sorry i misread your code, disregard the comment about cons.

Though, this leads to another question: multiple cons is still tail call modulo cons?
>>
>>57879883
this image pisses me off
>>
>>57879317
>>57878171

whats AoC and why do you keep posting that gay homosexual cat thing?
>>
Is object oriented programming a meme in lisp?
aka, is CLOS a meme?
>>
>>57879926
>inb4 the entirety of lisp is a meme
>>
is there such a thing like foldl but with a trinary function as input, with one of the inputs being the accumulator?
>>
>>57879883
sorry pham, I tried, its impossible unless you do a hack like local (setf)ting
>>
File: read dat sicp.jpg (66KB, 800x534px) Image search: [Google]
read dat sicp.jpg
66KB, 800x534px
>>57879926
No clue, but racketfag here. It's pretty decent in Racket. Maybe you just need some time to process the confusing parts of CLOS (OOP in general is confusing in lisps I think...).

>>57879973
O-oh okay. Thanks for trying!

>>57879958
So you want to use what is in the accumulator to decide what to do next?
>>
What does /g/ think about Go? I've been learning Elixir on the side for fun, but I just got a job for when I graduate in May and know I'll be using Go a lot. Is it worth making that my "main" language to learn from now on?
>>
>>57879958
Control.Applicative
>>
>>57879988
with a trinary foldr, your function could of been implemented easily
the problem is with odd lenghted lists
>>
>>57880001
applicatives are for injecting functions into boxes and still being able to use them
nothing to do with having a trinary function in the folding
>>
>>57880010
I've been ignoring odd-lengthed lists entirely.

Not particulary, but else where somebody suggested this solution:

(define (transpose-list ls)
(append* (map reverse (chunk* 2 ls))))
>>
>>57880036
*not particularly related
>>
>>57880036
actually, the problem seems to be the data structures you're using
why use a 1d array?
use something like

((a . b)
(c . d)
(e . f)
...

and then easily, use rassoc or assoc
>>
>>57880081
*1d list?
>>
>>57880081
Background on why I implemented a transpose-list procedure -- I was given a hexdump and told to figure out its meaning. I found each byte was switched with its neighbor, thus the need for a transpose-list procedure.

So If I were to use an associative list for this, I would have to "zip" up the list before transposing pairs, then "unzip" the pairs afterwards. That seems counterintuitive if not excessive.
>>
I've been using gprof for profiling in C but apparently it wets its bed at system calls and I'm using sockets.

What's the simplest alternative?
>>
>>57875383
I'm trying to make a script that polls the screen periodically for a color, then beeps when it sees it. Unfortunately I don't understand the syntax of autohotkey.

>Error at line 8.

Line Test ;
Error: The leftmost character above is illegal in an expression.

The program will exit.
>>
File: IMG_1898.jpg (85KB, 680x680px)
IMG_1898.jpg
85KB, 680x680px
>>57880226
Use an editor with syntax highlighting for autohotkey...
>>
>>57875383
AFAICT there is no simple way to handle multiple protocols on a single port in Golang.

I have to tear apart the request header myself in order to tell the difference between what's plain http and what's upgraded to websockets.

:|
>>
>>57880236
I tried jedit, but it was equally infuriating
>>
>>57880236
also which editor would that be?
>>
>>57879998
Javascript and Golang and the greatest modern cancers, either is suitable as a main language.
>>
>>57880213
Valgrind.
>>
File: 1469473621356.png (577KB, 480x476px)
1469473621356.png
577KB, 480x476px
move.w    #$9300+(((LENGTH)&$FF)>>1), VDP_CTRL_PORT
move.w #$9400+(((LENGTH)&$FF00)>>9), VDP_CTRL_PORT
move.w #$9500+((SOURCE_ADDR>>1)&$FF), VDP_CTRL_PORT
move.w #$9600+(((SOURCE_ADDR>>1)&$FF00)>>8), VDP_CTRL_PORT
move.w #$9700+((((SOURCE_ADDR>>1)&$FF0000)>>16)&$7F), VDP_CTRL_PORT
move.l #($80+((DEST_ADDR&$3FFF)<<16)+((DEST_ADDR&$4000)>>14)+((TARGET&$4)<<2)+((TARGET&$3)<<30)), VDP_CTRL_PORT


I fucking LOVE bitwise operations!
>>
>>57880259
No clue, but Googling autohotkey syntax highlighting yielded this https://github.com/ahkscript/AutoHotkey-Editors

It has a list of editors that are designed for autohetkey, can support autohotkey with modification, or support autohotkey ootb.
>>
>>57879339
welp, now I deactivated optimization and didn't merge some dlls into the exe, and I'm running 8 processes of the program.
I don't know what happened but it seems to be working now, for some unknown reason
>>
>>57880286
thanks
>>
>>57880286
that looks complicated, also I don't have EditPlus 2, I have 3.
>>
File: trash.gif (3MB, 390x293px) Image search: [Google]
trash.gif
3MB, 390x293px
>>57880333
>Dedicated AutoHotkey Editors:

> AHK Studio - Forum - Scintilla based editor written in AHK for AHK
> SciTE4AutoHotkey - forum
> QuickAHK - forum

kys
>>
my brogramming history:
ActionScript 2 -> Ruby -> JavaScript -> Python 3
I realise all of them are memes and I want to learn a real language. Regarding these previous languages, I've only learnt bits and pieces by reading random tutorials and dicking around, trying stuff and seeing what works.

So riddle me this; if I read pic related from cover to cover, will I get anywhere? Don't want to waste my time
>>
>>57880378
>Don't want to waste my time
>ActionScript 2
>Ruby
>JavaScript
Hmm
>>
>>57880434
That's exactly what I mean. I wasted my time with those gay languages and don't want to fuck myself in the ass again.
>>
#def do_twice(f ):
# f()
# f()

def print_spam():
print('spam')

def do_twice(function, value):
function(value)
function(value)

This is my code

And this is my error.

>>> from Think_python import*
>>> do_twice(print_spam(), 'spam')
spam
Traceback (most recent call last):
File "<pyshell#161>", line 1, in <module>
do_twice(print_spam(), 'spam')
File "C:\Users\Serdar\AppData\Local\Programs\Python\Python35\Think_python.py", line 22, in do_twice
function(value)
TypeError: 'NoneType' object is not callable

what am I doing wrong. it is a nonetype Error, but then what kind of function should I have implemented?
And I seem like I do not have understood the code of do_twice...
>>
>>57880454
Okay here is my programming history
PHP -> JavaScript -> Java -> C++ -> Python -> C -> Haskell

Read this the way you want.
>>
>>57880491
do_twice{print_spam(), 'spam')


evaluates to

do_twice(None, 'spam')


which runs do_twice as

None('spam')
None('spam')


None isn't callable.

If you remove the parenthesis after print_spam in do_twice(print_spam(), 'spam') (so it looks like do_twice(print_spam, 'spam') ) You'll get a different error.
>>
>>57879605
>doing it with index would be inefficient
But you're using haskell. Clearly you've given up on the idea of being efficient right?
>>
>>57880286
>ahk editors
Nice. Maybe il actually bother now
>>
>>57879916
Advent of code.
Daily challenges for December 1-25
Its a Christian thing.
They will be done soon.
Just wait for Ramadan.
And then hindi new year. They go hard in April.
>>
/g/ should start it's own Christmas themed programming challenge... without a requirement to have a Reddit, Twitter, Gmail, or Github account tied to it.
>>
>>57880980
someone should make a pastebin of the aoc challenges so everyone can read them without having a *-account. Competein is for losers anyway
>>
>>57880985
>>57880985
>"""someone"""

why doesthis trigger me so hard .. ?
>>
Is any class that overloads () considered a function object?
>>
>>57880980
>pajeet board
>Christmas
>>
>>57876207
have you looked at the output of a C++ compiler? It is pretty much zero overhead in reality. In fact, compilers these days are so crazy, they can even devirtualize, so that even vtables sometimes become a zero overhead abstraction.

C++ is not so limited because inheritance and virtual functions can largely be replaced by generics. I've written quite a bit of low-level code running on 1MHz microcontrollers in C++ with generics. Yes, I avoided vtables. Yes, if you mandate that I have to use "OOP to its fullest potential" or whatever, then it's not a zero-overhead thing, but I think that's silly. BTW, vtables aren't that expensive, even on a 1MHz 8-bit AVR with 1.5KiB RAM it's pretty ok to use them.

OOP is really not in direct opposition of high performance at all. There is merely a very small amount of friction that can be easily overcome (that is inherent in OOP) and then there is another relatively small amount of friction inherent in C/C++ (but not OOP) that can also be overcome (at some loss of convenience.) Yes, I've seen all of actons talks as well as Blows.

If you want to see something that is *actually* in direct opposition to high performance, look at some other languages that use e.g. garbage collection, dynamic typing, ..., even vtables, as easily avoidable as they are, are such an imperceptibly small overhead compared to these that it barely registers.

It's not OOPs task to give the compiler more power/opportunity for optimization, it should merely not INHIBIT the compiler from optimizing as much as it could without OOP. The point of OOP is after all adding structure for humans. And in 99%+ of the cases it doesn't. In C++ some extra effort is required sometimes to avoid overhead (like the SoA/AoS parameterization, making member functions const etc) but again, that is not the fault of OOP as such.

And practically, C++ code runs essentially as fast as C code, and if you do find that there is overhead, you can seamlessly drop down to plain C.
>>
File: 1461131877335.png (377KB, 500x654px) Image search: [Google]
1461131877335.png
377KB, 500x654px
I'm attempting to create a neural network with genetic like evolution of the weights.

So far I'm getting no improvement on overall fitness. If anyone can see any problems with my code that would be great.

https://github.com/Nathan-Devery/NeuralNetwork
>>
just posting to say my code's been fuckin' fine lately, every day i've written a worthwhile component or piece of technical prose.

never mind my obvious mental health difficulties and lack of, how you say, attaining of education related paperwork, i just might escape this bunghole current existence alive.

damn it feels good to reach a high plateau.
>>
>>57881137
Good to hear dude, keep at it.
>>
>>57881137
Good for you anon, keep it up.
>>
>>57881097
solid post, agree with pretty much everything. what do you do for a living, if i may ask?

>>garbage collection
this is a lazy, piece of shit idea that refuses to die because hardware is mercifully fast enough for it to not be an issue in most cases. any systems language worth its salt should either 1.) allow manual memory allcation, even though that's error-prone, or 2.) have a type system rich enough to infer when objects have gone out of scope automatically. GC is one of the main reasons i have less respect for software people than hardware people
>>
>>57881097
>it's pretty much zero overhead in reality
That is if you only look at the calls directly associated to the OOP nature. Not if you look at what could have been generated for the same task.
>overhead
That's the wrong way of putting it.
Question why people move away from OOP when performance really really matters though.
Or give me a counter example.
A high performance system that's at the top of the industry when it comes to performance that abides by an encapsulated OOP model.
>>
How do you get good at keeping code organised

I always start off with good intentions but then I get lazy and suddenly everything is spaghetti
>>
do c++ programmers considers reference counting as garbage collection?

asking out of curiosity since this isn't obliviously clear to me
>>
>>57881293
i don't really consider it GC, as it works on the objects individually (as opposed to stop-the-world mark-and-sweep, etc.). it's also the only kind of GC that Rust supports
>>
Fuck that loop macro.
Is there anywhere I can extensibly learn it?
>>
>>57881252
plan your program architecture and interfaces/functions out using pencil and paper before writing any code. i often spend just as much time doing this, if not more, than the actual coding. afterwards, writing the code should be fast and easy
>>
>>57881326
thank you friend

i guess the ability the to solve cyclic references necessarily requires a more heavy handed approach, where in c++ this is by definition disallowed?
>>
>>57881248
>if you look a the calls
Jesus. Sorry I'm tired. I mean instructions. Following the vtable pointer etc.
>>
>>57881293
It's explicit.
Every point where your program will (potentially) deallocate is known.
It's not deferred like GC.

And maybe from others point of view its far simpler. Which might be relevant. But I don't think that's important.
>>
File: 1369225153677.gif (2MB, 150x173px)
1369225153677.gif
2MB, 150x173px
>>57879901

Ignoring the mountain of includes, I really like your formatting. It's so pleasing to look at.
>>
>>57881367
>not using Visual Paradigm and just converting the diagrams to code
>>
>>57881367
also what i do is every time if my code is feeling too complicated is taking a break and returning in a role of an editor (in the sense of traditional publishing)

usually im able to reign the complexity into something much more manageable
>>
Is using SO_REUSEADDR bad practice?

I have it set in my development code since I restart the server application I'm working on often, but should I keep it later?
>>
>>57881230
Numerical analysis for simulations (which is neat) but occasionally I have to do fortran (which is not.) Have a degree in applied maths

I don't think the idea of garbage collection is too terrible, there is a place for it in less performance-critical applications. But I do think that garbage collection is actually just a partial solution (that of memory management) to a much more general problem (that of resource management) which, if solved, will either make GC as we use it today unnecessary or at least change how we use it. Maybe rust is on the right track?

>>57881248
What could have been generated for the same task... based on what alternative non-OOP representation? If you compare a straight-forward C (non-OO) and C++ (OO) representation, you will find performance to be the same. If you propose some alternative representation like e.g. an AoS<->SoA transformation or some other kind of transformation that may make the data more cache-friendly, then sure, you'll win.

A high performance system that's at the top of the industry that uses OOP? Oh, I don't know, so many. Any browser out there, basically any game out there, many operating systems that are out there, a large majority of the embedded systems out there, etc. But again, it depends on how strict your definition of "encapsulated OOP model" is, if you say that some of these don't count because they consciously avoid vtables (and hence are not OOP), then, well, you are right by your definition (which I don't agree with)
>>
>>57881418

VHDL a best. :^)
>>
>>57881437
CERNs data analysis framework used for the LHC too, btw

and many many numerical simulations that are out there that are used in meteorology, astronomy/cosmology etc

tensorflow, as well as most other things google created, from their database, search algorithm to their distributed filesystem

CUDA is sorta C++ (a subset, but close enough I guess)
>>
>>57881466
i program all my software in vhld since machine language is for wannabe hackers
>>
>>57881471
its as if OOP is an useful tool when you need it and not a hewn in stone philosophy where you got to go full enterprise java all the time
>>
>>57881370
no version of C++ that i know of allows this, but i could be mistaken. the way that some newer languages like Swift choose to solve cyclic references is by adding richer type information. they let you define "strong" and "weak" references, and as long as the cycle isn't composed of only strong references, it can be broken along a weak one and the entire cyclic structure eventually collected.
>>
>>57881541
Wait, what?

/dpt/ told me I was supposed to hate it no matter what, and that it can't be useful ever.
>>
>>57881552
eyy thems them breaks friend
>>
>>57881370
What is by definition disallowed? Cyclic references or garbage-collection? Neither is disallowed by the C++ specification, you are free to make as many cyclic references as you'd like, and you can make a C++ implementation that has a garbage-collector (and delete/delete[] can be a no-op). In fact, microsoft actually made something like that (but with an extension to c++, not staying withhin the standard):

https://en.wikipedia.org/wiki/Managed_Extensions_for_C%2B%2B
>>
>>57881579
apparently this even continues to exist even today:

https://en.wikipedia.org/wiki/C%2B%2B/CLI

waddya know. Microsoft, eh?
>>
>>57881544
>>57881579
oops, i was wrong. C++11 supports full refcounting with shared_ptr and weak_ptr for breaking strong cycles. further reinforcing the stereotype that if an idea exists, it's probably implemented in C++ somewhere :)
>>
>>57881639
heh i was about to ask a question about this since that felt a bit too hardcore for even the c++ spec

im sure there certainly _exists_ an c++ non-microcomputer compiler where that sort of behavior is allowed but im glad its nonstandard :-)
>>
>>57881681
allows what?
>>
File: 1399718486462.gif (12KB, 250x242px)
1399718486462.gif
12KB, 250x242px
Can programming cure depression?
>>
>>57881731
Sure.

Here's how a feel learning to deal with a new set of problems:

https://www.youtube.com/watch?v=DTtZ1ck8YzE
>>
>>57881507

If your software cannot adequately be described in a single schematic, what good is it?
>>
>>57881731
no
try drugs instead
>>
>>57881731
if you enjoy programming, sure
>>57881790
but rather do this first
>>
>>57881731

real-talk:
head over to /fit/ instead and clean up your diet & start working out

more sleep, regular exercise and a cleaner diet will do wonders for your mental performance, motivation & well-being.
>>
>>57881790
and don't do conventional shitty antidepressants, they have a lot of undesirable side effects
just stick to something better, do your research first of course
>>
>>57881844
>just stick to something better
Such as?

>>57881731
It probably can, but it probably won't.

For me, any time I'm doing something enjoyable and productive, I'm not depressed, so programming can sometimes solve that issue temporarily. If you make a gainful career out of it, I suppose you could call that a cure.
>>
>>57881844
as a person whose beat depression its also completely attainable. remember there are no one-fix onel-size-fits all solutions but they are rather tools you can use day-to-day
hell i dont exercise or eat well but im ok now
>>
>>57881881
what im saying is embrace buddha
>>
>>57881437
>many os'es
Really? Any examples?
>CERN
More specific maybe? Perhaps open source examples of what you mean? Just because someone labels something as OOP doesn't mean it is. I suggest you read more about OOP and its stated goals to understand it if you can somehow claim OOP projects don't compromise heavily for their performance intensive parts.
>aos vs soa
Well naturally for any large scale processing we're soa. That's what computers are made for. Aos would just be a headache to work with.
>how strict I am
Yes. Of course. If I make the incredibly lose claims that a object oriented language is any language that lets you have member functions with implicit or explicit this pointers it'd be very hard to find non-oop. C would fit that category. And given the initial "C with objects" start of C++ that's clearly not the right way to specify it.
Yet many people do find that as soon as the this pointer is implicit its OOP. It's very annoying because they're arguing for something they don't understand.
Good examples of genuine OOP is often gui applications. You have objects which encapsulate all their data. You even go to the extreme and use setters and getters. If you wish to do any implementation code for the UI you tend to assign 'listeners'. Objects containing virtual functions which get assigned to the widgets.

And I haven't honestly looked too much into the asm representation of that but I think you'd understand (you give a decent impression) how when you start making things like listeners you've already bloated your objects to a point where you have massive amounts of redundant state.
Which is not conducive to low level programming. You rarely find that OOP languages strip away fields that aren't used for specific cases and do the clever pointer arithmetic to mask an object with a lesser use case as a larger object where possible.
If that were the case then maybe I'd be more inclined to accept your ideas.
>>
>>57881880
>just stick to something better
weed friend
>>
New thread:

>>57881933
>>57881933
>>57881933
>>
>>57881940
I don't mind your OP, but please don't make threads so early, especially since it's morning in burgerland and the thread is quite slow.
>>
>>57881880
well, what would be the other meaning of the word "drugs" if we aren't talking about "medicine"?
>>57881907
not really talking about that.
serotonin inhibitors would be a lot better.
>>
>>57881895
> examples
windows, most OSes running on game-consoles etc (e.g. all the nintendo stuff, most of the microsoft stuff, ...)

> CERN
CERNs framework is called ROOT I think you can look it up

> for any large scale processing we're soa

There is no clear general answer for soa<->aos, sometimes aos is a big perf win (e.g. depending on the "hotness" distribution of members, whether SIMD can be applied to the whole struct, whether SoA implies a penality because the collection of the relevant members ends up being a complex process (can sometimes happen in ECS) etc). Prefetching capabilities of the CPU also come into play and make the situation even more complex. Highly regular accesses into AoS that skip cold members can also result in 100% optimal prefetcher performance.

What I think is pretty clear though is that aos is always the more readable, obvious thing to a human. I've never looked at a piece of AoS-based code and thought "this would be clearer as SoA" and I've never looked at a piece of SoA code and didn't "re-assemble" it into an AoS representation in my mind before I felt I properly understood it.


I personally think a language that does not support virtual methods, multiple inheritance et al can still be OOP. Maybe my definition of OOP is significantly laxer than yours. OOP to me is really mainly the ability to

- encapsulate state along with methods that belong to that state and act upon it (basically a class; defines both the members and the methods acting on it)
- inheritance is kinda a part of it, but different languages do inheritance differently (multi vs. singly, extending vs. encapsulating, "prototypal inheritance" etc, and I give all of these a pass)

e.g. I would still give Go a pass as an OOP language, though it lacks a lot of those things.

In fact, I personally think that if you use multiple inheritance and virtual methods, it's kinda a code-smell...
>>
>>57881895
Also, I don't think there is anything in the way for observers to be a zero-overhead abstraction (e.g. just make the observer a template parameter, and no virtual methods will be required)

if you use them to introduce redundant state, that is kinda your fault.
>>
is there a difference between these?
float result = log10(x) / (float) log10(2);
float result = (float) log10(x) / (float) log10(2);

i_result = (int) result;


the first gives me i_result=0 for x=2

the second gives me the expected 1
>>
>>57882045
what is the language and definition of log10
>>
>>57882010
>Windows
Win32 has an interface which is entirely C. Uses 'handles' and really doesn't allow you to do any OOP for interfacing. I don't know about the windows source though.
>root
I did find that.
It's very hard to pinpoint the performance heavy parts quickly. I'll do that later.
>>
>>57882062
I'll continue this post later.
>>
>>57882057
math.h in C I think.
or C++
>>
File: 1473863289691.jpg (183KB, 640x931px) Image search: [Google]
1473863289691.jpg
183KB, 640x931px
Can you program on non -Android phones?
What are some interpreters?
>>
>>57882105
Why would you program on a phone?

You're better off learning soft skills and doing other research if you're somewhere you can only use your phone.
>>
>>57882118
>soft skills
What are soft skills?
>>
>>57882143
Things like how to:
>work with a team
>interact with other humans successfully
>communicate in emails with appropriate tone by paying attention to word connotations

For example, I believe your time would be better spent in transit reading something like "How to Win Friends and Influence People", because that's going to help you tangentially with anything you do in programming, whether that's freelance in your pajamas or working with a team in an office.
>>
>>57882088
log10 returns a double
log10(x) / (float) log10(2) is troublesome because the numerator has more precision than the denominator

indeed the results, are (before casting to int)

log10(2) / (float) log10(2) = 0.99999995242670691730779708450427
(float) log10(2) / (float) log10(2) 1.00000000000000000000000000000000


tip: use
printf("%.16\n", f);

to print f to 16 decimal places

my recommendations:
1: don't cast either log10s to preserve precision
2: cast both log10(x) and log10(2) to floats, as you have done in the second method


it seems you are trying to compute integer binary logarithms, so the following is the best option: https://graphics.stanford.edu/~seander/bithacks.html#IntegerLog

obviously, this is cryptic. it is also VERY fast

a slower and more understandable method is to right shift x by 1 (equivalent to division by 2) until x = 1
int log2(x) {
int n = 0;

while (x > 1) {
n += 1;
x >>= 1;
}

return n;
}
>>
>>57882319
by integer binary logarithm, do you mean the smallet binary number of which logarithm covers the input x?

I am trying to find a functio to map
1->0
2,3->1
4,5,6,7->2

which mathematically should have integer values for the binary numbers, but I do not know whether floating point always will cause issues.

does double/double or float/float ever evaluate to less than the expected value for binary inputs?
>>
>>57882431
>>57882319
the latter example looks like it does just that, either way. So I might use that. Thanks.
>>
>>57882431
>>57882441
binary logarithm is log2(x)

this is exactly what you're doing, i think you just don't know it yet

i recommend the last 2 options i gave (the url or the function)
>>
>>57881132

There are several bad decisions there. I'll point out the three worst.

With your neural network implementation, all weights have a range of [0, 1). Your outputs are biased toward getting smaller after each successive layer.

Your crossover function only uses the two best individuals as parents. This makes it far too easy to get stuck in a local optimum. Your algorithm is crossing over the same two individuals tons of times and throwing away everything else. This is the most likely reason you see no fitness improvement.

Your fitness function only tries one input value. Without testing fitness on a broader range of values, you will probably get an answer that doesn't generalize.
>>
>>57877033
That's what Rust is for.
>>
>>57879450
>> It's shit
Forgive me, but that's a statement that cuts a bit short. Mind to elaborate?
>>
Just finished the OCA certification exam, waiting on the results, taking OCP in a few days. The only upside I can see to these is that maybe people will believe me when I say java is shit.
Thread posts: 321
Thread images: 28


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

If you need a post removed click on it's [Report] button and follow the instruction.
If you like this website please support us by donating with Bitcoin at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties. Posts and uploaded images are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that website. If you need information about a Poster - contact 4chan. This project is not affiliated in any way with 4chan.