[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: 334
Thread images: 24

File: K&R hime2.png (1MB, 1280x720px) Image search: [Google]
K&R hime2.png
1MB, 1280x720px
old thread: >>56301575

What are you working on, /g/?
>>
>>56307775
This is wrong however.
>>
File: 1393817943679.jpg (167KB, 960x1415px) Image search: [Google]
1393817943679.jpg
167KB, 960x1415px
>not using real anime women
>>
>>56307754
Why wouldn't you cast the return value of maloc? Surely a void* doesn't silently convert to a type* in C right?

I'm a C++ baby so I use new.
>>
>>56307754
Reading SICP.
>>
>>56307839
It does.
>>
>>56307847
It doesn't in cpp thou.
>>
File: battle programmer shirase.jpg (37KB, 640x480px) Image search: [Google]
battle programmer shirase.jpg
37KB, 640x480px
>>
>>56307858
So? C++ is not C.
>>
GitHub or GitLab?
>>
What to learn, Rust or C++?

I peeked a bit at IRC channels. The official Rust IRC seems to get ~400 messages per hour and questions are immediately answers, while the C++ channel seems to be a ghost town.

I mean, given that I'm learning the stuff on my own and don't really have anyone to share experiences with, Rust seems much more attractive in that regard.

Question to C++ programmers here: how did you learn the language? Did you have people to talk/ask questions to/learn from?
>>
>>56307839
C implicitly casts void * to anything.
You have to explicitly cast in C++.
It's also a nice reinforcement of intention.
>>
Everyone here who has a website, how do you host it and how much does it cost?
>>
>>56307877
Rust. C++ is only useful compared to Rust for the libraries it has.
>>
>>56307895
But that's bullshit
>>
>>56307886
I also want to know this.
I don't feel like paying $5 a month just to host some CGI scripts.
>>
>>56307900
It's really not. Rust is better in every imaginable way.
>>
>>56307911
Rust is shit
>>
>>56307877
I learned C++ making vidya games.

Personally I prefer C++ over Rust but C++ hardly has any use outside vidya games these days.
>>
>>56307877
Rust is more enjoyable and has a tigher knit community.

C++ has a shit load of things for you to learn before you are effective at it.

C++ has more jobs for it. Rust doesn't have any jobs for it yet.
>>
being too depressed and disillusioned to program or brush up on my C skills

the more i stay alive the more making additional software seems completely pointless unless you're just doing math or writing a specialised OS

>>56307828
>korra
>good

>>>/co/sug
>>>/trash/
>>
>>56307910
If you can't afford 5$ a month then you should go get a job because that is fucking sad
>>
>>56307920
Why? It's safer with useful language features like modules and algebraic data types without sacrificing performance.
>>
>>56307938
This isn't an argument.
>>
>>56307953
I know, it's a statement
>>
Are there best practices with Try Catch usage?

I always try to avoid using it altogether, except if user input is involved (usually this can be avoided too though).

However, I've seen code before where it's used everywhere and I assume that is bad usage.
>>
>>56307926
Can't you literally make anything with C++? Obviously there's some things that would be tedious but there's not a language that's as powerful as C++.
>>
>>56307932
>Tight knkt community
If you enjoy a community if SJW. Just don't voice the wrong opinions and order your newspeak dictionary.
>>
>>56307985
Nearly all programming languages are Turing-complete.
>>
>>56307980
You must use it only for exceptional behavior. Standard behavior must not raised exceptions.
>>
>>56307932
>>56307988
maybe rust fags should spend less time knitting and more time programming
>>
>>56307947
community, culture, creators, and programming languages can't be separated

It's a mozilla project and that will remain a scar on it like being from the creators of UNIX will always be a credit to C
The design philosophy habits of mozilla will bleed through in very obvious ways eventually

>bell labs
>did great things, made the gold standard of an OS that is good enough for all purposes
>mozilla
>was ran by the guy who made fucking ecmascript
>made an okay opera clone and the fucked it up in a desperate bid to convince chromefag normies to use it
>>
>>56307985
Sure you can make pretty much anything. Which i did back in the day. Now I switched to C# and only use C++ for specific tasks.
>>
>>56308013
>it's shit because it will be shit eventually
???
>>
>>56307980

Yesterday I was looking over someone else's code and they put a switch statement in a try wrapper, then made the default case throw an exception and the catch resolve it.

I seriously don't get why anyone would do this.
>>
>>56307886
Anyone?
>>
>>56308033
a language is an investment
>>
discord channel for dpt?
>>
>>56308097
No
>>
>>56308033
Just wait. Rust will become more of an impure monstrosity as mozilla tries to get the js/python/java audience.

Mozilla's overall philosophy is "if people don't like it, copy what's already popular, poorly" and also "be horrible autistic snobs that know better than everyone"

RIP rust in 10 years
>>
>>56308110
is there any programming discord channels?
>>
What do you think of this calculator program?

    #include <stdio.h>
#include <stdlib.h>

int s[255];
int *p = &s[0];

void push(int x)
{
*p++ = x;
}

int pop()
{
return *--p;
}

int main(int argc, char *argv[])
{
int i;

for(i = 1; i < argc; ++i) {
if(*argv[i] >= '0' && *argv[i] <= '9') {
push(atoi(argv[i]));
} else {
switch(*argv[i]) {
case '+':
push(pop() + pop());
break;
case '-':
push(pop() - pop());
break;
case '/':
push(pop() / pop());
break;
case 'x':
push(pop() * pop());
break;
default:
printf("?\n");
return 0;
}
}
}

printf("%d\n", s[0]);

return 0;
}
>>
>>56308150
I like push and pop
>>
>>56307980
Catch all is generally bad. If you're going to do it, do it near the starting point so you can log unknown errors in one place and recover in one place. You should still treat them as unhandled exceptions and fix with extreme prejudice, but the catch all allows you to save user work and clean up resources and shit.

Then most of the try/catches you write inside of that will be towards specific errors. I will write catch alls within the top-level catch all if I have to deal with an API that has terrible/non-existent documentation and then just code around the crap that it spits out.

Rewriting a hundred try/catch->log->recover is the worst way to use exceptions.
>>
>>56308150
1/3 of the way through the K&R/10
>>
>>56308129
Rust is java all over again. It has this very 'Academic' feel to it. I wouldn't be surprised if they start teaching it soon. It will gain widespread adaptation.
But despite all that, just like Java, it will feel like a drag writting code for it.
>>
>basing arguments on pure speculation
Never change /dpt/
>>
>>56307980
Exceptions were a mistake.
>>
I have a Lidarlite v2 sensor that reads in a continuous data stream, and throws NACKs and ACKs, however it sometimes halts, and throws a NACK as the last output. Any chance someone could help?
>>
Where can i learn how to write safe code or should i just bother with rust ?
>>
File: subsurface division.png (69KB, 844x1380px) Image search: [Google]
subsurface division.png
69KB, 844x1380px
working on a program that uses catmull clark subsurface division to smooth out models or height fields. think this is the kind of program that would look good in a portfolio?
>>
>>56307814
OK. Until you point me in the C89 spec where it is defined, I will ignore you.
>>
>>56308450
>Safe code
Writting code without corrupting memory isn't hard. But every one makes mistakes.
And that's how you get bugs like hartbleed.
>>
>>56308533
>in the C89 spec
Why in the C89 exactly? I guess it is because it's one of the rarest to find in pdf form?
Sorry fag, but if you want anything ask it for C11, the last C standard.
>>
>>56308563
There is only one C standard. It's C89. You're very ridiculous.
>>
>>56308520
well it looks nice
why not add a bunch of different things?
>>
>>56308150
autism
learn a real language and make a real project
>>
>>56308604
And this is absolutely wrong. Yet another giant mistake coming out of your foul mouth that serves no purpose higher to an anus.
>>
>>56308634
bla bla bla
>>
>>56308539
Ahh i see l, thanks :)
>>
>>56308646
What a mature argument! Just as expected from you.
>>
>>56308659
Fuck off furry fag.
>>
File: fingers-in-ears.jpg (15KB, 316x237px) Image search: [Google]
fingers-in-ears.jpg
15KB, 316x237px
>>56308659
>>
>>56307868
GitGud.
>>
>>56308675
I am not a furry nor I implied to be anywhere in my arguments. Moreover this has nothing to do with the topic.

>>56308679
You shouldn't have posted your picture, that way we can see your age and you may be banned for being underage. Anyhow, considering your age I can understand your ignorance on C topics, it's okay.
>>
I now have learned Visual Basic and Java
Where do I branch out now?
>>
>>56308736
You are definitely a furry, and using ancient standards when there are new ones is retarded.
>>
I need to learn java

I'm already pretty good at programming in other languages

what should I do
>>
>>56308608

like what? i didnt show the gui which allows you to select a few other shapes and to manipulate individual vertex positions to distort the models.
>>
>>56308763
>You are definitely a furry
I do not think that you know what the word furry means.

>and using ancient standards when there are new ones is retarded.
Excuse me, but I think you confuse me with the other poster. I did not argue against C99 nor C11.
>>
>>56308773
stuff like that and other model manipulations
splitting, extruding, etc
>>
>>56308629
What's autistic about a RPN calculator?
>>
>>56307845
>prefix notation
The fuck, I feel like a nerd right now.
>>
>>56308849
What? You mean like
(+) 4 5
?
>>
>>56307754
Thank you for using an anime image oniichan desu senpai
>>
>>56308772
You clearly don't know any programming if youre asking how to learn another one.
>>
>>56308863
(+ (* 3 5) (- 10 6))
>Value 19
>>
Programming is shit, post more anime
>>
>>56308894
Infix is basically just syntactic sugar for this, it's just that you've been taught that way first.

for instance, in some FP languages:
(+) ((*) 3 5) ((-) 10 6)
>>
>>56308889

I'm asking what to make genius
>>
>>56308903
fuck off faggot
>>
>>56308903
i forgot to say i suck cocks
>>
>>56308933
That may be true, but the only thing better than an animal's schlong is anime
>>
>>56308915
Why would they do that? It seems like they're complicating basic arithmetic.
>>
Fixed ChanThreadWatch ton run on Ubuntu 16.04 because CLI 2.0 stuff is deprecated in latest Mono.

Now run fine only using CLI 4.0 stuff. Is it worthy to upload somewhere, do a commit or any code monkey should be able to do that ?
>>
at what line count does code start to become difficult to read for a cpp file?
>>
>>56308984
>not working on making anime catgirls real instead
What a waste of effort
>>
>>56308997
666
>>
>>56308984
post on github or pastebin

i wanna see
>>
>>56308979
That's just how you take a regular operator and turn it into a regular function, you can still do

(3 * 5) + (10 - 6)
But sometimes you want to refer to operators as functions, e.g.

zipWith (+) [1,2,3] [4,5,6]
-- zipWith takes a function as a parameter, and applies it element wise on both lists, i.e. [1+4, 2+5, 3+6]

plus you can do sections
((+) 5) -- a function that adds 5
((==) 0) -- a function that compares to 0

(depending on the language, you may not need two sets of parentheses
>>
>>56309041
>plus you can do sections
(5 +)
(0 ==)
>>
>>56309051
>depending on the language, you may not need two sets of parentheses

Nice reading comprehension
>>
>>56308997
Depends on the person reading it, but so long as the accompanying header file is easy to read it can serve as an index or guide for the contents of the cpp file, which helps quite a bit.
>>
>>56307886
$5 a month with Digital Ocean.

No Ragrats.
>>
are magic number evil?
>>
>>56309382
depends on the number
>>
>>56309026
It was mainly correcting resx files and app.config to use CLI 4.0 instead of 2.0.

Have seen a small error in compilation log will fix that before uploading it somewhere.
>>
Might me a retarded question but

or '2' not in str(j) and '4' not in str(j) and '6' not in str(j) and '8' not in str(j) and '0' not in str(j):


Can this be done in one line like it is already, or is this the only way to do it?
>>
>>56309385
i'm writing a function to return a tile location from a grid of tiles, if the tile location is valid(eg. tile #5 is in a grid of 3x3 tiles) then it returns the number with the location of the tile, otherwise it returns -1 which is obviously not in range.


i would do a check to see if the function returns -1 and if not i could use the number returned
>>
>>56309441
not any(str(c) in str(j) for c in range(0, 10, 2))
>>
>>56309656

ty, although it does increase the running time by like 200ms
>>
>>56307886
Domain from Google for $1 per month.
Server from DigitalOcean for $5 per month.

Total: $6 per month.

I chose the Ubuntu server from DigitalOcean's list of options and install Apache web server. Then I SSH in to maintain it (infrequently) and upload html/php/whatever through FileZilla FTP.
>>
>>56309757
probably because you're not caching properly
"".join(range(0, 10, 2)) can be cached
str(j) can be cached as well
r = "".join(range(0, 10, 2))
j = str(j)
not any(c in j for c in r)
>>
>>56307868
>>56308698
GitLain
>>
>>56309851
GitLaid
>>
Finally people are waking up and realizing OOP is a terrible idea and we need to stop overengineering

https://news.ycombinator.com/item?id=12377475
>>
>>56309888
functional programming is doing a lot of overengineering for the sake of avoiding every single code repetition too, though
>>
>>56309888
Is it spreading?

Have we done it?
>>
>'No Man's Sky': Steam, Sony, And Amazon Begin Issuing Refunds, Regardless Of Play Time
MY SIDES
>>
Here's a Haskell solution of Euler 35:
module Main (main) where

import Control.Monad (mzero)
import Data.Int (Int8)
import Math.NumberTheory.Primes.Sieve (primes)
import Math.NumberTheory.Primes.Testing (isPrime)
import System.Environment (getArgs)

type Digit = Int8

toDigitsRev :: Integer -> [Digit]
toDigitsRev 0 = []
toDigitsRev n = let (q, r) = quotRem n 10
in fromInteger r : toDigitsRev q

fromDigitsRev :: [Digit] -> Integer
fromDigitsRev = foldr step 0
where step d res = toInteger d + 10 * res

rotate [] = []
rotate (x:xs) = app x xs
where app a [] = [a]
app a (x:xs) = x : app a xs
rotations xs = take (length xs) (iterate rotate xs)

run limit = length $ do
p <- takeWhile (< limit) primes
let digits = toDigitsRev p
if p > 2 && any (flip elem [0,2,4,6,8]) digits
then mzero
else if all (isPrime . fromDigitsRev) (rotations digits)
then pure p
else mzero

main :: IO ()
main = getArgs >>= print . run . read . head


$ time ./Main 1000000                                                   
55

real 0m0.089s
user 0m0.087s
sys 0m0.000s
>>
>>56309888
https://www.youtube.com/watch?v=xButjfhZWVU
>>
>>56309904
Not OOP =/= FP
>>
>>56309940
mfilter
save some of those ifs
>>
>OOP criticism
>b-but FP! but Haskell!
every time
>>
>>56310018
How would that look? I was looking for something like when/unless for MonadPlus, but no cigar.
>>
i just found out how much the software engineering internship i'm applying for pays. it's 6 weeks long in the summer and the work day's 9 hours. guess how much
>>
>>56309940

My Python

from eulerlib import prime_numbers as pm

pl = pm.primes(1000000)

def primes_under_million(prime_list):
um_primes = [False]*1000000
for i in [v for i,v in enumerate(pl)]:
um_primes[i] = True
return um_primes

def circlePrimes(prime_list):
result = sum(1 for i in prime_list if isCircular(i))
return result

def isCircular(n):
r = str(n)
return all(primes[int(r[j:] + r[:j])] for j in range(len(r)))

primes = primes_under_million(pl)
print (circlePrimes(pl))


55
t: 0.6270358562469482
>>
>>56310125
mfilter :: (MonadPlus m) => (a -> Bool) -> m a -> m a
{-# INLINEABLE mfilter #-}
mfilter p ma = do
a <- ma
if p a then return a else mzero
>>
>>56310163
That doesn't fit into the do-notation tho.
>>
File: never go full guardian.jpg (485KB, 1187x1200px) Image search: [Google]
never go full guardian.jpg
485KB, 1187x1200px
What is the god-tier language?
>>
>>56310146
>>56309940

How different is Python from Haskell?
>>
>>56310197
SML
>>
>>56310197
>posting alt-right memes
back to /pol/ aka /r/the_donald
>>
>>56310221
Haskell is pure and a qt.
>>
>>56310225
>everything i don't like is pol/alt-right/trump/hitler
>>
>>56310221
very. they're entirely different paradigms. python is OOP/imperative, haskell is purely functional. haskell has static typing and python is dynamically typed. also, haskell's compiled but python's interpreted
>>56310197
Scheme
>>
>>56310197
The one I'm working on.
>>
>>56310258
>haskell's compiled but python's interpreted
that's not true
>>
>>56310146
>from eulerlib import prime_numbers as pm

cheater
>>
>>56310272
yes, it's more of a *. but in general, that's how the languages are used (especially when Python has shit like eval() that's part of the standard).
>>
>>56310179
I ____think____ this does what you want


run limit = length
. mfilter viable
. takeWhile (< limit)
$ primes

viable p = not unviable && allPrimeCombos
where digits = toDigitsRev p
hasEven = any (`elem` [0,2..8]) digits
unviable = (p > 2) && hasEven
allPrimeCombos = all (isPrime . fromDigitsRev) (rotations digits)
>>
File: pb.gif (231KB, 800x508px) Image search: [Google]
pb.gif
231KB, 800x508px
>>56310308
Impressive.
>>
>>56310281

>don't want a big ugly sieve explicitly in the code
>cheater
>>
>>56310179
>>56310308
>>56310339

Oh and lint (which told me to do infix elem list, rather than flip elem list) is telling me

app a [] = [a]
app a (x:xs) = x : app a xs

is just
foldr (:) [a] xs
>>
>>56310369
Yes, it's also just xs ++ [x]. I realized that just after posting. Thanks family.
>>
>>56307878
>It's also a nice reinforcement of intention.
Bullshit. If you do something retarded like
long schlong = (long*)malloc(sizeof(char)); // oh shit

You're still fucked.
>>
Is Haskell the king of functional programming?
>>
>>56310435
No. It's Coq.
>>
>>56310435
no lang with ambigious types is king of fp
>>
Any of you guys here have experience with Launchcode? I'm currently a beginner with the CS50X course and want to get into web development after finishing.
>>
>>56310457
>no lang with polymorphism is king of fp
>>
>>56310448
Pretty sure it's Andromeda.
>>
>>56310412
And let's assume we didn't declare `schlong` right there and so it isn't immediately clear that it is of type `long`:
schlong = (short*)malloc(sizeof(short));

The cast doesn't even help *mentally*
>>
>>56310435
Haskell is pretty shit, actually.
>everything is lazy
>uses monads and not algebraic effects
>type system is System F-omega with a tonne of extensions instead of a simpler but infinitely more powerful system
>>
reminder that every moment not spent watching anime is a moment wasted

stop progranming and start watching
>>
>>56310471
>>56310412
s/long/long*/g
>>
>>56310480
>uses monads and not algebraic effects
When will this meme stop? Monad are strictly more general than "muh algebraic effetcs".
>>56310480
>type system is System F-omega with a tonne of extensions instead of a simpler but infinitely more powerful system
That's GHC and it's Fc btw.
>>
File: 2005868.jpg (339KB, 1200x1695px) Image search: [Google]
2005868.jpg
339KB, 1200x1695px
I added some formatting to my C messageboard!
http://45.32.80.36/board.cgi

pls rate!
>>
>>56310509
The only example of a monad being more powerful than algebraic effects I've ever been presented with is Cont.

Linearity solves the rest of what monads can do.
>>
>>56310435
>>56310480
All that said, it's a great sandbox for applying category theory to programming that's slightly less ivory-tower than type theory.
>>
>>56310560
So basically it's useless for ivory tower people and useless for people that wanna get work done?
>>
>>56310480
>>everything is lazy
this is good, and if you don't like it
{-# LANGUAGE Strict #-}

>F-omega
with extensions (e.g. datakinds, typefamilies) it's dependently typed
>>
>>56310532
>waaah, I hate this language because it's not based on muh gadget that wasn't even around yet when the language was being designed
Just use PureScript or Idris if it gives you such a hard on. Or you can just use GHC and emulate effects with monads and typeclasses.
>>
File: 1472396863102.jpg (156KB, 700x661px) Image search: [Google]
1472396863102.jpg
156KB, 700x661px
>>56307877
I wrote some code, spent days trying to get it to compile, read the error messages, Googled them and read the StackExchange responses, progressively learning more and more about the language, and now I C++14...

...and you can too.
>>
>>56310595
haskell is PERFECT GUYS you can just emulate every missing feature!
WOW!!
>>
>>56310590
It's not dependently-typed to any useful degree, since you can only "depend" on constants.
>>
Finally wrote basic post insertion and editing for my realtime imageboard. Haven't finished the image upload UI for replies yet. Also there are some bugs, if you edit in the middle of the input field. Progress in progress. Test site: https://test.meguca.org
>>
>>56310640
No
>>
File: neuron_diagram.jpg (12KB, 375x374px) Image search: [Google]
neuron_diagram.jpg
12KB, 375x374px
>>56307754
Anyone else writing AI systems using Lucifer?
>>
>>56310625
Wew lad, nice strawman. I'm just saying "it uses monads instead of algebraic effects" is not even a relevant criticism.
>>
>>56310667
no
>>
>>56310685
wtf i love haskell now
>>
>>56310702
meme
>>
>>56310660
Can Haskell do this?
Vector :: * -> Nat -> *
repeat :: a -> (m :: Nat) -> Vector a m
>>
>>56310723
Never reply to me again unless you're contributing to the thread.
>>
>>56310726
yes
>>
>>56310726
Coq can.
>>
>>56310772
Prove it.

>>56310778
I know.
>>
>>56307754
Because I compile with -Wall for better checking.
>>
Reminder that xmonad, the only real program written in haskell, has unfixable bugs that cause it to crash from normal usage
>>
>>56310832
wtf I hate bugs now

xmonad never crashed on me btw
>>
>>56310800
-std=c89 -Wall -Wextra -Wno-parentheses -Werror -Wfatal-errors -pedantic -O3
>>
File: 1472345922435.jpg (97KB, 865x720px) Image search: [Google]
1472345922435.jpg
97KB, 865x720px
>>56310852
>-std=c89
>>
>>56310523
Bah, you're cheating by using lighttpd
>>
>>56310800
-Wall will not warn you if you don't cast a void pointer because you *shouldn't* explicitly cast a void pointer. In fact, it SHOULD warn you if you DO.
>>
>>56310782
{-# LANGUAGE TypeInType, GADTs, TypeOperators #-}

module Test where
import GHC.Types (Type)
import GHC.TypeLits

data Vector (a :: Type) (n :: Nat) :: Type where
Empty :: Vector a 0
(:::) :: a -> Vector a n -> Vector a (n + 1)

Do the rest yourself, it's do-able
>>
>>56310866
It always trigger casuals of /dpt/
>>
>>56310523
>Sleeveless
>>
>>56310832
hasklel not even once
>>
>>56310885
>leaving out the impossible part
nice trick
>>
File: 1472164812189.jpg (24KB, 390x234px) Image search: [Google]
1472164812189.jpg
24KB, 390x234px
>>56310885
>Do the rest yourself, it's do-able
>>
>>56310889
>uses the simplest version of the simplest language
>thinks he's not a casual
>>
Newbie here Trying to a write a basic python program that prompts the user to enter a weight in pounds then displays the equivalent weight in kilograms
does my code look okay?

weight_kg = int(input('What is your weight in pounds?' ))
weight_kg = 2.2 // 0.45
print('You weigh', weight_kg, 'kilograms.')
>>
>>56310866
>anime

>drawn in a proprietary animation software written in C++
>that runs under Windows XP
>in a country where downloading it without paying can land you in prison

What is /g/'s obsession with anime when everything about it goes against their ideals?
>>
>>56310915
Why don't you try running it you idiot
>>
>>56310922
It's just crossboarder pedophiles who come here since they have no friends. Ignore them
>>
>>56310909
>>56310910

GHC.TypeLits
>>
>>56310915
>weight_kg = int(input('What is your weight in pounds?' ))
>>
I'm doing a survey filling script, any of you know websites you'd actually get money from filling them? Also any advice for making it
>>
>>56310876
how is using a web server cheating?
>>
File: 1469139600152.png (248KB, 600x800px) Image search: [Google]
1469139600152.png
248KB, 600x800px
>ITT
>>
>>56310885
You skipped anything to do with dependent types.

Besides, all that is really equivalent in expressive power to just using types:
data Z :: *
data S :: * -> *

data Vector :: * -> * -> * where
Empty :: Vector a Z
(:::) :: a -> Vector a m -> Vector a (S m)

You just get different syntax doing it that way.
>>
File: 1472418059004.png (65KB, 600x800px) Image search: [Google]
1472418059004.png
65KB, 600x800px
>>56311028
your png is now optimized
>>
File: qwa.jpg (6KB, 399x57px) Image search: [Google]
qwa.jpg
6KB, 399x57px
>>56310935
I did and I get pic related. I know im retarded :( the kilograms answer seems off
>>56310977
is that bad?
>>
>>56311048
Are you a bot?
>>
>>56311059
>weight_kg
>pounds
>>
>>56310832
>has unfixable bugs

What is the nature of these bugs?
>>
>>56311065
no, why?
>>
>>56311059
>Is that bad?
You're assigning a variable called "weight_kg" but it's actually holding the weight in pounds. What the fuck were you thinking, man? Come on, you're better than this.
>>
>>56311082
IO monad is impure, so it's doing all sorts of kludgy hacks to avoid it
>>
File: dpt anime club.jpg (456KB, 1521x1076px) Image search: [Google]
dpt anime club.jpg
456KB, 1521x1076px
>>56310922
it's cute
>>
>>56311009
You could write your own, it's not like you actually have to handle anything complex when all you do is serve GET and POST for a single endpoint.
>>
>>56311125
cringe
>>
>>56311102
okay !thxs for pointing that out sorry senpai :)
>>
File: z4xocz2fvobx.png (43KB, 599x366px) Image search: [Google]
z4xocz2fvobx.png
43KB, 599x366px
>>
http://hackage.haskell.org/package/Vec
>>
>>56311206
>this will be executed at the end of the loop
really? wow
>>
>>56311241
http://hackage.haskell.org/package/sized-vector-1.1.0.0/docs/Data-Vector-Sized.html
>>
>>56311241
>Vec: Fixed-length lists and low-dimensional linear algebra.
>Fixed-length
>>
>>56311206
why not, instead of checking if the loop is done each iteration, you just do everything you want to do when it's done like console.log('all done'); after the loop is done
>>
>>56311273
forall n. Vector a n
>>
>>56311241
>>56311273
Well, I suppose arrays are always fixed-length, but could depend on any length. There is nothing in this library that is a fully-functional dependent type in any way.

>>56311287
n must be instantiated with a compile-time constant.
>>
>>56311241
>>56311259
go ahead, write the repeat function
>>
>>56311297
no it mustn't

>>56311302
it's in there
>>
Reminder that there is no valid reason to use haskell for actual software development in the year 2016.

Reminder that the sole attraction for using haskell is some amusing features that have no practical application.
>>
>>56311310
Reminder that ironic shitposting is still shitposting
>>
>>56311297
oh, and you've still yet to learn that "compile time" and "run time" have nothing whatsoever to do with dependent typing
>>
>>56311346
Who said I'm trying to be ironic? Haskell is missing fundamental features and is unsuitable for developing real software.
>>
>>56311309
You mean this?
replicate :: SNat n -> a -> Vector a n

A value of SNat is constrained to be the term-level representation of n, which must be instantiated with a compile-time constant, which can be expressed using just types like in >>56311035.

>>56311363
Not this shit again. It's not full dependent typing because you can't depend on a runtime value. It is equivalent in power to something that is not dependently-typed.
>>
>>56311393
you can get a SomeNat from a runtime value, and you're still retarded on this issue. there is no such inherent fucking thing as compile time or runtime in type theory. what about the fucking REPL? GHCI has no compile time
what about proof checkers without FFI? they've got no runtime

jesus
>>
>>56311393
>It's not full dependent typing because you can't depend on a runtime value. It is equivalent in power to something that is not dependently-typed.
your retard
>>
https://hackage.haskell.org/package/reflection-2.1.2/docs/Data-Reflection.html
>>
>>56311431
>you can get a SomeNat from a runtime value
No, you can't.

By compile-time constant, I mean it can always be expressed using type constructors and base types. Something like S (S Z).
>>
>>56311310
>>56311381
this
>>
>>56311381
Nice Scotsman family.
>>
>>56311505
>No, you can't.
Yes, you can

>>56311504
is one example

typelits is the other
https://downloads.haskell.org/~ghc/7.8.2/docs/html/users_guide/type-level-literals.html
>>
>>56311310
Pretty much. Haskell is a proven failure at this point.
>>
Type-level naturals, strings, etc. are certainly useful, but they don't give Haskell dependent types in any way, and they can be expressed through only base types and type constructors.

>>56311540
>Yes, you can
Show me.
>>
>>56311641
>show me
I gave you the links, it's not something I use.
>>
>>56311530
???
>>
>>56311669
Type-level literals is what it says on the tin.

This "reflection" stuff looks different, but it linked me back to this paper:
http://okmij.org/ftp/Haskell/tr-15-04.pdf
It's basically generalized ST.

No dependent types here.
>>
>>56311812
>It is also possible to convert a run-time integer or string value to the corresponding type-level literal.
Exactly what it says on the tin.
>>
is it possible in c++ to convert function pointer to string
example

string result = convert<void(int, int)>();

this should return "void_int_int"
>>
>>56311812
>>56311826

So to establish the current process

>pi types: NOT GOOD ENOUGH B/C NO RUNTIME
>runtime types: NOT GOOD ENOUGH B/C REASONS
>>
Why should you use a BST when hashtables exist?
>>
>>56311866
when you don't just need to access one element often, but also values "next" to it as defined by some ordering
>>
>>56311048
kys
>>
>>56311866
Search in balanced BST is O(log n), lookup in hashtable in O(n)
>>
File: stoicface.jpg (39KB, 346x440px) Image search: [Google]
stoicface.jpg
39KB, 346x440px
>>56311866
BSTs are used for finding ORDERED elements quicker. Hash tables are just key-value pairs.

Hash tables can use BSTs to make collision resolution quicker.
>>
>>56311934
That's worst case lookup which pretty much never happens unless you goof up badly. It will pretty much guaranteed be O(1) for a hashtable lookup.
>>
File: questionable.jpg (35KB, 177x278px) Image search: [Google]
questionable.jpg
35KB, 177x278px
>>56311934
>lookup in hashtable in O(n)
>>
>>56311978
>>56311986
>they don'tt know what big O means
Get a load of these plebs.
>>
>>56311978
You've never done hard realtime programming, have you? If an algorithm runs efficiently 99.9999% of the time but 0.00001% of the time it runs significantly longer to where it can risk missing a deadline, it goes in the trash.
>>
>>56312012
Are you retarded?
>>
>>56311934
>>56312012
>Present average case for BST and worst case for Hashtable
Good comparison
>>
>>56311978
O is only for worst case. Saying that it's O(1) usually doesn't make sense.
>>
File: valgrind.png (17KB, 428x86px) Image search: [Google]
valgrind.png
17KB, 428x86px
I asked here a month or two back about compiler design guides.

Was working on a toy language --> Chip-8 instructions compiler.

I have made progress! 99% sure I construct a valid AST from the given source code. No error handling yet, I finished the actual parsing 2 days ago and did Ludum Dare right after.

I'm gonna make it, anons!
>>
>>56312039
O(log n) is literally the worst case for a balanced BST
>>
>>56312039
To be fair, he said it was balanced which implies height of the tree is O(log n)
>>
O(n) = O(500n)
And this is why O is not good enough
>>
>>56312073
good enough for what?
>>
>>56312107
reasoning about performance
it's solely about complexity
>>
>>56312048
No it isn't. g(x)=O(f(x)) means there exists a constant c>0 in R so that c*f(x)>g(x) for all x>x0 for some x0 in N.
>>
>>56312125
yes, nobody's claiming the opposite tho
>>
>>56312020
Most people don't have hard realtime constraints
>>
>>56311864
I'd like to see this in action. But I highly, HIGHLY doubt that it's possible to add true dependent type checking with a library.

>>56311864
I haven't seen a pi type, and what do you mean by "runtime type"?
>>
>>56312145
I mean lift a term to a type, and pi types have been shown to you the other day

type family f (x::T) = ...
>>
>>56312155
a runtime value*, not a term (though in this case runtime values are terms)
>>
File: 2016-08-29 01.14.32.png (268KB, 1078x1528px) Image search: [Google]
2016-08-29 01.14.32.png
268KB, 1078x1528px
>>56312048
Hmm
>>
>>56312175
And?
>>
>>56312143
I know that, but hearing the phrase "pretty much guaranteed to be O(1)" triggers me to no end.
>>
What's your favourite sort /dpt/ ?
>>
>>56312186
>Average case: O(...)
>Best case: O(...)

Do you know that Big-Oh is a mathematical definition about functions that has nothing to do with algorithms? Big-Oh is fucking older than CS.
>>
>>56312210
sleepsort because it's /comfy/
>>
>>56312210
*
>>
>>56312210
shellsort
>>
>>56312210
>>56312227

that or shuffle sort
>>
>>56312210
import LogicT

bogosort l = once $ do
p <- permute l
if sorted p then pure p else mzero

sorted (x:y:zs) = x <= y && sorted (y:zs)
sorted _ = True

permute [] = pure []
permute (x:xs) = permute xs >>= insert x

insert e [] = pure [e]
insert e l@(x:xs) = pure (e:l) `mplus` (((:) x) <$> insert e xs)
>>
>>56312266
>p <- permute l
>if sorted p then pure p else mzero

>not just "mfilter sorted (permute l)"

>((:) x)
>not (x:)
>insert e xs
>not e `insert` xs
>>
>>56312287
nice meme
>>
>>56308132
yes.
>>56312057
nice! good work anon
>>
>>56312145
First quote was supposed to be >>56311826.

>lift a term to a type
If you're talking about the reflection thing, I'd like to see some specifics. That's a pretty bold claim for a library.

>type family f (x::T) = ...
Unless x is used in a kind, it's not dependent.

I'd be pretty thoroughly convinced if you could do this in Haskell:
repeat :: a -> (m :: Nat) -> Vector a m

main = do
m <- readLn
let v = repeat "Hello" m

And it should be simple to do if Haskell does, in fact, have dependent types.
>>
>>56312305
Thanks! May I ask, though, what's the need for a tripcode?
>>
Currently working on learning Rust/implementing a Tor relay in Rust.

Beyond that, I'm wanting to integrate Raft for consensus into my distributed hash table.
>>
>>56312362
triggering people, mostly
>>
>>56312363
Your projects sound pretty cool

You should post more
>>
>>56312363

What about Rust do you like?
>>
>>56312336
it's not convenient but it's possible, i'm not doing it though

you can use existentials & proxys to erase & reify info
>>
>>56312447
Well, until you do it, nobody is going to take the claim that Haskell has dependent types seriously. Assuming you're not just bluffing, which I'm pretty sure of.

I've implemented dependent types before and it's really not just something that you can tack on. It's ingrained into the language's core. And if you have them, they're straightforward.
>>
Can someone link the SICP version that is adapted for Python?

Ty
>>
File: rust-cohle-older.jpg (42KB, 490x383px) Image search: [Google]
rust-cohle-older.jpg
42KB, 490x383px
>>56312424
he's a great actor imo
>>
>>56312501
http://www-inst.eecs.berkeley.edu/~cs61a/sp12/book/
>>
Why does an x86 processor start execution at physical address 0xffff0? Since the BIOS's memory space starts at 0xf0000, why not just start from there?
>>
>>56312538

thank you. Is it as good as the original SICP?
>>
>>56312556
no idea. i've never read it.
>>
mov weebs,gas
>>
>>56312552
http://superuser.com/questions/988473/why-is-the-first-bios-instruction-located-at-0xfffffff0-top-of-ram
>>
>>56312587
Thanks for the link, i didn't find that earlier.

But, it still doesn't answer my question. His argument boils down to "it starts at the end because starting in the middle would be a bad idea". In that case, why not just start at the fucking beginning?
>>
File: something_wrong.png (3KB, 211x143px) Image search: [Google]
something_wrong.png
3KB, 211x143px
I am trying to do an exercise on this book. It requires me to create a temporary array in a function, story some text and, based on that, use a pointer to point to dynamically created storage and store the info there.

I think I got the solution, but I have one doubt.

So I created a pointer on my main function, which I planned on passing it to my temp_array function and then create storage for that passed pointer in temp_array to copy the info.

But it aint compiling, I figured there has to be something wrong with this declaration?
>>
>>56312677
>notepad++
found your problem, fucko
>>
>>56312210
merge and heap
>>
>>56312502

Hes most handsome man imho.

I am not gay but I would totally fuck him.
>>
>>56312691
that's code::blocks
>>56312677
post your code in code tags, provide info on compilation errors;
>>
>>56312677
what's the error? post it here

your temp_array function must be
void temp_array(char *p)
{
}


see if that helps
>>
>>56312691

Actually codeblocks :^)

Come on help me anon.
>>
>>56312677
ptd is uninitalised
you are a fucktard
>>
>>56312717
>>56312711

Ya'll niggas will laught at my code if I post it, and I am a soft bitch that cant handle the bantz. But anyways here it goes.

 #include <stdio.h>

void temp_array(char * p);

int main(void)
{
int i = 0;
char * ptd;

temp_array(ptd);

while((ptd[i]) != '\0')
{
printf("%c", ptd[i]);
i++;
}
}

void temp_array(char * p)
{
int size;
int i = 0;
int n;

char ar[80];
char c;

while((c = getchar()) != EOF)
{
ar[i] = c;
i++;
}

p = (char *) malloc(i * sizeof(char));

for(n = 0; n < i; n++)
{
p[n] = ar[n];
}
}
>>
Fun tip. When you try to compile a program and it fails, it usually prints why it failed.

For example if you type in your .C file the following.

    int x = FUCK;
print x;


... then the C compiler will probably tell you something similar to "Error at line X col Y, keyword FUCK not found".

Once you stop guessing, and start reading, you're on your way to become a better programmer.
>>
>>56312736
here you go
#include <stdio.h>
#include <stdlib.h>

void temp_array(char *);

int main(void)
{
int i = 0;
char *ptd = NULL;

temp_array(ptd);

while ((ptd[i]) != '\0') {
printf("%c", ptd[i]);
i++;
}
return 0;
}

void temp_array(char *p)
{
int i = 0;
int n;

char ar[80];
char c;

while ((c = getchar()) != EOF) {
ar[i] = c;
i++;
}

p = (char *)malloc(i * sizeof(char));

for (n = 0; n < i; n++) {
p[n] = ar[n];
}
}

>>
>>56312758
This was meant for you >>56312736
>>
>>56312736
ptd is uninitialized
>>
>>56312771
>>56312758

While thats agreeable, you're wrong in one thing and the reason why you are wrong is due to me being wrong in my original post.

The program did compile without errors.

But its a nice suggestion anon ty :^)
>>
>>56312766
You aren't returning p. It's lost. You either want to pass in a pointer to a pointer or just pass p back. Also, what the fuck is that function even doing?
>>
Whoever said working from home is great is a lie. Unless you leave around the quietest place in existence, getting work done with constant noise is sheer pain. I so want to lease out an office and just lock myself in it to program.
>>
>>56312766
You have a fundamental misunderstanding of what a pointer is. They aren't references.
>>
>>56312816
Roommates? Busy street? You just being retarded?
>>
>>56312816
>has the opportunity to work from home
>still finds a way to complain

You have been given the holy fucking grail of programming jobs, dude, you have reached the pinnacle of paid software development.

How did you even manage to land a remote job?
>>
>>56312812

Well the idea is to get the information stored in a big temporal array and store that info in an array that fits just right using a pointer and malloc.

I thought I could create a pointer in main, pass it to the function, and store the location of the newly dynamic allocated memory with the new information
>>
>>56312833
This, all values passed to a function are COPIED to the stack. Even though you change p, you're only changing a copy of the original.

You want to pass in a double pointer (char ** p), or return a char pointer and set the original pointer to the return value of the one returned.
>>
>>56312847
All prgramming jobs eventually become remote. You find out there's literally no reason to be at the office to do what you can do at home. And people contact you by email or skype anyway, so it's like you werent at the office in the first place. At least at home you can work in a mode of comfort, as they say.

I also work for myself, now. Programming is one of the few jobs, if any, where you can do everything from home.
>>
NEW THREAD

>>56312866

NEW THREAD

>>56312866

NEW THREAD

>>56312866
>>
File: 2016-08-28-191301_385x443_scrot.png (39KB, 385x443px) Image search: [Google]
2016-08-28-191301_385x443_scrot.png
39KB, 385x443px
>>56308150
haskell is betteer
>>
>>56312766
People on g are dumb, but I'm an exception. Read this:

You have to return p. You're changing it inside the function but the one in the main function stays the same. Remember that malloc returns a pointer to new memory.

Also set the last byte of the newly created array to \x00 or else you might go out of bounds while reading the array.
>>
>>56312870
I agree fully, but my manager doesn't share this view.

There are very, very few people who understand the benefits of having programmers work from home.
>>
>>56312854
Yeah, I get what you are trying to do. But you don't understand pointers. Pointers are numbers. When you pass a pointer to a function the function gets a copy of the integer (the pointer). When you change it, you are only changing the local copy of the integer (pointer). Imagine, every time you are passing a pointer into a function, it is just like passing a number. The difference is that you can use the number as a pointer (hence the name) to a location in memory there is some data (that's the dereference operator (*)).

To modify the value of a pointer object in a calling function from a called function you have to pass a pointer to that integer (the pointer). This is a "double pointer" (char**). It literally means that there is a number that points to a memory location holding a number that points to a memory location. You can then modify the second level pointer to change the memory in the calling function.
>>
>>56312583
Move the GNU Assembler to the weebs? You're only fueling them.
>>
So this semester I'm taking a microprocessor course that teaches you how to program in x86 assembly and teaches the basics of computer architecture. The final project changes each semester, but it is required to be fully programmed in assembly. Last year's project was a basic calculator (+,-,*,/). According to a friend who took the course, there was a guy who wrote it in 300 instructions. I've written a simple calculator in C that was 300 lines, and the compiled assembly is 1500 instructions. My friend said his was 1200 instructions. Is this possible? Or was the guy bullshitting us?
>>
>>56313025
>teaches the basics of computer architecture
>starts with x86 assembly instead of something sensible to beginners

Anyway, did you compile for size with -Os? Also, interfacing with libc can make your code larger.
>>
>>56313083
>Anyway, did you compile for size with -Os?
Yeah. That's my compiled C code.
>Also, interfacing with libc can make your code larger.
Which is why my friend's hand-written assembly is 1200.
This guys was 300, supposedly.
>>
>>56312736
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void temp_array(char **);

int main(void)
{
char *ptr;
temp_array(&ptr);
puts(ptr);
free(ptr);
return 0;
}

void temp_array(char **p)
{
size_t text_length;
char buffer[80];
fgets(&buffer, 80, stdin); /* read up to 79 characters plus terminating null from stdin */
text_length = strlen(&buffer); /* check how many characters were read */
*p = malloc( (text_length + 1) * sizeof(char) ); /* malloc space for characters and terminator */
memcpy(*p, &buffer, text_length + 1); /* copy these characters and terminator from stack to heap */
}
>>
>>56313124
Yeah, but for what platform? I imagine modern 64-bit executable with all the stack smashing precautions will be larger than a simple hand written 16-bit real mode stuff.
>>
>>56313155
bog standard 32-bit flat model x86.
>>
>>56313193
How does your calculator work? "Pushing" numbers to a "stack" and finishing it off with an operation in reverse polish notation is much more efficient than trying to parse the input.
>>
>>56313341
Seriously. Reverse polish notation calculators are like babby's first assembly program. You already have the stack pointer. Just push numbers on it and call the arithmetic subroutines to modify it. The reason it's larger in C is because C abstracts the assembly stack away from you and modifies it on its own, adding extra stuff to it if all you wanted was a simple reverse polish notation calculator. It's the one type of application that is actually easier to implement in assembly.
>>
>>56312424
I'm a big fan of the concept of borrowing so far. In fact, the entire type system is a hell of a lot better than anything I deal with on the day-to-day (Python, Javascript and Go).

Beyond that, I've only been working with Rust for a day now, but it seems very promising
>>
>>56313520
>The reason it's larger in C
It isn't in good C code.
>>
>>56313147
Don't say what each line does, say why you do that. These comments are useless.

>sizeof(char)
always 1
>>
>>56313736
You can't do hardware level stack manipulation and control in C you dumbfuck.
>>
>>56313806
And? It doesn't stop you from writing it with shorter code in C.
>>
>>56313341
It's infix my man. I use shunting yard.
>>
>>56313827
It literally does.
>>
>>56313873
And you are wrong.
>>
>>56313751
fair points
>>
>>56309940
>>56310018
I had a different solution with a fairly different algorithm:

import Data.List

digits 0 = 0
digits n = 1 + digits (quot n 10)

rotate n = (mod n 10)*10^((digits n) - 1) + (quot n 10)

maprotate = sort.(map rotate)

-- Takes two sorted lists and returns the sorted list of elements that appear in both lists.
-- From solution of earlier problem, good to have around.
inter a b = reverse $ interH a b []
where
interH [] _ acc = acc
interH _ [] acc = acc
interH (x:xs) (y:ys) acc
| x < y = interH xs (y:ys) acc
| x > y = interH (x:xs) ys acc
| x == y = interH xs ys (x:acc)

step primeList = inter primeList (maprotate primeList)
circular primeList = (iterate step primeList)!!(digits $ last $ primeList)


The circular function generalizes the problem by taking any sorted list of numbers and return only the subset which is closed under application of the rotate function.
Thread posts: 334
Thread images: 24


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