[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
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 17
File: K&R himegoto waifux2.png (1 MB, 1000x1400) Image search: [Google]
K&R himegoto waifux2.png
1 MB, 1000x1400
old thread: >>51949011

What are you working on, /g/?
>>
first for crossdressing haskllers
>>
ACTUAL NEW THREAD:

>>51953865
>>51953865
>>
>>51953918
fuck off
>>
I remember when /dpt/ used to get me excited and motivate me to program. Now I just come here to take a shit.
>>
Threadly reminder that there is nothing wrong with singly-linked stack implementations.
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");
frame_t *frame = stk->head;
int data = frame->data;
stk->head = frame->next;
stk->size -= 1;
free(frame);
return data;
}
>>
I'm partial to cute trap thread
>>
#define my_macro(X) (X) * (X)

int main() {
void *macro = my_macro;
int x = 5;
macro(5)
}


why doesn't this work?
>>
>>51953972
i like this meme
>>
>>51953972
>singly-linked stack
Why would we need to know the previous of a stack? Once it's at the top, the previous is null.
>>
>>51954011
what the fuck
I only posted this in one thread lmao
did you copy it or is this me
>>
>>51954011
pass it to cpp and see what's the output
>>
>>51954040
The previous links to the previous link
when popping, you set stk->head to the stk->head->next.
>>
>>51954062
this is C, not C++
>>
>>51953972
horribly inefficient
>>
>>51953972
Well, except your null pointer exception.
>>
>>51954079
cpp is the C preprocessor, not the C++ compiler
>>
>>51954096
What's the correct way to handle those? bypass the free operation and simply return 0?
>>
>>51954058
a macro doesn't have an address
>>
>>51954114
I'd say to bypass everything and return a special value. 0 isn't a special value if it's the data, as you could put 0 on the stack.

You could pop the data into an argument pointer and use the return value as an error indicator.
>>
>>51954114
have it return true/false, pass in a reference to collect popped value. Returning a valid value on success or a valid value on failure could put code using this implementation in an undefined state.
>>
Thinking of writing a program that grabs code from posts in the /dpt/ and runs it
or something like that
for example, if I wrote this

a = 5
print('{0}'.format(a)) # python3 is shit

it would run it in my term, showing the post number too

I want to make it do something interesting though, idk

Perhaps I would make it so that you gave it the post number instead so people can't wipe my hard drive

I want to make something out of posts in /dpt/ though, where each post affects the program in some way
I think it would be fun, but I'm having a hard time coming up with an idea on what it would do
>>
>>51954195
>>51954223
Maybe I could just have it return an enum value STACK_EMPTY or something?
>>
>>51954226
Have it analyze word frequency as well as the frequency of words in proximity to each other.

Then have it start posting.
>>
>>51954274
so just a markov chain

I couldn't do posting because captcha, but I could post the output

I'll get started on it
>>
>>51954250
as long as you separate identifying the result and the result itself, that would suffice, but it's a bit more overhead than necessary.
>>
Why are people still posting in the other thread?
Don't they realize mods always delete the newest one?
>>
>>51954296
you can offload the captcha solving to amazon turks
>>
>>51954332
>don't know how things work around here
>don't like anime
Hmm...
>>
>>51954332
Why support the trap thread?
If you dont approve dont post in it. Its really simple.
>>
File: haskell_logo1.png (30 KB, 647x599) Image search: [Google]
haskell_logo1.png
30 KB, 647x599
I am trying to learn Haskell, how would I create a function that takes a list like [1,2,1] and creates the list [1,1+2, 2, 2+1, 1]?
>>
>>51954404
Oh and it should work for arbitrary lenght of lists
>>
>>51954404
>>51954427
Break it up into sub-problems. For example:
1. How do you generate the list [1+2, 2+1] from [1, 2, 1]?
2. How do you merge those two lists to get [1, 1+2, 2, 2+1, 1]?
>>
Do people write real software in haskell or is it just a toy language for autists?
>>
>>51954459
And then you can be super 1337 with your composition.
-- insert your code here
generate :: Num a => [a] -> [a]
merge :: [a] -> [a] -> [a]

-- composed
generateAndMerge :: Num a => [a] -> [a]
generateAndMerge = merge <*> generate


>>51954504
https://wiki.haskell.org/Haskell_in_industry
>>
>>51954504
if you have to ask...
>>
void *macro = my_macro;


How the macros are bad meme began
>>
File: kp.png (130 KB, 1836x834) Image search: [Google]
kp.png
130 KB, 1836x834
r8 my solution f︂︂a︂m.

function eqSumPowdig(hMax, exp) {
var i,
j,
sum,
digits = [],
answer = [];

for(i = 2; i <= hMax; i++) {
sum = 0;
digits = i.toString().split('');
for(j = 0; j < digits.length; j++) {
sum += Math.pow(parseInt(digits[j]), exp);
}

if(i === sum) {
answer.push(i);
}
}

return answer;
}
>>
>>51954504
It's entire purpose was just to be an academic/toy language for autists but there are some real world applications written in haskell, yeah.

>>51954522
>IMVU
nice
>>
Why the fuck can't I have an unused function in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954404
>take first two elements
>add together
>cons 1st element with the results
>recurse on the rest of the elements with the second elements cons to it.
>>
>>51954504
A bit, like some finance firm has it and some antispam software but no mostly a language for autists and academics. And dont confuse that it isnt used for software that the language is garbage, many discoveries in comp sci is from a bunch of academics using haskell
>>
>>51954522
>https://wiki.haskell.org/Haskell_in_industry
>weedreporter
ayy lmao
>>
Why the fuck can't I have an unused variable in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954549
>using go
>>
>>51954574
go is shit
>>
>>51954574
use a sane language that doesn't give a shit like C
>>
>>51954404
I'm not sure if I understand you correctly. This works for your example though.
f :: [Int] -> [Int]
f (a : b : cs) = a : ((a + b) : (f (b:cs)) )
f x = x
>>
Why the fuck can't I have an unused import in my Go program? I'll be using it in just a few minutes Jesus.
>>
>>51954549
>>51954574
2 minutes later and you haven't honored your half of the deal. the clock is ticking
>>
>>51954549
Holy shit, lmao. I'm glad I decided not to learn Go
>>
>>51954584
f (a : b : cs) = a : (a + b) : f (b:cs)
>>
>>51954584
f (a : bs@(b : cs)) = a : (a + b) : f bs
f x = x
>>
>>51954578
>>51954579
>>51954582
>>51954596
Go is nice for networking. Enough to compensate for its general shittyness.
>>
haskell truly is an arcane meme

>>51954627
a lot of other languages have just as nice networking
>>
>>51954637
Neither C or Python do

Hell no does Java; too verbose
>>
>>51954664
Congratulations, you argued that 3 other languages don't. Good work!
>>
>>51954702
So what language does?
>>
>>51954584
Seems to work perfectly thanks, Haskell is pretty hard to learn desu. just needed something that generates the denominators for the Farey Sequence
>>
>>51954664
>networking
>needing anything other than sockets
>>
>>51954709
Python, actually. Ruby as well.
>>
>>51954759
Data serialization, encoding, compression, hashing, encryption, threading...
>>
>>51954803
>having to type .encode('utf-8') after every string
>>
Refactoring my code yet again since I've changed how thread switching works. Fun!
>>
>>51954847
>what is ssl
>>
With markov chains of text, is each state a word, and the chain is of all of the known words, for example?
>>
>>51953857
Newfag here
Recommend me 1 book on Java that
-Doesn't shill any specific IDE, encourages to use the terminal instead
-Has plenty of self tests/exercises
-Not written by a currynigger

I only know python
>>
>>51955245

> -Doesn't shill any specific IDE, encourages to use the terminal instead

Use a IDE or you will die.
>>
Clion is actually a really nice IDE.
>>
>>51955287
I will, but I'd really like to have my own choice
>>
>>51955302
>get it for free because I'm a student
>get it all setup
>never use it again
I feel kinda bad, but at the same time using a text editor and compiling shit yourself is more satisfying
>>
>>51955503
>get it for free because I'm a student
dropped

How could anyone in their write mine develop software with a closed-source IDE is beyond me.
>>
>>51955644
why is this thread here when the other 1 is better
>>
>>51955658
why are you asking me
>>
>>51955644
>write
>>
>>51955644

I'm sure you can imagine using closed source software.
>>
>>51953857
Swift calculator
>>
>>51955743
Holy shit, I was listening to someone talk when typing that post
>>write mine
Jesus christ lmao

>>51955761
Not for an IDE, though. I've used vim since I started programming and I've always loved knowing exactly what I'm doing. I think I just dislike IDEs in general, although I could really use tooltips on hover, which I don't think there could be a plugin for
>>
>>51955804
>Not for an IDE, though.

I don't see how it's distinctly different than any other closed source software.

Do you think it's sending your leet source to JetBrains or something?
>>
>>51955904
No, I just don't trust it not injecting /something/ into my code.
JetBrains doesn't care about my toy programs lol
But I honestly just prefer writing makefiles and having control over everything and not having my project bound to some IDE
I've seen a few github repos where the installation is "open this project in QtCreator then click Build and Run" and it's just autismo
>>
JUST CRUD MY SHIT UP

Flask + SQLAlcgemy Rocks!

Also, you like my IDs? How do you generate your IDs?
#justwebdevthings
>>
>>51955935

Fair enough, I just think they provide some tools which increase productivity.
>>
>>51955963
Your fortune: codemonkey
>>
>>51956004
Yup.
Did that term come from monkey-patching? Because besides writing SQl I just patched/formed my own Flask

I also have to deploy and maintain so DevOp :)
>>
>>51956040
>>>/g/wdg/
this is the programming thread
>>
>>51955963
my ids are hashes of registration time and first name with "cuck-" appended at the front for male and "bulldyke-" for female
>>
File: welp fuck.gif (2 MB, 398x261) Image search: [Google]
welp fuck.gif
2 MB, 398x261
>Tried to make a hangman game in python while waiting for my plane
>You can't just enter in one letter as input in python

Granted I had a couple rum and gingers before I sat down to make it but is that shit real?

Can you really not just enter one letter as input, do you really need gletch or whatever the fuck?
>>
>>51956072
Are you retarded?
>>
>>51956106
Are you stupid?
>>> cuck = input(":")
:a
>>> print(cuck)
a
>>
>>51956117
>flask
>SQL
>DevOp
sounds webdev to me
>>
>>51956088
what if someone registered at the same time with the same gender?
>>
>>51956158
well then they should include their RACE as well, if you get what I mean.

what I mean is, the RACE will need to be an additional CONDITION. a CONDITION to consider is RACE.
>>
C++ bros i need help again, I need to understand what happens here.

So lets say i create 3 variables and add them up inside the
print statement. According to logic, every value must go into
memory but what happens to the value that is printed out after
it is evaluated inside the print statement? Where does the value "20"
go into in the memory?

int threenumbers()
{
int g = 6;
int d = 4;
int p = 10;
std::cout << "Sum is " << g + d + p << std::endl;
return 0;
}
>>
>>51956158
>>51956195
why doesn't every registrant get a unique randomly generated hash?
>>
>>51956222
they should, i agree
>>
I want to get into machine learning, specifically I would like to make an extension that can try and solve captchas. It doesn't have to be amazing but the whole area is very interesting to me.

Any good places to start?
>>
>>51956222
how about

hash of current unix time + hash of randomly generated numbers

that cool enough for collisions?
>>
>>51956259
plus the registrants information for salt
>>
>>51956270
ok, but that would be too long no?
how do we clip/trim and combine from the three generators?
>>
>>51956283
just throw them into a sha1 hash, nobody cares.
>>
>>51955963
>How do you generate your IDs?
Synchronized monotonically increasing ints? You have to get into some high-performance shit before they stop being a perfectly reasonable primary key.
>>
>>51956072
try harder
>>
>>51954226
I don't like this
why does Guido think that looks better than
print '%d' % a
>>
>>51956207
that behavior has to do with your architecture and not c++ but typically it would be left in a memory region called the stack, and can be overwritten later by a future function call.
>>
>>51954627
Explain how to upload multiple files using one POST request with Go.
>>
>>51956300
at least sha128
>>
>>51954899
>Not writing a class that will handle that for you
>>
>>51953857
non-trap thread: >>51953865
>>
>>51956436
>i don't like anime and this is my first day on 4chan
the post
>>
>>51956361
Is there a way i can read that value back out from the memory? After it has been evaluated in the print statement of course.
>>
>>51954565
>weedreporter
Maybe I should take a look at Haskell after all.
>>
>>51956472
n o
have you considered doing
sum = a + b + c
std::cout << sum
>>
>>51956254
Pattern Recognition and Machine Learning, Bishop
>>
>>51956158
because it's a synchronized process. Only one registration is processed at once and time is not cached before being blocked.
>>
>>51956452
>i'm a huge faggot please rape my face
>>
hey people, can you please help me with this?
https://jsfiddle.net/m66tpc4c/
I can't get this working in chrome, and I don't get why it doesn't worl
>>
I scrapped some html for some lewd stories - should I post code
>>
>>51956626
this is the programming thread
>>
>>51956626
txtarea doesn't have a closing div. Thank me later.
>>
>>51956703
>>51956717
did you guys even open the link in chrome?
>>
>>51956706
performance matters a lot, especially for things like games and especially for mobile games. i'm gonna make a taylor series approximation for a function and it will make a very real difference because i profiled it and it alone is taking up a very large percentage of CPU time. trigonometric functions aren't cheap
>>
>>51956766
I'm talking about optimization for the sake of optimization, not actually profiled bottlenecks in cpu intensive applications (which are a really small percentage of modern software).
>>
>>51956800
well for a performance-sensitive application you can still afford a bit of time to clean up the style of the function, remove pointless computations, arrange the variables and code to be more likely to fit cache access patterns
>>
>>51956800
Because they're new, and don't know any better?

I'd rather new programmers overestimate the need for high performance than go completely in the opposite direction and get accustomed to writing absolute dogshit code.
>>
>>51956763
yup.
>>
>>51956829
What about new C programmers who think micromanaging their memory usage = faster code?

like >>51953972
mallocing for every new item in a linked list is slow as fuck
>>
>>51956853
That guy is a troll, not a new programmer.
>>
>tfw tired
>>
>>51956839
you didn't notice anything strange? what version of chrome/ium are you using?
>>
>>51956919
THIS IS NOT THE WEBDEV GENERAL
>>
>>51956829
I wouldn't. I'd rather have readable beautiful code than "but if I add a function call there's overhead" tier autism.
>>
>>51957010
I think you'd be hard pressed to find someone who cares about performance that much but isn't aware of things like inlining. But you're right, as long as they understand things like complexity as well as certain other factors like GC or cache when applicable, even intermediate programmers don't really need to care.
>>
>>51956999
exactly.
nice trips, btw.
>>
>>51957038
thanks
>>
File: crying-baby.jpg (19 KB, 438x374) Image search: [Google]
crying-baby.jpg
19 KB, 438x374
>>51956999

>No! You're not a real developer who writes/uses programs like I do!
>>
>>51957055
>>WEBDEV
>>DEV
webdev is development
it's not programming
this i the programming thread
not the development thread
>>
>>51957055
There is literally a general dedicated to webdev.
>>
>tfw tired
>>
I have a stupid question about Github. I want to use the API to check whether there's a new release available, and prompt the user to download it if there is. The actual code works fine, but I need to use an oauth token in the URL for it to work. I generated a token that only has public_repo access, but when I submit it to github, the token gets revoked. Trying to do it without the token gives a 403 forbidden error. Anyone done something like this before?
>>
>>51957055
GET OUTT AHERE G-GGET OUTTA HERE
G-GET OUTTA HERE
>>
>>51957091
You got banned from github.
>>
>>51957078
>>51957080
>>Developer are programmers to a greater or lesser extent.
>>Computer scientists are programmers to a greater or lesser extent.
>>Enterprise software is the domain of the developer.
>>
>>51956800
sometimes every clock cycle matters so writing code in a way which helps your compiler optimize from the start is key.
>>
>>51957118
We noticed that a valid OAuth access token of yours was committed to a public GitHub repository. Publicly disclosing a valid access token would allow other people to interact with GitHub on your behalf, potentially altering data, your contact information, and billing data.

As a precautionary measure, we have revoked the OAuth token. A new token will need to be generated in order to continue using OAuth to authenticate to GitHub. Here are a couple of steps you can do to ensure your account security has not been compromised:

* Review any unauthorized OAuth applications, and remove any you don’t recognize: https://help.github.com/articles/keeping-your-ssh-keys-and-application-access-tokens-safe/#reviewing-your-authorized-applications-oauth
* Review you security log to ensure that no other malicious activity has occured: https://help.github.com/articles/reviewing-your-security-log/

Which is fair enough, but the scope is limited to public, so there's no practical way to do anything interesting with it.
>>
>>51957150
If you're talking about cache optimization, that's less about what the compiler can do and more about how the CPU runs the machine code. The compiler really can't help you at all to utilize the cache better, except potentially by inserting prefetch instructions.
>>
>>51957091
Why not just have a single file in the repo with the version as a line and access the raw via the http url? And if there is an update do the usual cloning via whatever.
I mean, using the API is nice, but this hackaround solution I propose sounds like a lot less effort if that's the only functionality you need.
>>
>>51957150
>In extremely rare cases for particular pplications, every clock cycle matters
Fixed that for you. For 99% of code development times > performance.
>>
>>51957139
this is the programming thread, not the developer thread
a programmer is a type of developer
a webdev is a type of developer
this thread is for the former
>>
File: lol.png (196 KB, 1440x900) Image search: [Google]
lol.png
196 KB, 1440x900
>people talking shit about java and using anti java memes to me in facebook and this board
>>
>>51957223
you fucking retard didn't even open the link in chrome
>>
>>51957235
>Cristian was the lower case pro-Java shitposter all along
It's like poetry, sort of.
>>
>>51957240
i saw the code lol

>>51957235
are you still working on that, its been months
>>
>>51957171
i was not referring to anything specific

>>51957186
yes its quite niche, all though probably more common than you think. Real time systems for example.
>>
File: repo.png (58 KB, 1223x671) Image search: [Google]
repo.png
58 KB, 1223x671
>>51957249
more like working on and off.
the repo is 26 days old bro.
It's done.

right now I'm thinking over how to code the second part which will contain other stuff like the physics moving strenght or where cancels should go or the inputs.

Also after that I'll make a level editor.

Dunno if working full on the engine to make it so normies could use it or just say fuck this shit and work only for me.

>>51957247
what do you mean?
>>
>>51957294
Really though, the only optimization concerns that affect the design of your entire application from the beginning are cache, and threading. Neither of which can really be attributed to the compiler doing something smart for you.
>>
>>51957316
>github gui client
haha
HAHAHAHAHA
>>
>>51957316
only work for you
i started my game the last time I saw you post this a few months back and finished it a month ago, C and SDL
you seem to be making an actual fighting game though so that's more complicated (mine was just a platformer)
>>
>>51957330
>Tfw I do a game jam with an artist and musician
>Try to teach them how to use the git command line
>It's 4 fucking sentences they have to remember
>The get guis and ask me questions I can't answer
Hnnnng
>>
>>51957330
>hating easy tools
;^)

>>51957353
dunno, it's hard to make progress when you suffer from depression every two weeks or something.
>>
>>51957330
serious question, how does one look at previous commit versions of files and different branches using command line git?
>>
>>51957353
BTW there was a shitty bug that took me two weeks to solve after asking the libgdx irc guys.
>>
>>51953972
Everyone saying this is a troll. Can someone explain to me why?
>>
>>51954011
A macro isn't a function, it's just simple substitution, the preprocessor allows for some syntactic variation, such as enabling the use of parameters as in your example.
So, there is no call and no return, and no increase in cyclomatic complexity because it is an open subroutine.
What you have done is:
#define my_macro(X) (X) * (X)

int main() {
void *macro = (X) * (X);
int x = 5; // Why is this even here?
macro(5)
}
>>
>>51957419
using a linked list for a stack is the most retarded thing and is nearly 100x slower than an array

>>51957436
posted that as a meme, sorry you took the time to reply
>>
>>51957031
it's surprising how many people think that putting inline in a function declaration increases performance
>>
>>51957451
Wouldn't you have to worry about filling up the array?
>>
>>51957493
Are you saying that it does not improve performance, or are you saying that the increase in performance is negligible?
>>
>>51957516
yes, my linked list stack has no possible way to overflow unless you run out of memory
>>
>>51957516
what is realloc
>>
this:
rect(69, 139, 262, 69);
fill(0, 0, 0);
textSize(43);
text("Click Here", 95, 185);
mouseClicked = function(){
noStroke();
fill(247, 243, 168);
ellipse(69, 366, 69, 69);
ellipse(122, 367, 69, 69);
fill(237, 99, 99);
ellipse(95, 187, 69, 69);
fill(247, 243, 168);
rect(60, 191, 69, 176);
stroke(0, 0, 0);
line(97, 170, 96, 152);
};

what is my life?
>>
>>51957548
computationally expensive compared to reallocing every item as needed
>>
>>51957548
But then you're just making stabs in the dark about how big to make the array
>>
void stack_push(stack_t *stk, int data) {
if (stk->size == stk->alloced) {
stk->array = realloc(stk->array, 2 * stk->size);
stk->alloced *= 2;
}
stk->array[stk->size++] = data;
}

int stack_pop(stack_t *stk) {
if (!stk->size) {
printf(stderr, "popping from empty stack\n");
exit(EXIT_FAILURE);
}
return stk->array[stk->size--];
}


it also happens to be way, way faster
>>
>>51957599
your stack doesn't shrink?
0/10
>>
>>51957596
nope, *2 is the optimal, unless all of your heap is consecutive and you can reclaim, then *1.5

>>51957592
lmao

people finish their first semester in cs and think linked lists are for everything
>>
>>51957608
add three more lines if it matters to you
>>
>>51957323
>Really though, the only optimization concerns that affect the design of your entire application from the beginning are cache, and threading.
not at all, of course there are limits. Realizing when an instruction set implementation is appropriate is another factor, getting around C's integral promotion rules and fp operations for example.
>>
>>51957516
It's called a stack overflow, you can either realloc or accept that memory is finite.

>>51957592
Stroustrup debunked this shit years ago.
Linked lists got deprected by hardware.
https://www.youtube.com/watch?v=YQs6IC-vgmo
>>
>>51957737
stroustrup is a meme

do not take him seriously you dumbass
>>
>>51957760
because you know what is more optimal better than he does
right
>>
>>51957523
>Are you saying that it does not improve performance, or are you saying that the increase in performance is negligible?
not at all, the inline keyword is only a hint to the compiler. Any mainstream optimizing compiler of today will make a better decision in this regard.

Some of the usage I've seen doesn't even take into account what inlining is as the usage is on non small functions which are not called often.
>>
>tfw trying to fully grasp copy constructor/copy assignment operator and move constructor/move assignment operator
Should I be using move as much as possible since its more efficient?

Also when should class member objects be pointers and when should they be regular values.
>>
>>51957823
this is when i stopped learning C++
>>
>>51957760
Experiment for yourself. DRAM is slow as fuck, CPU cache is not and prefetching only works if your data is in contiguous blocks.
>>
>>51957859
i ran 1 million push and 1 million pops and it clocked in at
real    0m0.065s
user 0m0.048s
sys 0m0.016s
>>
OCaml, SML or haskell?
Which is the better language in 2015 and why?
>>
>>51957777
>everything needs to be C performance
LOL
>>
File: 1428792812823.jpg (10 KB, 200x213) Image search: [Google]
1428792812823.jpg
10 KB, 200x213
How do I make my game look "nice"?
>>
>>51957823
polymorphism is a good reason to use pointers.

for memory reservation you can use a vector-container most of the time so use that if you can.

call by reference is not a good reason either (in C++ but not C)
>>
>>51957788
> the inline keyword is only a hint to the compiler.
Not entirely true.

Whether the function is actually inlined is up to the compiler, but the presence of the inline keyword changes the semantics (e.g. whether it can be defined in more than one translation unit, whether it's allowed to have static local variables, whether such variables are shared between translation units).

The precise rules are different for C and C++, and for plain "inline" versus "static inline".
>>
>>51957891
I'd go with either OCaml or Haskell, but I don't know enough about either to say which. I really enjoyed Haskell, but OCaml looks great too.

>>51957928
quads dont lie
But seriously, using a linked list for a stack is a) more work and b) much slower, why would you in the first place?

http://pastebin.com/Ff6JRq9e

  ./a.out
Linked List: 90 ms.
Vector: 32 ms.
./a.out
Linked List: 87 ms.
Vector: 37 ms.
./a.out
Linked List: 95 ms.
Vector: 37 ms.
./a.out
Linked List: 88 ms.
Vector: 35 ms.
./a.out
Linked List: 87 ms.
Vector: 31 ms.
./a.out
Linked List: 100 ms.
Vector: 30 ms.
./a.out
Linked List: 96 ms.
Vector: 31 ms.
./a.out
Linked List: 90 ms.
Vector: 29 ms.
./a.out
Linked List: 86 ms.
Vector: 30 ms.
./a.out
Linked List: 87 ms.
Vector: 32 ms.
>>
Reminder that for most practical inputs, a simple, linear algorithm with good memory usage patterns will destroy an asymptotically less complex algorithm that jumps all over the place in memory.
>>
>>51957993
With constant-time or amortized constant-time being an exception, since by nature they don't touch very much memory anyways.
>>
>>51957523
function like macros are a faster alternative to inlined functions and the performance gain is guaranteed.

type safety is lost unless you implement it and they can be tricky to use.
>>
Are there any good tech talks on concurrency that isn't done by some indian or a guy that hasn't spoken to more than 1 person at a time in his life?
>>
>>51957859
> Experiment for yourself.
Of course, the quality of the results will depend upon the quality of the experiment.

E.g. a test case which does practically nothing but push and pop items will strongly favour the vector. Whereas the more "real" work you do alongside that, the smaller the difference. Not only because the stack operations are taking a smaller slice of the pie, but the cache coherence of a specific data structure becomes less significant once a) the other data used by the program is contending for the cache and b) there's "real" code which can be executed while uncached data is being fetched.

Point b) is what most often renders trivial benchmarks meaningless. Out-of-order and speculative execution are fundamental to maintaining throughput on modern CPUs, essentially parallelising single-threaded code. But trivial benchmarks have no real work to parallelise with whatever the benchmark is testing, causing cache misses to stall the pipeline even though that's far less common for real code.

tl;dr: you can only meaningfully benchmark fragments of code as part of the program where they're actually going to be used.
>>
>>51957891
If I were writing code to interface with native libraries, I would probably use OCaml. I much prefer to write in Haskell, but FFI can be a pain in the ass due to laziness and side effecting monads and such.
>>
>>51958043
> function like macros are a faster alternative to inlined functions
Macros typically aren't any faster than a function which is actually inlined. It's not uncommon for them to be slower due to the fact they're not actual functions (particularly if you're simulating a function which returns a value).

> type safety is lost unless you implement it and they can be tricky to use.
Type safety is usually less significant than arguments with side-effects being evaluated more than once.

Function-like macros should be an absolute last resort where they provide a demonstrable gain over inline functions (either in terms of performance or legibility).
>>
>>51958043
>function like macros are a faster alternative to inlined functions and the performance gain is guaranteed.
No. They're not a guarantee of performance gains. Macros can suffer the exact same issues for almost the exact same reasons as inlines do.
>>
>>51957951
well that's just to get around C++ programmers defining functions in header files for some reason so the linker doesn't complain about multiple definitions.

it has no affect on the compiler's decision as whether to inline.
>>
>>51958172
>They're not a guarantee of performance gains.
Of course they are, macros are prepossessed at compile time.

>Macros can suffer the exact same issues for almost the exact same reasons as inlines do.
and those issues are what exactly?
>>
My web framework.

I'm working on Windows now, to see if I can hack a problem out (bad performance). I went from using tcpclient to socket and that increased performance from 5-16ms to around 2ms, but its still not enough as I get 350us on Linux, about a sixth of the speed. The interesting thing is that I was getting exactly whole numbers of millisecond response time (5.001 to 16.001) with tcpclient, Microsoft are definitely doing something suspicious, it'd be really shit if they're introducing lag to make their other software unbeatable.

I'll continue hacking (ie trial and error programming). My latest thoughts is that send/receive are especially expensive on Windows.
>>
>I want every function call to be inlined indiscriminately because CPU instructions don't real and don't need to be loaded from RAM to cache to be used just like every other bit of data
>>
>>51958138
yeah you don't know how preprocessing at all.

asm code is generated for inline functions but not for macros so they are obviously always faster.

>arguments with side-effects being evaluated more than once
preprocessing is just text substitution, expressions are not evaluated.
>>
ok, it seems that using
list.add(index, new element());

doesn't add a new element to the list (making it bigger) but rather work as insertion, changing the element.

BTW it's java.
>>
>>51957940
what kind of game is it? but regardless, as long as you keep a consistent style it should look fine/tolerable
>>
>>51958309
who are you quoting? i actually use __attribute__((noinline,noclone)) on some functions
>>
>>51958443
>Macros are a guarantee of performance gains
>>
>>51958392
I'm not the person you replied to, but I'm going to say YOU don't know how preprocessing or compiler optimisations works.
>asm code is generated for inline functions but not for macros
>but not for macros
What? A macro is going to insert code into your program most of the time. How the hell does it get away with not producing any object code?
Also, don't underestimate the optimiser.
>preprocessing is just text substitution, expressions are not evaluated.
Right. That was exactly his point:
#define my_macro(x) ((x) + (x))

int a = 1;
my_macro(++a);
>>
>>51958228
> Of course they are, macros are prepossessed at compile time.
They're a guarantee of inlining. Inlining is not a guarantee of performance gains. Or at least not a guarantee of sufficient gains to offset the losses from reduced code density.

With an inline function, the compiler can choose to inline it in the cases where there's an actual benefit to doing so (i.e. enabling useful optimisations, particularly loop induction) and using call/return otherwise. With a macro, it's inlined before the compiler even gets to see it.

In theory, the latter can be solved through procedural abstraction (identifying duplicate code and making it a separate procedure). In practice, that feature is only found on compilers for small-scale microcontrollers where minimising code size is essential and the total amount of code is small (identifying duplicates scales non-linearly with code size).
>>
>>51958405
Nah, it's inserition
>Coding OOP without the API docs for the library open
https://docs.oracle.com/javase/8/docs/api/java/util/List.html#add-int-E-
>>
>>51958277
Same guy here.

>I'll continue hacking (ie trial and error programming). My latest thoughts is that send/receive are especially expensive on Windows.
Confirmed false, it still takes between 1ms and 2ms even if I do absolutely no sending and receiving. This is still three times slower than Linux.

What's suspicious is that this is slower than the asp library I'm benchmarking against.
>>
>>51958506
care to explain what's going on?
>>
>>51958476
I just double check and my list.size doesn't increase.
>>
Random question but is there anything wrong with this RAM chip? Considering buying it but it seems so cheap...
http://www.ebay.com/itm/221969421950?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1586.l2649
>>
>>51958506
It may be that windows is just shit at measuring. Programmers are not used to it but every single measurement comes with an associated error, which is at least as big as the smallest unit that the thing can report.
>>
>>51958547
wrong thread
>>
>>51958540
Post code. All I can think of at the moment is that you're using the wrong list subclass.
>>
File: hydrophobic_sand.webm (318 KB, 352x264) Image search: [Google]
hydrophobic_sand.webm
318 KB, 352x264
Ask your beloved programming literate anything.
>>
>>51958590
nobody likes you
>>
>>51953857
random browsing on internet
>>
>>51958583
https://github.com/cristianceron/CharacterEditor/blob/master/core/src/character/Character_Atlas.java

line 56
>>
>>51958277
> The interesting thing is that I was getting exactly whole numbers of millisecond response time (5.001 to 16.001) with tcpclient, Microsoft are definitely doing something suspicious
Windows uses a 1000 Hz heartbeat (time-slice). Linux is configurable, typical options are 100, 250, 300 or 1000 Hz (lower numbers give better throughput, higher numbers lower latency).

Any syscall which can't be completed immediately will suspend the calling process to allow another process to run. The calling process will be resumed by the heartbeat once the syscall can complete. Thus, if you measure the time interval between the return from blocking syscalls, the intervals will invariably be an integral number of milliseconds.

Any syscall which needs to block until some other process has performed some action (e.g. communicating with a process via a pipe) will typically exhibit this behaviour.
>>
>>51958621
Looks fine, my bet would be on either chara or the index being null or non valid positions.
Step into it with the debugger man.
>>
File: (47).png (260 KB, 563x542) Image search: [Google]
(47).png
260 KB, 563x542
>tfw writing inefficient code
>>
>>51958533
I have two ways of opening and closing network connections.
One uses the httplistener class.
The other uses the socket class.

Httplistener is benchmarking at 150us (no shit) on Windows, but about 1ms on Linux.
Socket is benchmarking at 1.5ms on Windows, but about 350us (probably less) on Linux.

Ideally, there should be nothing simpler, and therefore faster, than a raw socket. Microsoft are doing some shit, I'd think httplistener is connecting to IIS, but not, because then it wouldn't work on mono.

BTW, 1ms == 1000us.

>>51958550
No, I'm getting my measurements with apachebench, and if you were right httplistener wouldn't benchmark so fast.
>>
>>51958669
I dunno, it simply works.

ain't gonna fix what ain't broke.
>>
>>51958679
I'm fine with that as long as you admit that you either don't care or aren't skilled enough to do otherwise, and not saying "wow guys it's 2015 computers are fast now :^)".

Dumb frogposter.
>>
File: kek.jpg (181 KB, 788x1014) Image search: [Google]
kek.jpg
181 KB, 788x1014
>>51958679
>tfw barely designing and then implementing a "stringly typed" scripting language parser
>>
>>51958712

>stringly typed
Everything is a string?
>>
>>51958695
you sound triggered. heh. truth is, i choose to write inefficient code because it's easier. it's not like computers nowadays in the year 2015 can't handle the extra computation processes per second :^)
>>
>>51958741
Pretty much. If the strings are numeric you can do math, etc, but there's no real type system and all function parameters in the underlaying built in functions are strings.
>>
>>51958654
Interesting, but then how does httplistener get its speed? Is it possible to open a connection without a syscall?

>>51958679
I'm also fine with that, provided you don't volunteer for anything that bottlenecks (or don't work with me at all)

>>51958786
Fast servers are a security measure.

With a slow server, a ddos will shut it down. With a fast server, a ddos will slow it down. The alternative is finding some magical method of distinguishing a genuine response, like cloudfront.
>>
>>51958786
I agree with this guy. I write all my code to perform the same operation 1000 times in for loops, unless of course in doing so would change the behavior of my program in which case I just sleep for 10ms after such calls.
>>
>adding delays to your program for the sole reason to make it appear like it's doing something important
kill yourselves
>>
>>51958864
>making your program look trivial because it does fucking nothing
enjoy losing clients, dumbshit
people are dumb, they expect their programs to take a long time so they seem large and complex
>>
>>51958864
just added a sleep(10000) to my program

nigger
>>
>>51958864
>Tfw classmate added a sleep() to the input handling code so it wouldn't pick up key too fast
I sometimes wonder how they get so far in the classes while being so shit
>>
                foreach (string subDirectory in Directory.GetDirectories(lblFolderBrowse.Content.ToString()))
{
foreach (var element in Directory.GetFiles(subDirectory.ToString()))
{
file = System.IO.Path.GetFileName(element);
lstAllFiles.Items.Add(subDirectory.ToString() + @"\" + file);
}
}


How the fuck do I parse out JUST the subdirectories folder name, instead of the full path? I've never had to do something like this before.
>>
>>51959185
Discard everything preceding the last "\" from the string.
You can do it manually or with a regular expression.
Or are you asking something different?
>>
File: pls.png (144 KB, 883x1547) Image search: [Google]
pls.png
144 KB, 883x1547
i just want the goddamn taylor series

why does everything have to be so fucking broken
>>
>>51959252
Nope, that's what I'm after.

Adding this feature to my program is a killer, I've now gotta go through everything that interacts with the files in the subdirectories and write a method to find entries of type [subdirectory]/[filename] and remove the crap.
>>
>>51959185
maybe you should just kill yourself lmao
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on wi
n32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pprint import pprint
>>> import os
>>> print os.getcwd()
C:\
>>> dirs = os.walk('.').next()[1]
>>> pprint(dirs)
['$Recycle.Bin',
'Boot',
'Documents and Settings',
'eSupport',
'Fraps',
'Intel',
'NVIDIA',
'PerfLogs',
'Program Files',
'Program Files (x86)',
'ProgramData',
'Python27',
'Recovery',
'System Volume Information',
'Users',
'Windows']
>>>
>>
>>51959301
Why don't you just calulate it "manually"?
You can ask Wolframfor the derivates.
Personally I would just check the periodicity of the function you're using and make a lookup table with a certain precision.
>>
So what's the status on things like WebAssembly and asm.js?

Can I really start developing web applications without needing to deal with hipster JS frameworks and other cancerous shit?
>>
File: 1450596004297.png (288 KB, 907x1855) Image search: [Google]
1450596004297.png
288 KB, 907x1855
>>51959399
i have no idea what you're talking about

i just want something like in the widget at the top but with more digits of precision. it's not too much to ask when the example in >>51959301 does exactly that. you think i should calculate the expression below manually to 16+ digits of precision?
>>
>>51959252
Now I'm having trouble removing folder name from [subdirectory]\[filename]

I want off this wild ride.
>>
/g/ has some of the dumbest opinions on languages I've ever read

what makes you all so fucking retarded?
>>
>>51959472
The precision of a Taylor series depends on how many terms you're doing as well as how far you're from the point. And well, the usual precision of of float/double.
If you can't calculate the actual derivatives of the expression because you want something generic, you can aproximate them by numerical methods, but you'll lose precision there too.
If you want extra precision you should probably begin by trying to figure out the error cap of your aproximations at a given point, otherwise the extra digits will be pointless noise.

I don't know what you want this for so I can't really give you any concrete tips other than it's really hard to get really good precision that is cheaper than calculating the actual function.
>>
>>51959592
most people here are hobbyists and amateurs who have never written anything more substantial than a fizzbuzz implemented as a linked list.
>>
>>51957874
>never posting how fast the array version is
>>
>>51957891
There is only minor differences between SML and Ocaml. I personally like the SML syntax better, pattern matching and function definitions look clearer, there are no special floating point arithmetic operators (ie +.) at the cost of having to define explicit types in functions that use arithmetic. But there is more learning material for Ocaml. Haskell is ok if you just want to study fp and not actually do any programming with it. I personally think Haskell is overkill if you want to do anything practical compared with ML languages.
>>
>>51959618
it doesn't matter
if your program is doing anything substantial, other more integral parts of your application will have much worse time complexity than a fucking linked list stack.
>>
Familarizing myself with C++11 and multi-threading.

I have a feeling that this style of programming leads to very insidious bugs. It's interesting to try and figure out how you can make thread safe data structures though. Making it so you're Mutex locks the data up at the right granularity seems like it may take some practice before I get a feel for it.
>>
How do I implement a strstr?
>>
>>51959634
it's always the DB desu
Thread replies: 255
Thread images: 17

banner
banner
[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.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.