[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]
4chanarchives logo

Daily Programming Thread


Thread replies: 328
Thread images: 23

File: 1422385664777_7.jpg (460KB, 2500x1000px) Image search: [Google] [Yandex] [Bing]
1422385664777_7.jpg
460KB, 2500x1000px
Old /dpt/ at >>51928020

What are you working on?
>>
1st for parallel implementations of averaging two integers in C
>>
Second for anime
>>
java
>>
C is still shit.
>>
sixth for python for being productive and easy to use
>>
>>51936223
Does anybody know of a better algorithm to find the maximum consecutive sum of a list? This takes nearly a second and goes through nearly 20k iterations for a list 10k items long, and that's a little on the inefficient side for me.

def max_subarray(List):
result = None
for j in xrange(length,0,-1):
for i in xrange(length-j+1):
listsum = sum(List[i:i+j])
if listsum > result:
result = listsum
save = i
List = List[save:save+j]
length = len(List)
return result
>>
>>51936590
>Python
>Caring about performance
>>
>>51936590

There's probably some math I'm missing out on due to not enough education, a link to resources or search terms to google would probably be enough.
>>
>>51936590
First see if there is an algorithm that does what you want
Then implement it
Then depending on the language you're using try to optimize it a bit, i.e., see if you're using the most efficient methods to iterate without duplicating memory to minimize allocations and that type of things that slow down the program.
Try to use contiguous memory, I'm not sure how List is implemented in python.
>>
>>51936590
Google lists an O(n) algorithm. Your algorithm looks more like O(n3).
>>
>reading tutorial
>"so here's how you do this"
>10 minutes of reading later
>"remember that code we wrote earlier? well it fucking sucks, do this instead"

I hate this shit
>>
>>51936725
>>51936709
thanks, found it
>>
>>51936739
codecademy?
I think I remember seeing this when running through it to learn ruby syntax

It was either variables or loops, I ended up using them anyway
>>
>>51936590
What do you mean by consecutive? Seems like your algorithm is finding the max sum of any two elements of List.
>>
>>51936739
better to give you the right code from the beginning so you can just paste it in your program instead of understanding how it works amiright
>>
>>51936739
what do you suggest instead?
I think it's a good approach, first the tutorial introduces a naive solution to ilustrate how to solve it and then gradually improve it by introducing more complex features you're trying to learn.

>>51936778
this
>>
>>51936739
It's usually the correct way to introduce things, especially if it's about features that people misuse.
Of course, you need to make an effort to understand why it sucks.

If you were going to an university, they tend to make you learn assembler for literally no other reason than to make you appreciate the luxury of even a simple low level programming language introduced later.
>>
>>51936786
Well I'm going through SFML tutorial now and they have seem to follow this format of
>here's an overview of what it is/does
>here's a common usage
>here's some other things it can do but go read the API to learn about them
>here's a note or two about common mistakes/misuse
>>
>>51936739

I hate reading books that do this too. I go through a chapter writing 5 different iterations of code and I end up coming out just learning useless clutter I could have learned if I skipped it entirely.
>>
>>51936590
probably the same as far as big-O is concerned, but try this

def max_subarray(l):
return max([sum(l[:i]) for i in range(1, len(l) + 1)])


if it's still too slow try numpy
>>
>>51936858
I don't see nothing wrong with the approach you just described.
And this might be interesting to you: http://it-ebooks.info/search/?q=sfml&type=title
>>
>>51936778
When I'm taking notes from a textbook I don't like writing down snippets from examples only to find it could be simplified or shortened. It's not a problem if they preface it with "this is a naive solution but there is a better way to do this", but when another example just shows up later and it's "oh by the way, this is better", that's annoying. And fuck you I never copy-paste.

>>51936867
This guy gets it
>>
>>51936918
>http://it-ebooks.info/search/?q=sfml&type=title
Thanks. I'm just scratching the surface of it right now but I feel like I'm going to be sticking with it so I'll boomark those.
>>
File: 1450369221617.png (80KB, 694x732px) Image search: [Google] [Yandex] [Bing]
1450369221617.png
80KB, 694x732px
well dpt?
>>
>>51936881
just testing some shit out but if you're operating on a numpy array then this version is almost instant for a 10000 element array

ex.
l = np.array([random.randrange(-100, 100) for x in range(10000)])

def np_maxsub(l):
return np.max([np.sum(l[:i]) for i in range(1, len(l) + 1)])

np_maxsub(l) # almost instant
>>
File: 2015-12-19_00-19-25.png (14KB, 540x525px) Image search: [Google] [Yandex] [Bing]
2015-12-19_00-19-25.png
14KB, 540x525px
Are you ready for this /dpt/?

I don't think you're ready.

http://blogs.microsoft dot co dot il/tamir/2008/03/02/how-to-high-performance-graphics-in-wpf/
>>
>>51937020
>homework
list.Average(); //why use lambda here
>>
>>51937115
It's a meme from one of the last few threads
>>
>>51937106
WHAT THE FUCK
>>
>>51937106
This makes my penis cry
>>
>>51937020
List<int> someList = new List<int>() {...};
int average = someList.Sum().Select(x => x/2);


Did I do it right?
>>
File: questionable.jpg (35KB, 177x278px) Image search: [Google] [Yandex] [Bing]
questionable.jpg
35KB, 177x278px
>>51937106
>>51937106
>>
>>51936223
So is there any online small easy projects for beginners with C# ?
I tried 2 courses in Udemy one for beginner one advanced, and I am reading some free books right now, but I find my self to learn better if the thing is meaningful, not just some cutoff parts of a "useful" code.
You get the idea, learning while coding something easy. But I still can't think of anything serious myself.
>>
Working on writing a basic compiler. Any books I can sue to help me figure out how to properly write and implement a fsm for my parser?
>>
>>51937152
>x/2
no
>>
>>51937020
let avg = fun nums ->
(nums |> List.sum) / float nums.Count
[1.0; 45.6; 3027.2; 22.0]
|> avg
|> printfn "%d"
>>
File: pwLentX.jpg (108KB, 983x983px) Image search: [Google] [Yandex] [Bing]
pwLentX.jpg
108KB, 983x983px
>>51937106
>>
>>51937186
You're right, I have no idea why I put a 2 in there. It should be
someList.Sum().Select(x => x/someList.length);
>>
>>51937106
eh, comes out fine if you paste into an editor
>>
>>51937020
listAvg = \x -> (foldr (+) 0 x) / (fromIntegral (length x))
>>
>>51937115
>LAMBDA
>>
>>51937152
>java
no. and your code is also wrong.
>>
>>51937251
>why use lambda here
>>
>>51937115
>>51937020
or everyone's initial thoughts when they're asked to average a list
float(sum(list))/len(list)

which I suppose could be rephrased to
g = lambda x: float(sum(x))/len(x)
>>
>>51937287

your life is wrong
>>
>>51937132
>>51937144

It's Hack Team Style code. There's a Ruby gem for it.
>>
Why is
itertools
so based?
>>
>>51937287
That's C# mate.
>>
>>51937309
>>51937250
>>51937228
>>51937191
>>51937152
>>51937115
>using built in list and sum functions
Absolutely disgusting. I suppose youre worthy of the cs grad meme.
(define (av x)
(/ (foldr + 0 x) (foldr (lambda(y z) (+ 1 z)) 0 x)))
>>
>>51937295
>I cant answer the question
>>
>>51937589
>using built in list [...] functions
>foldr
>>
>>51937020
cmd = lambda x: average(x)


average () finds the average of a list, and is defined at the beginning on the program
>>
File: DON-DRAPER-PUKES.gif (2MB, 640x360px) Image search: [Google] [Yandex] [Bing]
DON-DRAPER-PUKES.gif
2MB, 640x360px
>>51937589
(define (av x)
(/ (foldr + 0 x) (foldr (lambda(y z) (+ 1 z)) 0 x)))
>>
Trying to remind myself how to use pointers by coding a max heap. Man, I'm rusty.

So writing an insertion function for the heap class.
Pseudocode
>if root.data is NULL
>>insert value into root.data and call it a day
>else
>>If value is greater than current node.data, traverse to right child and consider that
>else if
>> value is greater than current node.data, traverse left child and consider that

>when child is null; create new node , attach to parent; fill in data value; prime children as null

Assuming this makes any sense, my questions are; does it matter if I drop left or right when data value is equal to a node's data value? (ie, I'm trying to put 17 into heap, 17 is already there) Do I have to be consistent (always right or always left) or does it not really matter? Should I just add a int dupe to the class to the node's data and keep a tally of how many duplicates are represented by a single node? (wasteful for the ones that aren't duplicated)

And second, more importantly; I want to iterate through the heap, starting at root and descending, to find the bottom where I can attach a new item. How do I write this? I've an idea for what I'm doing, I'm just trying to remember how to write and shuffle through various copies of the struct.
>>
>>51937106
>http://blogs.microsoft dot co dot il/tamir/2008/03/02/how-to-high-performance-graphics-in-wpf/
fucking jews
>>
>>51937589
>instead of using the powerful tools easily available to me I should make my own
>>
>>51937607
>this guy thinks foldr is a built in list function.
kek. its an abstraction of a simple function code. You probably dont even know what it does.
>>
>>51937722

folds are functions, scrublord.
>>
>>51937287
>java
>>
>>51937655
>powerful tools
Funny way of saying crutch
>>51937636
Its by far the most elegant solution to this problem and actually solves the problem in a meaningful way.
>>
File: help.png (6KB, 290x268px) Image search: [Google] [Yandex] [Bing]
help.png
6KB, 290x268px
>>51937637
Gah. C++. I'm tired.
>>
>>51937742
so you dont know what fold does. to be expected desu senpai
>>
>>51937771
>I'm a strong independent programmer who don't need no library
Enjoy reinventing the wheel.
>>
>>51937799
>I cant make a wheel
Pathetic
>>
>>51937782
>Public:
>Protected:
>capital p
start over
>>
>>51937791

I do know what folds do. They're still functions.
>>
>>51937830
Its an abstraction.
>>
>>51937863
So are functions, what's your point? They are abstractions that aren't functions? Because that's wrong.
>>
>>51937881

Arguing with lisp fags is like arguing with lisp fags is like arguing with lisp fags is like arguing with..

Now we know not to bother.
>>
>>51937830
>doesnt know the difference between regular functions and higher order functions
Are you proud of your cs degree senpai
>>
>>51937901
Oh look. The guy who doesn't know what a tree is.
>>
>>51937881
You dont know the difference between a procedure and a function. Please dont make yourself look this bad.
>>
>>51937942

Uh.. I know what a tree is.

>>51937914

They're still functions. Just admit it, and we can all move on.
>>
>>51937816
Yeah, like I said, pretty rusty.
>>
>>51937722
>You probably dont even know what it does.

>takes CS 101
>acts superior
*tips graduation cap*
>>
I just got an internship job offer and i havent met the guy if be working with. Its with dell for a research side project. I have to sign a bunch of papers and shit, but this would be my first real programming job.

Any first timer job tips?
>>
>>51937954
>admit to something irrelevant
thats pretty sad. Its apparent you dont know what foldr does.
>>
>>51937991
>foldr and lambda in cs 101
Thats some uni you attended. Im a bit jealous.
>>
>>51938010
https://wiki.haskell.org/Fold
>function
>>
>>51938010
It doesn't matter what arguments it takes, it's still a built-in function. You're way too retarded to try to act like a pedantic autist, stop it.
>>
>>51938040
>I can wiki
Is that how the kids are getting their cs degrees now desu sempai.
>>
>>51938042
>it's still a built-in function
This is too good. People who dont know what higher order functions are trying to talk about them.
Your argument is like saying programming languages that arent assembly are nothing more than functions that translate to assembly. You clearly dont understand the concept of abstraction.
>>
>>51938100
higher order functions aren't functions, ok.
>>
>>51938150
>I dont know what a higher order function is
>>
Let's talk about snafucation or averaging two integers in C or something.

This shitposting has gone too far.
>>
>>51938163
>I dont know what a higher order function is
Yeah I noticed.
>>
>>51935771
I wrote an HTTP daemon based on http 1.0
It was a couple of thousands of lines and was a lot of fun. I added a GUI so normies can use it. I stopped maintaining it when I did a stress test with http req floods and it only lasted 3 minutes before total DoS
>>
>>51938195
Admitting you dont know is the easiest path to learning. Some day youll look at your degree with pride. But not today.
>>
File: proj2.png (743KB, 1920x1080px) Image search: [Google] [Yandex] [Bing]
proj2.png
743KB, 1920x1080px
>/g/ arguing about something they heard about once and never used

Anyway this is my current little project, map manager for halo 2 (you can only play the first 3 levels on an unactivated copy, but renaming other levels works kek)
>>
>>51938204
nice
>>
Anyone else learn OpenGL with file:///W:/openGL/Tutorial0.3.8/html/index.html ? I like it so far, but I'm curious if anyone has any supplementary resources ?
>>
Implementing stack in Haskell:
testStack :: Stack Int ()
testStack = do
push 2
push 3
push 4
push 5
five <- pop
pop
push 6
pop
push 7
push five

toList (testStack)
--equal to [5,7,3,2]

This was fun -- and it was interesting to see how imperative it ended up. That said I much prefer pattern matching on a list for stacklike operations.
>>
File: 1390443984160.png (299KB, 600x541px) Image search: [Google] [Yandex] [Bing]
1390443984160.png
299KB, 600x541px
>>51938237
>file:///W:/openGL/Tutorial0.3.8/html/index.html
>>
>>51938237
>file://
lmao
>>
>>51938213
Well I definitely learned something new today: that you're not just a faggot you're a higher-order faggot.
>>
>>51938225
>renaming other levels works kek

It's nice when videogames don't pack everything into some massive 69gb game.dat file or something.
>>
File: 1438034901598.png (17KB, 133x89px) Image search: [Google] [Yandex] [Bing]
1438034901598.png
17KB, 133x89px
>>51938225
>using for in a functional language
This is for comedic purposes right anon...
>>
About to start making an email client with PyQt. Seems ezpz.
>>
>>51937815
>not knowing the difference between can't and shouldn't
>implying anybody in this thread can't make their own sum function
>implying anybody in this thread can't make their own length function

You're just fucking autistic and probably entirely unemployable. If anybody under me made their own sum function when one was already available, I'd start wondering why I hired them.
>>
Someone want to try out this program on their machine and tell me if it works.

https://github.com/ccosm/Security-Cams

Just start up client.py and server.py and enter the info on the server thing into the client thing

You'll need PyQt5, v4l2, and you might need to recompile the shit inside of the huffman folder.

>>51938291
Yeah I love it.
>>
>>51938304
>Ive never used functional language before
>>
>>51938265
Indeed, the PC versions of Halo games were pretty open to modders which is cool.

>>51938274
GUI widgets are objects in Racket, and besides, for/* is clearer in most cases.
http://docs.racket-lang.org/style/Choosing_the_Right_Construct.html#%28part._.Traversals%29
>>
>>51938324
haskell happens to be the only one I've used, but it has both sum and length. I fail to see your point.

unless you're saying I should rewrite the sum and length functions in that too, in which case you're definitely autistic
>>
>>51938323
  sudo pip install python-qt5                                                              100 ↵
Downloading/unpacking python-qt5
Downloading python-qt5-0.1.10.zip (57.5MB): 57.5MB downloaded
Running setup.py (path:/tmp/pip_build_root/python-qt5/setup.py) egg_info for package python-qt5


The binaries distributed with this version are Windows only,

- If you are on linux, look at
github.com/pyqt/python-qt5/wiki/Compiling-PyQt5-on-Ubuntu-12.04.


Man...
>>
>>51936739
>tutorial/book
>copy paste this code snippet and run it
>look at the result
>now copy another snippet

When will people learn that exercises are about 10000% more useful than just walls of text and code dumps?
>>
>>51938364
>that sum example
Its like they expect the reader not to understand lambda expressions. Youre above that I hope.
>>
>>51936739
>>51938440
I've always been a fan of trial by fire.

Get on one of those coding sites and just attempt to solve the problems. Google when you need to, but never google the actual problem
>>
>>51938438
There should be a package for it in whatever package manager you use. Apt has one anyway.
>>
>>51938378
sum a list in a functional language without the use of functions or higher order functions. I doubt you could without googling the solution.
>>
>>51938474
Only for python 3, actually. Is it for python 3?
If so, you should really ditch /usr/bin/python, as a lot of people have that as python 2.7
>>
>>51938470
Yeah, but when learning a new language that's usually not a great way to go about it since your grasp of even the basic syntax is completely missing. I think a book with good exercises is the best way to learn, because then the exercises can be adapted by the author so that they will always be solvable by the reader while still teaching them something.
>>
>>51938478

(define sum (lambda (x)
(if (nil? x) 0 (+ (car x) (sum (cdr x))))))
>>
Is anybody here good with bit arrays in C? I'm looking at an implementation used for a different purpose (paging) and dont understand why the return value is i*4*8+j instead of i*32+j??

Can anybody explain why??
>>
>>51938456
Yeah, I expect people are smart enough to realize for/fold combines foldr and lambda as one function and it's better to use it lmao
>>
>>51938491
Nope it works on 2 and 3, developed with 2
>>
>>51938510
nil?, car, cdr are all functions, and of course you are also using sum, which is a function (even though you defined it). The post you replied to clearly says don't use functions.
>>
>>51938511
There's literally no difference, it was probably just done to make the 4 bytes/u32int, 8 bits/byte thing more explicit.
>>
>>51938456
>writing more verbose code with less abstraction is better
If you want Java, you know where to find it.
>>
>>51938555
C*
>>
File: 1438052923634.png (85KB, 694x801px) Image search: [Google] [Yandex] [Bing]
1438052923634.png
85KB, 694x801px
>>51938510
>not tail recursive
>>
>>51938542
Yeah thats what I thought. I saw it on two different sites so I thought there was some odd wizardry behind it.

Thank you.
>>
>>51938512
if youre just gonna sum a list then (foldr + 0 lst)
is all you need.
> for/fold combines foldr and lambda as one function
My sides. You dont know what a lambda expression is.
>>
>>51937106
>>51938541
What are you trying to prove?
Trying not to use functions in a functional language?
>>
File: global local.png (13KB, 554x408px) Image search: [Google] [Yandex] [Bing]
global local.png
13KB, 554x408px
Hey, i'm trying to figure out how to assign globals and locals to a file, i'm copying some of the syntax from a book, and this came up. can anybody help explain whats wrong and why it won't build the code? it's stopping at the (float 11;) part
>>
>>51938646
That the post you replied to gave pointless constraints
>>
>>51938669
you can't name a variable "11". Variable names can't start with digits.
>>
>>51938669
Oh sweet jesus
>>
Holy shit, why is the development environment on Windows such a nightmare? I'm starting to understand why some people just build everything from scratch... it's a miracle any software on Windows works at all. So many conflicting libraries. Building debug versions of older VC runtimes is a horrific endeavor.
>>
>>51937106
>.co.il
>>
>>51938671
>I cant program in functional languages
I bet you cant even implement your own sorting algorithm
>>
>>51938669
>#include <stdio.h.>
No trailing dot. So #include <stdio.h>
>main()
While technically not incorrect in C89, don't do this. Implicit int is a cancer.
>float 11;
A variable name can't start with a number and can't consist only of a number.

Also you forgot the closing semi-colon in main() and there is no prototype for prAgain().
>>
>>51938701
I thought it said l1 except in an atrocious font
>>
>>51938701
the fuck is wrong with this guys book, he keeps making mistakes. god damn it. thanks, anything else i should know?
>>
>>51938669
11 = 9.0
>>
>>51938638
Wow! you're actually dumb. All you need is (sum lst).
If you look closely you'll see the lambda is still there, it's the body of the for/ statement
>>
>>51938705
>>51938705
because C was made for unix and everything was built off of C
:^)
>>
>>51938726
>closing semi-colon
Closing curly-bracket I mean.
>>
>>51938728
It obviously says l1 in the book. L for local, g for global.

And you've missed a closing brace after return 0;.
>>
>>51938740
>all you need is sum lst
My sides. I cant find them.
>>
>>51936518
How and why would you want to parallelize that shit?
>>
>>51938749
thank you, that fixed it.. why would he have put prAgain if there is no prototype for it?>>51938726
>>
Is there a non-shit way to do server-side HTML generation/templating? I'm leaning towards using Hamlet.

<html>
<body>
<h1>hello, #{name}


renderPage =
let name = "faggot"
in $(hamletFile "website.html")
>>
>>51938740
>If you look closely you'll see the lambda is still there, it's the body of the for/ statement
What the fuck? Do you know what the difference is between an expression an a lambda?
>>
>>51938791
(sum lst) and (apply + lst) are both clearer than your foldr bullshit. enjoy being unemployed :)
>>
>>51938816
add each integer on different cores. Obviously.
>>
>>51938821
Just use C. I got tired of writing my own HTML so I wrote a simple DSL in C to handle code generation for me. It'll work better than any off-the-shelf solution, trust me.
>>
>>51938735
the more mistakes i realise that i made the better this picture becomes
>>
>>51938835
>I dont understand abstraction
kek. Its incredibly clear if you know what fold does. If you dont you dont need to be using a functional language
>>
Python. Paramiko to cisco gear learn autonomously what path to build and build necessary requirements. Keep getting stuck in endless nests I want it to be prettier.
>>
>>51938829
Of course he doesnt. Which is why hes using for in a functional language to begin with.
>>
>>51938829
in lisp there isn't one. I'll even make a simple example so it doesn't hurt your little brain too much. Lets say you have a list of strings, and you want to append something to each.
;; /g/ being excessively functional
(define strs (list "a" "b" "c"))
(map (lambda (s) (string-append s "!")) strs)

;; normal clear code
(define strs (list "a" "b" "c"))
(for/list ([s strs]) (string-append s "!"))

see how the body of the lambda is still there?

>>51938887
making stuff more complicated for no reason is actually the opposite of abstraction
>>
What the fuck is a hash, why do I need them, how do I use them.
>>
I want to make something like tender with python but I have no experience managing databases or even making websites with python, I guess django looks fine but I haven't used it yet.
Any help/books would be appreciated.

Where should I start?
>>
>>51939004
A cryptographic hash or a hash for indexing into an array?
>>
>>51939004
Let's say you have a phonebook. A bunch of names, and associated phone numbers. Now I tell you, go find John Smith's number. How do you do it? Do you search through every entry in the phonebook?

No, you know the phonebook is sorted somehow, so you look up where the S's are and start your search there. A hash is just a faster implementation of this kind of thing.
>>
>>51939004
a hash function takes an input and buckets it according to some notion of uniqueness. you might want to a hashing them if you want to have a set of unique values or a key-value set, or another set that needs to be bucketed.
>>
>>51939059
>you look up where the S's are and start your search there
That's not how hashes work. They don't really have a good real-world analogy.
>>
>>51936223
>when you leave little notes in your code of where you're up to so when you go back you can get right into it again

thanks f am
>>
>>51939052
the concepts are the same. the difference is cryptographic hashing functiions need to be difficult to invert.
>>
>>51939087
Well, the computer does some math and figures out magically where the S's start, while a human still needs to flip through the pages.
>>
>>51939004
In cryptography hashed values cannot (without considerable effort and time) be reversed. You store passwords as hashes for example so that if you get hacked the users details are safe, to authenticate them you simply take the users input, hash it, and check it against your stored hash.

Values will become the same hash every time, but you should take care and make sure you use a modern hashing technique and add an element of randomness such as a salt.

Hashes are also used elsewhere, but other anons have already touched on them
>>
>i like my notes. The fuck was I doing here.
>i need better variable naming conventions
>sleep.wait it sleeps and waits
>dont enable this. Kittens might die
>>
>>51939120
It's like that except that it's not organized in a clear way (alphabetically) it's organized in a purposely hard-to-predict way.
>>
>>51938712
merge :: Ord a => [a] -> [a] -> [a]
merge [] ys = ys
merge xs [] = xs
merge l1@(x:xs) l2@(y:ys)
| x <= y = x : merge xs l2
| otherwise = y : merge l1 ys


memeSort :: Ord a => [a] -> [a]
memeSort [] = []
memeSort [x] = [x]
memeSort xs = go (splitAt' (len `div` 2) xs)
where len = length xs
go (l1, l2) = merge (memeSort l1) (memeSort l2)


splitAt' :: Int -> [a] -> ([a],[a])
splitAt' 0 xs = ([],xs)
splitAt' n (x:xs) =
let ~(meme1, meme2) = splitAt' (n - 1) xs
in (x:meme1, meme2)


Output:
λ> memeSort []
[]
λ> memeSort [6,5,4,3,2,1]
[1,2,3,4,5,6]
λ> memeSort [1,5,420,-1,3.14159]
[-1.0,1.0,3.14159,5.0,420.0]
λ>


Sorry for not seeing your post earlier, I was memeing in IRC
>>
>>51939209
hashing functions do not need to be purposefully hard to predict predict. for example h(x) = x mod 10 is a reasonable hashing function that is easy to predict. even in cryptography, hashing functions are frequently easy to compute (but not invert!)
>>
>>51939059
>>51939073
>>51939144

Ugh thank you, everything I've read now completely makes sense. Ive been looking at the wrong hash as the places I've been reading havnt bothered to make the distinction between the two. Which makes sense, but still confused me. Thanks anons.
>>
>>51938988
>see how the body of the lambda is still there?
Yes. The the body is there, the lambda is not. That's my point. Don't go strawman on me anon.
>>
what assembly is worth learning in this day and age?
>>
>>51939250
What does the "~" do?
>>
C#

Why isn't this working /g/?

int GetCellIndex(short x, short y) => { return (y-1)*9+(x-1); }
>>
>>51938274
racket devs suggest to use for/* for iteration
>>
>>51939287
This whole argument is a strawman. In >>51938740
I was explaining how for/list eliminates the need for the lambda because the body of for/list IS the anonymous function.

I know you guys wanna be elite and functional and argue about everything, but chill
>>
>>51939482
Not a C# dev, but shouldn't you just get rid of the =>?
>>
>>51939482
>int GetCellIndex(short x, short y) => { return (y-1)*9+(x-1); }
Remove return and the brackets.
>>
>>51938257
BTFO
>>
>>51936590
Literally a wiki article with example code in python for this exact problem:

https://en.wikipedia.org/wiki/Maximum_subarray_problem

Kadane is kind of a traditional example of "dynamic programming" in algorithms classes. It has linear vs your cubic (`sum` takes linear time) complexity.

Not that it has anything to do with the actual problem but naming params with initial caps is considered bad style, initial caps are reserved for class names (note it's class /names/, when passing a class reference you still use snake case, see the numerous examples of "klass" as an argument in the standard library).
>>
>>51939509
;; normal clear code
(define strs (list "a" "b" "c"))
(for/list ([s strs]) (string-append s "!"))

there is no lamda/anonymous function here. There is just a block of code that is looped over.

>I know you guys wanna be elite and functional and argue about everything, but chill
This isn't even some obscure concept. Java, C#, JavaScript and Python among others all support lambda's. They are considered functional concepts, but they exist in almost every popular language that's not extremely low level. You need to know what one is to not look like a complete idiot when working on a team in any of the languages.
>>
>>51939482
What are you trying to do? A function?
remove the =>

An anonymous function? Remove "int GetCellIndex"
>>
>>51937020
>use a rope to hammer this nail
>>
Someone from the previous thread suggested that Javascript was more well thought-out than Python. I do not know if this person is still around at the moment, but I would like to remind them that the language was literally created in 10 days.
>>
>>51939521
Thank you based anon.
>>
So I just started learning some Haskell and I want to stop using the command line now.

I've never used anything for programming other than Eclipse, and visual studio. Currently I am on Linux and I see people on /g/ talk about using emacs/vim for text editors and that something is wrong with using IDE's or whatever.

I just installed emacs and it seems like just a weird text editor... what should I know that I obviously don't?
>>
>>51939715
>but I would like to remind them that the language was literally created in 10 days.
Hardly makes a difference does it anon?

Both languages are pretty shit. I guess I prefer python personally. Never really though of one being hugely better than the other, but python has nicer syntax at least.
>>
>>51939625
This is a very neat algorithm. There's a chapter in "Programming Pearls" that talks about it. The author of the book first came up with aO(n^2) algorithm to find the maximal sum (something like >>51936590), and after thinking about it for a while and discussing it with someone else, he refined it to a O(n log n) algorithm. He thought that was the best that could be done and left it for a couple years. Then he mentioned the problem at a conference, and someone in the audience (Kadane) came up with this O(n) solution in like 5 minutes.

I watched a few videos about it and nobody really explained it to my satisfaction. The way I understand it, the algorithm is based on the fact that you can "prune" a subarray on the left end of the main array if you know that the subarray will never contribute to the maximal subarray, i.e. because the sum of that subarray on the left end is <= 0.
>>
>>51937020

average = lambda { |list| list.reduce(:+) / list.size }


>>51939762

To suggest that any language that one has spent only 10 days of thinking on is in any way "well thought-out" is to suggest one has no standards at all.
>>
>>51939785
>someone in the audience (Kadane) came up with this O(n) solution in like 5 minutes.

Some people are not meant for this world.
>>
>>51939743
Vim or bust

Or sublime text 3 if youre a sane normal man
>>
>>51939858
that doesn't really help me.

like other than making text files what does this program do?
>>
>>51939882
>like other than making text files what does this program do?

towers of hanoi.
>>
>>51939638
Yup, and if you don't want to get laughed off the team you'd follow the documentation recommended style and not use lambda all over the place when for/* forms are available.
>>
>>51939882
Those are all text editors.

A text editor alone isn't a replacement for an IDE, since an IDE usually comes with your compiler/build system/debugger etc. built in, and locked behind its GUI somewhat.

For Haskell, all you need is GHC and a text editor. Your "project" is specified with a cabal file.
>>
>>51939901
Seems like an IDE would be less of a pain in the ass then.

Why don't people just use IDE's?

Being serious I saw a guy do this
https://youtu.be/D1sXuHnf_lo

It seems that when he types something it happens immediately.
>>
>>51939840
>To suggest that any language that one has spent only 10 days of thinking on is in any way "well thought-out" is to suggest one has no standards at all.
I recall he based it a lot of off other languages he has worked on in the past. It's certainly for from the worst of languages out there. Miles miles better than PHP. It's far less verbose than Java. And The Good Parts(TM) of it are actually pretty nice to work with in my experience, if you can deal with the dynamic typing and weak typing shite.

The current version has certainly come on a long way since v1.0 too.

It's generally retarded reasoning to claim a language must be shit simply because not much time was spent on it. Might as well claim a movie is shit because it had a low budget.

Also the anon didn't claim it was well thought-out. Simply better thought out than python.
>>
>>51939954
Personally, I don't use an IDE. I find that IDEs always make it more difficult to do "advanced" things like configuring the compiler settings or doing non-trivial library linking.

For Haskell, I don't think an IDE can really get you anything. Cabal automates most of the build process, and if you really want it, most programming-oriented text editors support linting and autocomplete.
>>
>>51939954
>Why don't people just use IDE's?
Almost everyone in industry does. The only people who don't are generally just control freaks. They also generally tend to lack understanding of the benefits IDE's provide to productivity. Or they use text editors that have so many plugins there are basically IDE's anyways.
>>
>>51940096
One of the best programmers I worked with used vi (not vim). As far as I know she didn't use any macros or anything either, just straight vanilla /bin/vi.

I use emacs myself. The only reason I'd use an IDE is for the GUI designer stuff. Most things in an IDE are just a distraction, at least for the purpose of writing code.
>>
>>51940096
desu the only reasons I use vim are:

1) I can have multiple files tiled on my screen
2) it literally matches my firefox and 4chan css
3) its in the terminal

tooltips etc like when you mouse over functions and shit seems awesome though
>>
>>51940195
(cont)
I also don't like having my projects bound to IDEs, having to integrate git/hub with the IDE, etc. It's all just a frontend to what I can do myself in the term, which I'm more comfy with
>>
>>51939954

>Why don't people just use IDE's?
For me, it's two reasons:

1. Interface feels clunky. I do a lot of my editing in Sublime, which has a number of useful features purely as an editor, without having to take up much more than around 10% of screen real-estate for the menu bar and tab bar.

2. Many IDEs have a build system that is over-complicated/difficult to understand. I tend to use a plain old Makefile (albeit with GNU Make extensions) for most things, because there's not a lot of learning curve to understand what everything does. If I have to deal with a convoluted project system that isn't used on any other IDE, then that IDE better damn well be the best damn thing since sex. So far, nothing has met my standards.
>>
Is sml '97 actually viable nowadays? What's the best implementation? MLTon? Any benchmarks available? Are spaces significant in sml like they are in haskell?
>>
>>51940361

To be honest, family, I really like JetBrains IDEs. IntelliJ is considerably better than Eclipse (at least, imo) and CLion is great.
>>
>>51939341
I thought I would need it to make the pattern match lazy (so splitAt' would be lazy), but I tried it in ghci without the ~ and it looks like it works lazily anyway.

Reading https://wiki.haskell.org/Lazy_pattern_match , it looks like let-expressions match lazily by default. So if instead I had been matching on (,) as a function argument, or in a case-expression, I would have needed the tilde, but not in this case.
>>
>>51939954
Non-IDEs are more general and can be made specific on a per-purpose level, such as adding addons to make vim able to perform live, "perfect" code completion with clang. IDEs, on the other hand, are typically tailored to a specific language or environment, making them less versatile. There is great utility in learning one tool completely instead of 40 poorly.

Non-IDEs do not come with 5 billion features you'll only use 1% of the time. One can add features as needed, incrementally. This greatly reduces the program's bloat level, increasing dramatically the starttime, responsiveness and resource footprint. You're also almost certain to be working with standard project management tools that can be used from the command line, or in general from any toolset other people are using, instead of IDE-specific project files. This is a huge bonus for portability, reproducibility and sharing.

Since non-IDEs aren't IDEs, they need only focus on the core task they're meant for (typically editing text), making them significantly more efficient to use for any language even before any specific tailoring.

TL;DR: use vim, pleb.
>>
>>51940417

You know, I've used IntelliJ in Android Studio, and to be quite honest, I was not a fan of the fact that it was constantly swapping memory to the fucking disk. By comparison, Sublime Text is only using 4 MiB of memory at this current moment.
>>
It took me 3 hours to implement A* from scratch in C, from the pseudo-code on Wikipedia. Am I retarded? I feel like I'm not cut out to be a programmer if it takes me this long to reimplement someone else's algorithm.
>>
>>51940550
You're already better than 99% of programmers.
Most people employed as a programmer today couldn't even implement A* if their life depended on it.
>>
>>51940498

Compared to Sublime Text it's fuckhuge, but compared to other IDEs, it's pretty nice.
>>
>>51937020
Professional Enterprise Programmer reporting in.
Func<IEnumerable<double>, double> average =
list => list.Sum() / list.Count();

// Example
Console.WriteLine(average(new[] { 1.0, 2.0, 5.5, 27.3 }));
>>
File: t-thanks microsoft.png (404KB, 640x582px) Image search: [Google] [Yandex] [Bing]
t-thanks microsoft.png
404KB, 640x582px
Why aren't you using GNU Nano for all your editing needs?
>>
>>51940664
GNU Vim is better.
>>
>>51940664
It's shit.

Emacs (or Spacemacs if you prefer Vim keybindings) is pretty much better in every way, and easy to configure for literally *any* language.
>>
>>51940687
What kind of configuring do you need aside from syntax highlighting?
>>
>>51940706
If it's an interpreted language, don't you want a REPL?
>>
>>51940708
No, because I don't write in scripting languages.
>>
>>51940723
>he spends 10x as long writing code that isn't even performance-oriented
>>
>>51940723
Opendylan is a compiled language with a repl. Checkmate, masterb8.
>>
>>51940738
>he fell for the interpreted language meme

>>51940751
isn't this literally like running a bash 1 liner that runs make and executes your toy program over and over?
>>
>>51940596
Nah mate, even Visual Studio lags less.

>>51940708
Does one really need a REPL in their editor? I mean, I've got an extension in Sublime to evaluate Ruby in the editor, as a way of generating code programmatically, but that sees very little use. When I just want a REPL, I alt-tab into my terminal.
>>
>>51940849
It's a matter of efficiency. Alt + tab, paste, enter vs. C-x-e

Eval-buffer and Eval-region are also invaluable when I'm hacking scripts together.
>>
>>51940849
>Nah mate, even Visual Studio lags less.

Works for me, m90.
>>
Android Studio is pretty shitty. Don't know what the dev environment is like, I only used it to save snapchats, lel, but it super bloated.
>>
>>51940849
>to evalueate Ruby
Is ruby your goto language for random stuff? What are you working on?
I've always had the impression that ruby is only good for web shit
>>
>>51940965

He's working on his doctoral thesis: machine learning which adequately selects best waifu.
>>
Anyone here C#?

I have 5 decimal objects and need to make sure that their sum isn't greater than exactly 1, but this seems a bit tricky to implement. Any advice?
>>
>>51940778
A REPL lets you give commands to define new values, evaluate expressions, etc., and it can load definitions from a file, so you can mess with them, like if you aren't finished but want to see if the output of the stuff you have so far looks right.

But if you're in bash, you might as well use the standalone REPL program that you probably have for whatever language.

Here's an example of what repl output might look like:
  codesnips  ghci sort.hs
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( sort.hs, interpreted )
Ok, modules loaded: Main.
λ> 5
5
λ> 3 + 6
9
λ> let meme s = s ++ " is a meme"
λ> meme "haskell"
"haskell is a meme"
λ> memeSort "Memes are for the masses" -- memeSort defined in sort.hs
" Maaeeeeefhmmorrsssst"
λ>
>>
>>51941058
Couldn't this be done in literally one if statement or am I retarded? (I know nothing about C#)
>>
>>51941058
double sum = 0;
double array[5] = {0.2, 0.3, 0.4, 0.5, 0.6};
for(int i = 0; sum < 1.00 && i < 5; i++)
{
sum+=array[i];
}
>>
>>51941137
>>51941094
It can be, for some reason I was having a moment of mental retardation and thought I had to use .Compare

Thanks senpai, I was being a retard
>>
>>51941216
>no line numbers in emacs
>that green term background
>not doing -t when you know your term is too small for screenfetch
-1/10
also get banned
>>
>>51941216
>white background
>tool-bar
>menu-bar
>that word wrap
0/10. Try again.
>>
File: 49808588_p0.jpg (84KB, 512x492px) Image search: [Google] [Yandex] [Bing]
49808588_p0.jpg
84KB, 512x492px
>>51941216
4chan is 18禁
>>
>>51940965

Ruby is my goto language for random stuff (when not using C or C++), and I've even used it in a few homework assignments. Not a few weeks ago, I used it for an assignment to implement el gamal encryption using the discrete logarithm problem, and also using elliptic curves. It is useful for a lot more than just web shit, although I am recently finding myself using it for web shit. I've got a friend who wants to port over a game played on /b/ using simple gets to a web interface, with a chat, some accounts for keeping track of wins/losses/etc... and he's willing to pay a little cash for it, so I'm seeing what I can hack up for him this winter break. Web development's not really my forte, but it is at least decent that I can toss something together in Ruby real quickly for that purpose if need be.
>>
>>51941026

1. Master's degree, not PhD
2. I'm mostly studying operating systems and security.
3. If I wanted to focus on machine learning, I'd be much more interested in making a program that can fake being human and act like a waifu, rather than simply choosing a subjectively good waifu.
>>
>>51941334

I know, I'm just having a laff.
>>
>>51941345

Aye.... although I will be studying some computational linguistics next quarter as an elective. Alas, I will still not end up with the knowledge to make a waifu bot...

(not that any of that matters because even if I make a waifu bot, I will never be able to knock her up, thus making it all pointless).
>>
File: tfw cumming.jpg (69KB, 580x644px) Image search: [Google] [Yandex] [Bing]
tfw cumming.jpg
69KB, 580x644px
How do I implement a tiny stack for storing integers?
Do I preallocate the space for the stack and then push and pop things, or do I grow and shrink it as it's used?
>>
>>51941392
>women are only good for getting knocked up
Didn't know you were such a misogynist, Ruby.
>>
>>51941392
What would a half-anime half-human half breed look like?
>>
>>51941421
https://en.wikipedia.org/wiki/Dynamic_array

I've implemented a ton of them before. However, THIS IS WHY I USE C++: SO I CAN JUST TYPE "std::vector<int>" AND LITERALLY NEVER HAVE TO DEAL WITH THIS SHIT.

typedef struct {
int* data;
size_t size, cap;
} ist;

void ist_push (ist* st, int a) {
if (st->size >= st->cap) {
st->cap *= 2;
st->data = realloc(st->data, st->cap * sizeof(int));
}
st->data[st->size++] = a;
}
int ist_pop (ist* st) {
// TODO: stack underflow?
return st->data[--st->size];
}
void ist_init (ist* st) {
st->size = 0;
st->cap = 8; // you choose initial capacity
st->data = malloc(st->cap * sizeof(int));
}

int main () {
ist stack;
ist_init(&stack);
ist_push(&stack, 2);
ist_push(&stack, 3);
ist_push(&stack, 4);
while (stack.size > 0)
printf("=> %d\n", ist_pop(&stack));
free(stack.data);
return 0;
}
>>
>>51941474
might have fucked up my size check, should be "if (st->size + 1 >= st-.cap)"
>>
I'm trying to use this FOSS(?) java program:
- runs as a web service, uses at least 500MB of RAM
- impossible to predict how much it takes to process inputs, outputs sometimes after X milliseconds, sometimes after 3X ms.
- started a feature request in their issue tracker 2 days ago, proposed a patch, still haven't got a response
this is shit
>>
>>51941523
hentai@home?
>>
>>51941421

>How do I implement a tiny stack for storing integers?
Using an array or vector and an index for the "top" of the stack.

>Do I preallocate the space for the stack and then push and pop things, or do I grow and shrink it as it's used?
Depends on your use case.

>>51941444

Not quite my views. It's more the point that I want kids in the future, and as such, I've decided it's not something I'm going to compromise on when choosing someone for a life partner. But that doesn't mean that I'm going to look only for this trait. If a woman's only redeeming quality is that she can and is willing to birth me a few kids, I'm not going to take her. I'd like to think I'm worth more than that. Good companionship and loyalty are also highly important. It's just that the kids thing is something I'm going to absolutely put my foot down about.
>>
>>51941558
>Depends on your use case.

I'm just trying to write a stack for this codeeval challenge.
https://www.codeeval.com/open_challenges/9/
>>
Working through a MEAN stack tutorial and enjoying winter break.
>>
File: scheduling idea.png (14KB, 636x394px) Image search: [Google] [Yandex] [Bing]
scheduling idea.png
14KB, 636x394px
Been learning Java for about 5 months, and want to try a small project to really grasp it. Basically, I'd like to help my bosses make schedules at work. It's retail and we have about 30 employees with different availability for each, and shift times/demand vary a lot.

I was thinking of making a scheduling program for practice. GUI, display a spreadsheet for the week, and create createable "profiles" for each worker, showing their availability. The spreadsheet would read the profiles, and color-code the spreadsheet accordingly (pic related). They could just click a cell, and type in a shift.

Thing is, I have no idea where to begin studying to do this. Never worked with it, but would JTable be a good spreadsheet look for this? And for the profiles, how might I go about doing that, arrays of an "Employee" object and have the table read it somehow? Any advice is welcome.
>>
>>51941568

I would say that you should make it resizable then. You have no idea whether you will have 100 or 1,000,000,000 integers to read.
>>
>>51941646
>is called ruby
>gives sensible advice

my head hurts
>>
File: email.webm (70KB, 358x100px) Image search: [Google] [Yandex] [Bing]
email.webm
70KB, 358x100px
Learning PyQt to make a simple email client

this is such a meme
>>
>>51941627
If it was me, I'd look at other systems that have already solved this problem. Now you don't necessarily have to use these programs but you can certainly study them to find out how they work.

http://easyappointments.org/
https://github.com/caldav4j/caldav4j
>>
>>51941692
Alright, thanks. Noticed there were lots, and I can grasp the idea, just not all the specifics. Those source codes are helpful.
>>
File: LOw5roo.png (45KB, 272x273px) Image search: [Google] [Yandex] [Bing]
LOw5roo.png
45KB, 272x273px
>>51936223
>when your incredibly complex and long code works perfectly first run

just open sourced my first lib ever /g/, feels good
>>
>>51941748
What's the library do?
>>
>>51941748
>works perfectly the first run
>leaks on the second run
>entire system crashes on the thousandth run
>NASA fires you for ruining their billion dollar space mission
>>
I have learned python and ruby, yet I am having trouble thinking of projects to apply them to. Any suggestions?
>>
>>51941757
Allows you to define API models directly onto the model itself in Flask that's totally version managed and obeys user permissions.

Made it for my workplaces that can't ever seem to write a fucking API that doesn't always give back incomplete models or that define their JSON model each and every time they need to spit it out.

web dev basically, small, but very complex and very very useful
>>
>>51941675

I have a bachelor's degree in computer science and a lot of knowledge about systems programming. Who says I have to be a one trick pony and only know Ruby?
>>
>>51941811
Oh yeah, and basically lets you spit out the object straight through a response object.

return User.query.all()


would become

[
{'id':1, name: 'memes'},
{'id':2, name: 'dreams'}
]


for eg
>>
Code monkey here, whats a good resource on algorithms and understanding big O?
>>
>>51941855
There isn't much to understand, you should be able to determine when and if your algorithms are wasteful to the point where their execution time grows exponentially to the amount of input received.
>>
>>51941855
CLRS
>>
>>51941855

CLRS

https://thepiratebay.vg/torrent/8078082/Introduction-to-Algorithms-3rd-Edition.pdf
>>
>>51940664
Atom reporting in
>>
typedef struct {
int data;
frame_t *next;
} frame_t;

typedef struct {
frame_t *head;
unsigned size;
} stack_t;

I'm getting "unknown type name "frame_t", but why?
>>
>>51941995
frame_t isn't defined until "} frame_t;"

you have to do
typedef struct _frame_t {
int data;
struct _frame_t *next;
} frame_t;
>>
Windows vs Mac on programming
>>
>>51941995

Need to forward declare the struct.
struct frame_t;
typedef struct {
int data;
struct frame_t *next;
} frame_t;


Also, don't implement stacks with linked lists. That's retarded.
>>
>>51942011
Is there like a C style guide for this sort of thing?
this works
typedef struct _frame {
int data;
struct _frame *next;
} frame_t;

typedef struct _stack {
struct _frame *head;
unsigned size;
} stack_t;
>>
>>51941885
I get that much, I also do things like avoiding branching as much as possible but I'd like to get better at not reinventing the wheel and understanding when people discuss big o

>>51941891
>>51941899
Thank you
>>
Hey /g/uys, I was about to start really delving into my programming books, but I started wondering.
If I was gonna start with C++, should I go a step further and start with C?
I've read that its good to know just to understand
whats going on with the computer, but I assume the language isn't widely used these days?
I enjoy learning to program honestly, and was hoping to learn some of the more complex ones, and then learning Java / C# to potentially look for work.
>>
>>51942051
Not sure, but I do know that *_t is reserved for POSIX types and shouldn't be used elsewhere. But, regarding the naming style, I typically do

typedef struct s_frame {
int data
struct s_frame *next;
} Frame;
>>
>>51942085
Not just POSIX, but POSIX and Standard C
>>
>>51942042
>C
>ever not retarded
>>
>>51942076
Think of it like this, anon:
If you learn C, you can immediately write valid C and valid C++ code. If you learn C++, you'll have no idea what features are or aren't C-compatible, and no idea why these features were even added to the language in the first place.

Going from C to C++ is very easy. Going to C++ to C feels like you're shooting yourself in the foot, or just doing a bunch of unnecessary work. The reality is, for learning, it's best to start with C.
>>
>>51942225

It was designed in 1970, give it a little slack. Having to add an extra line to forward declare is hardly the worst part of C.

>>51942085

Hey, hey...

You forgot a fucking semicolon.
>>
>>51942267
Any chance you could recommend some starting books? I assume that I wouldn't need any super new content.
I figure K&R would be on the list, but I dunno if thats so much a starter as something I would read after I somewhat understand the language already.
>>
Which programming language helps achieve the highest amount of productivity for a single programmer?
>>
>>51942301
K&R is a primer on the C language for people who already know how to program.

I recommend something like Head Start C, which dives into programming basics, like for loops, variables, conditional logic and other staples of basic programming.
>>
>>51942287
>You forgot a fucking semicolon.
Heh, I've been using Python for a few days, haven't used C in a few weeks, my bad.

In other news, >>51941682 actually logs into the email now
>>
>>51942319
I think knowing programming in a language like Python and then learning C after would be easier that going straight to C. That's how I learned, at least.
>>
>>51942301
If you approach K&R with an open mind and actually work through most of the exercises, you can get through it in a solid day of study (maybe 10 hours or so?) and be ready to implement any algorithm you want in C.

It was my first introduction to programming, so I struggled a bit. It's very short, and it doesn't dwell on any one topic for very long, so there's basically no fluff. I think it's a good resource for a beginner if they're dedicated and willing to work through some difficult material.

>>51942338
I would really suggest not learning Python. It may seem appealing to take the easy path, but you really can't appreciate it until you have some background in another language that forces the gory details upon you.
>>
>>51942306
C.
>>
>>51942338
I find that python cripples people who learn it as a first language because it takes a long time to unlearn all the nasty (computationally) expensive habits that python encourages.
>>
>>51942319
... head first c?
>>
Hey guys, rate my stack implementation.
void stack_push(stack_t *stk, int data)
{
frame_t *frame = (frame_t *) malloc(sizeof(frame_t));
frame->data = data;
frame->next = stk->head;
stk->head = frame;
stk->size += 1;
}

int stack_pop(stack_t *stk)
{
if (stk->head == NULL)
printf("Stack empty.\n");
int data = stk->head->data;
stk->head = stk->head->next;
stk->size -= 1;
return data;
}
>>
>>51942301
Get the older edition of C Programming: A Modern Approach. The older editions is for C89 but that still covers 99% of the useful stuff in C. You can pick it up used off Amazon for less than $15.
>>
>>51942392
If you're writing something performance sensitive, try to avoid dozens of ->'s. It is not good.
>>
>>51942363
>>51942370
I suppose.
But the fact that you pretty much will never make anything remotely interesting in C for a long time turns people away from it. Also pointers are hard, and shit like "strings are characters are numbers!! everything is numbers!!!!" isn't exactly intuitive.

>>51942406
Wrong approach to "better performance". Your >>51942392 linked list stack is OK but it never frees the memory it allocates. Contiguous memory is more efficient than constant allocations, so using one fat block of memory and changing its size using realloc()
>>
>>51942363

>>51942301 (this is me)

Would you recommend it as a first book? I'm mostly thinking of learning C so I know whats going on when I'm programming.
After I'd like to get a good grasp of C++, and then Java / C# for employment options, I can honestly say I enjoy learning to program (I've opened up a C++ book to a decent spot, about 600 - 700 pages in, I don't recall right this second) and can say that I am very rarely frustrated with the learning process of it as I enjoy seeing what I'm working on come to life (even if its just in the command prompt)
>>
>>51942443
>I am very rarely frustrated with the learning process of it as I enjoy seeing what I'm working on come to life (even if its just in the command prompt)
not many people seem to be like this. Good luck you should get the hang of it soon
>>
>>51942432
>Wrong approach to "better performance".
??????????????
In what world is multiple redirections and memory fetches not inefficient? Iterating over contiguous memory will always be fast. Chasing pointers is not -- it's that simple.

Freeing is retarded at this point. 99% of programs don't need to free their memory, because they don't run long enough for it to matter.
>>
>>51942471
Getting rid of pointers means changing the structure of the code drastically. He couldn't just, take off the "*" and expect performance change.
>>
>>51942471
>>51942432

python babby detected
>>
>>51942479
>not even the same poster
the most Python programming I've ever done is helping my gf with her CS homework and writing a slow loris script.
>>
>>51942478
>Getting rid of pointers means changing the structure of the code drastically.

No, but he could restructure it into a resizeable array instead of calling malloc every time he pushes. It would be trivial.
>>
>>51942076
>>51942301
>>51942443
(these are all me)
I also wanted to ask about a specific book, I used to see the name all over the place, and found it at goodwill for $4 so I grabbed it due to instantly recognizing the name.
I found a copy of
C++ Programming: From Problem Analysis to Program Design
could anyone give me a rating for the book from say 1-10? And I was wondering if its a beginner level book or something I should move to after getting a little experience?
>>
>>51942500
mallocing every new frame eliminates stack overflows
>>
baka desu senpai
>>
>>51942511
>>no
1) no
>no
no it doesn't
>>
>linked list for a stack
>>
>>51942532
Implementing a stack as a singly linked list eliminates any need to resize the stack, you dumb fuck.
>>
>>51942533
>literally making every operation cost 300+ CPU cycles
congratulations guys, really good work
what will /dpt/ dream up next?
>>
>>51942533
Honestly, it could be worse.
Not that bad if you just want to hack something together or if you don't care about the small performance consequences.

>>51942538
That's true, but what's wrong with resizing your contiguous block of memory? It'll end up using less than half as much memory as the linked list.
>>
>>51942547
???
You could always have an array of frame_t pointers instead of an array of frame_t if that's what you mean.
>>
>>51942547
I just ran a million stack push and pop operations and it ran so fast it's not even worth worrying about.
real    0m0.065s
user 0m0.048s
sys 0m0.016s
>>
>>51942572
How many cycles does it take to insert a value into a linked list? How many cycles does it take to write a value into an array?
>>
>>51942558

It would literally take less time to implement it using a resizable array.
>>
>>51942589
>he finally realizes that /g/ shitposting and arguing over tiny optimizations literally doesn't matter at all

>>51942596
We have to remember that although linked lists are shit for things like stacks that are
>faster
>less LOC
using dynamic arrays, linked lists still have some uses, and may be more elegant for these applications.
>>
>>51942591
>mallocing and assigning to a pointer is faster than assigning to an array index
whew
You do know that no shoving is needed for a stack, right?
>>
>>51942589
>almost 7ms
>not worth worrying about
Hope your program doesn't need to run at 90fps because there goes ~63% of your frame budget.
>>
>>51942628
maybe you should buy a computer made this millennium if that's really an issue for you
>>
>>51942628
>talks shit
>doesn't know how to read decimal numbers
>>
>>51942628
>pushing and popping a million items PER FRAME
ya good point kid
>>
>>51942613

Yes, linked lists have their uses. I will not deny this. But implementing stacks is not one of them.

>>51942589

You know, if you do a benchmark, you have to show a comparison, right?
>>
>>51942645
If you used this shitty stack for everything in your program, then it's not crazy.
>>
>>51942654
There is a comparison you idiot. Don't you see the times for real, usr, and sys?
>>
File: 1430115915517.jpg (160KB, 1024x576px) Image search: [Google] [Yandex] [Bing]
1430115915517.jpg
160KB, 1024x576px
>>51942664
>>
New thread
>>51942683
>>
>>51937020
:: cat avg.list 
2
23
14
1
4
6
7
89
3
25
333
2
:: echo "scale = 2; $(awk '{s+=$1} END {print s}' avg.list) / $(wc -l avg.list | awk '{print $1}')"| bc
42.41
::

>>
>>51942664

I'm saying you need to provide a comparison between using linked list vs using array, dipshit.
>>
>>51942692
How do you know sys doesn't use an array, asshat?
The only one we know is usr, because that's him, and he's using a linked list.
>>
>>51942507 (me)

I just ordered K&R and C Programming: A modern approach.
Anything else I should get?
>>
>>51942778
Really only need the latter but that's alright.

Why the fuck did you buy them, though? They are freely available online.
>>
Wrote some Haskell code to represent infinite continued fractions, and lets you do stuff like multiplying them, returning a infinite continued fraction as a result.
e.g.
x = [1;2,2,2,2,2,2,...]
x ~= 1.4142...
y = x * 2
y = [2;1,4,1,4,1,4,...]
y ~= 2.8284...
>>
>>51942817
I enjoy having physical copies more than reading off my computer screen honestly, I can't really say why, it just seems to work more better for me. They also weren't really expensive, and I work 40 hours a week, so it isn't a huge expense, especially if I end up doing what i want to, which is to end up programming for a living.
>>
>>51942847
> be me
> more better
I swore to fuck I deleted more and replaced it with better
>>
>>51941682
Use tkinter
Thread replies: 328
Thread images: 23
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK