[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: 28
old thread: >>53820383

What are you working on, /g/?
>>
Thank you for the Hime OP.
>>
File: 03-apollo-arrow-geneva-1.jpg (608 KB, 1920x1280) Image search: [Google]
03-apollo-arrow-geneva-1.jpg
608 KB, 1920x1280
>>53826391
KILL YOURSELF YOU MEGA FAGGOT

YOU SUCK AT PROGRAMMING
>>
Learning JS.
Is there a book covering everything in JS/ES 5 and best practices, but shorter than Eloquent? Eloquent seems to target people just learning programming.
>>
>>53826428
FUCK OFF TO >>>/g/wdg
>>
>>53826428
JavaScript: The Good Pars
>>
>>53826443
That's rude.
>>
ALL OF YOU FUCKING SUCK AT PROGRAMMING I'M LITERALLY THE BEST PROGRAMMER ITT
>>
Is there any reason to switch from gcc to clang for my C++ project?
>>
>>53826454
Parts*
>>
>>53826454
I'd like a full coverage, not only parts some author deems good. Also, is it shorter really?
>>
>>53826428
Don't use semicolons
>>
>tfw Travis CI is bretty gud
I might actually switch back to GitHub.
>>
repostan

Anyone know what the fuck is wrong with VS's github plugin/diff tool? No changes reported although there are; then if I manually add any number of changes to a commit from command line, the github plugin magically turns on and reports any remaining changed files.
>>
>>53826459
>I am the best programmer in this thread
>Thinks Java is a great langugae
>>
>>53826473
better error messages
>>
>>53826473
Clang compiles code faster.
>>
>>53826477
It's pretty short. It's pretty comprehensive. It mostly just explains a good way of using JS and what parts of it are kind of broken and best avoided as it teaches you.
>>
File: IMG-20160106-WA0012.jpg (828 KB, 1536x2048) Image search: [Google]
IMG-20160106-WA0012.jpg
828 KB, 1536x2048
w-what the hell is this?
>>
>>53826459
I doubt that sir. I doubt that quite firmly. In fact.. I believe you sir are among the more weakly skilled programmers in this thread, and I am more skilled than you. More skilled I say.
>>
>>53826473
Can someone link that post (from a maillist) which confirms that even gcc developers don't know what the fuck is going on in the codebase and how it works. I think it was about improving some algorithm and fucking it up and not knowing how the old one works with less bugs, iirc it was about register colouring. Does anybody know what I'm talking about?
>>
>>53826518
A dream come true.
>>
>>53826539
I guess GCC is in the same state as X then..
>>
Help me /g/, I feel like I'm tangling my program in an anti-pattern.

I'm programming a game composed of tiles. I have a world class containing the tiles in an 2D array, and each tile needs information about the other tiles in the world. How can I get it without passing down some god object representing the world in the tiles' constructors?
>>
>>53826576
>and each tile needs information about the other tiles in the world
Why? Why would each tile need to know about every other tile? I can't think of a good reason for that.
>>
>>53826576
Your biggest anti-pattern is using OOP.
>>
>>53826576
Your question is difficult to answer without knowing more about the information that each tile needs. Why would the tiles need said information at construction?
>>
>>53826604
A tile can be placed in another tile, basically as a destructible object. If the object (tile) is destroyed I need to delete it also from the parent tile. So I need access to the parent tile inside the 2d array.
>>
>>53826428
Javascript: best parts.
>>
>>53826576
Pass the board to all tiles. The board manages communication between tiles.
>>
>>53826642
if it's a 2D array, why would tiles have childs? If you want a child/parent structure, just make tiles have a referent to their parent tile. They don't need access to every tile.
>>
>>53826518
I am working on a trap manga that teaches you programming right now.
>>
>>53826642
wouldn't it need just the parent tile instead of every tile?
>>
>>53826663
Board? I think you're suggesting exactly what my problem is right now.

>>53826666
>>53826682
I guess you are right, didn't think of that for some reason. I'll just keep track of it's parent.
>>
>>53826539
everything is shit. you could literally do it better yourself if you really wanted to and put the time and effort into it.
>>
>>53826676
post MC?
>>
Who is using vi(m) here?
If you are how did you get into it?
How do you have it confirgured etc.
What are know abouts?

I can't find shit about it on google botnet(tm)
>>
>>53826871
vimtutor
if (!isdirectory("~/.vim/bundle"))
call system(expand("mkdir -p ~/.vim/bundle"))
call system(expand("git clone https://github.com/kien/ctrlp.vim.git ~/.vim/bundle/ctrlp.vim"))
endif

set rtp^=~/.vim/bundle/ctrlp.vim

filetype plugin indent on

set tabstop=2
set shiftwidth=2
set ignorecase
set smartcase
set ruler
set number

nnoremap <silent> <C-l> :nohl<CR><C-l>
>>
>>53826848
MineCraft?
>>
>>53826891
wow, that's fucking retarded
just save your .vim directory
>>
>>53826871
here's what I did when I was learning how to use vim:
went here - https://github.com/search?utf8=%E2%9C%93&q=language%3AVimL+stars%3A%3E1000&type=Repositories&ref=searchresults and started looking through different repos reading readmes and getting plugins I found useful to me.
>>
File: presented_by_aqua.jpg (143 KB, 1280x720) Image search: [Google]
presented_by_aqua.jpg
143 KB, 1280x720
>>53826391
it is not okay to like boys!
>>
>>53827088
even if I am a girl?
>>
>>53827088
true, that's why I like men
>>
>>53827131
this 2bh
>>
>>53827088
b..but i like lolis
>>
>>53826391
making a web game to learn some networking. so far ive learned how to send/recieve udp packets in C. wew
>>
>>53827121
you are not a girl fucking faggot
>>
I'm totally lost on how to fix this, there's multiple things wrong. Could someone point me in the right direction here and help me find what I did wrong?

http://pastebin.com/2kFmNWRP
>>
>>53827235
I am
>>
>>53827255
prove it or gtfo
>>
>>53827276
no
>>
>>53827255
Cup size?
>>
>>53827307
C, sometimes D depending on the bra.
>>
>>53827319
Plausible answer. What's your preferred type of bra?
>>
>>53827307
I am B
>>
>>53827333
Wire ones are the only ones I can get proper support from.
>>
I want to join your elite programming club. Teach me brothers
>>
>>53827121
then you seem to be lost
>>>/ck/
>>
File: 1431379318885.jpg (78 KB, 1254x261) Image search: [Google]
1431379318885.jpg
78 KB, 1254x261
unless you post pics then for all intents and purposes you are anon like the rest of us
>>
>>53827348
Average 2 fizzbuzzes for n many numbers, where n is an integer that you safely getchar().
>>
>>53827367
see >>53827088
>>
>>53827088
Well I'm a girl that likes girls...
>>
>>53827121
yes you fucking pedo
>>
>>53827384
that still makes you a faggot
>>
>>53827385
even if I we are the same age?
>>
>>53827396
underageb& then
>>
Distributed storage system that uses an anonymous attribute-based authorization protocol I devised.
>>
I am giving up on programming guys my math skills aren't up to par
>>
>>53827499
you can still become a node "programmer"
>>
>>53827499
95% of programming jobs don't involve math
>>
>>53826518
Please tell me this is true.
>>
>>53827548
What do they involve then?
>>
>>53827576
Not that Anon but logic, mostly. And the ability to take a problem and reduce it into abstract and quantifiable terms
>>
>>53827576
data entry
>>
>>53827586
if you can't into math you're going to suck at logic and completely miss many possible solutions
>>
>>53827604
Math helps but a lot of abstraction and solving problems doesn't necessarily rely on math.
>>
>>53827637
if you're unable to understand math it's a strong indication that you're retarded and that your programming ventures are going to suck ass
>>
>>53827687
95% of programming jobs do not require you to not suck ass
>>
>>53827687
True can confirm this is my biggest problem right now at work when I encounter math problems I have to spend a little while to figure out how to do and search it up
>>
reminds me of that part in starless where instead of curry with rice you get a steaming hot pile of shit with rice
>>
File: layne-staley-gi.jpg (58 KB, 500x300) Image search: [Google]
layne-staley-gi.jpg
58 KB, 500x300
pls be my gf /dpt/ girl
>>
>>53827576
google & stackoverflow
also strings and arrays
>>
>>53826391
Please stop this programming trap scat meme.
>>
>>53827844
Great I can do both of those things!
>>
    public static void main(String[] args) {
for(int i=0; i < 100; i++){
if (i % 15 == 0)
System.out.println("Fizzbuzz");
else if (i % 3 == 0)
System.out.println("Fizz");
else if (i % 5 == 0)
System.out.println("Buzz");
else
System.out.println(i);
}
}
>>
>>53827894
>System.out.println
WHY CAN'T A SIMPLE PRINTLN SUFFICE?
>>
>>53827894
10/10 hired

but it would make more sense logically


if(i % 3 == 0 && i % 5 == 0)



For the top
>>
>>53827923
both make sense, yours is more readable.
>>
>>53825617
Anyone?
>>
File: 640px-Capitol_at_Dusk_2.jpg (27 KB, 640x321) Image search: [Google]
640px-Capitol_at_Dusk_2.jpg
27 KB, 640x321
>>53827238
>wtf calling command-implementing functions just after runFun for no reason
>what is
std::string
's copy
>wtf having twice as many string variables, half of which aren't even used
>what is returning a value from a function
>wtf
{while(...) ...; ...; }

constructor
>wtf
'ch1'

>what is a command loop
>wtf not even calling lenFun
>what is the call stack

you (or whoever) didn't write this code, rather you SHAT it. It seems like you are unable to read and understand your own production. This list is only a tiny part of the things relevant to this program you must learn before you know them. Spoonfeeding you would be harmful, so put this aside, study, and come back to it later. And ffs don't call functions -Fun, it's not funny.
>>
Interview question time

Reverse a String




>>
>>53826391
Perceptron in Python for an open day at my university.
>>
>>53828088
How about I do you one better and reverse a line of words
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *stack[500];
int top = 0;

void push(char *str)
{
stack[top] = (char *) malloc(strlen(str) + 1);
strncpy(stack[top], str, strlen(str) + 1);
++top;
}

char * pop()
{
return stack[top--];
}

int main(int argc, char *argv[])
{
FILE *file = fopen(argv[1], "r");
char str[50], ch;
int x = 0;

while(fscanf(file, "%c", &ch) == 1)
{
if(ch != ' ' && ch != '\n')
{
str[x++] = ch;
}
else
{
str[x] = '\0';
push(str);
if(ch == '\n')
{
top--;
while(top >= 0)
{
printf("%s%c", pop(), top < 0 ? '\n' : ' ');
free(stack[top + 1]);
}
top = 0;
}
x = 0;
}
}

fclose(file);

return 0;
}
>>
File: 1452369082597.png (402 KB, 1024x768) Image search: [Google]
1452369082597.png
402 KB, 1024x768
>>53828088
'hello world'[::-1]
>>
#include <stdio.h>

int main() {
int n;
for(n = 1; n <= 100; n++)
switch((n % 3 == 0) | (n % 5 == 0) << 1) {
case 0: printf("%d\n", n); break;
case 1: puts("Fizz"); break;
case 2: puts("Buzz"); break;
case 3: puts("FizzBuzz"); break;
}
return 0;
}


>>53827973
if else if
Fizzbuzzes aren't readable. There are two duplicate expressions; this is inelegant and inefficient. The pattern-matching version, or this one above I posted some days ago are much better. It's also common for people to write this:
        for(int n = 1; n <= 100; n++)
if (n % 3 == 0)
System.out.println("Fizz");
else if (n % 5 == 0)
System.out.println("Buzz");
else if (n % 3 == 0 && n % 5 == 0)
System.out.println("FizzBuzz");
else
System.out.println(n);

And to wonder why this isn't working. In contrast, pattern-matching has the "most specific pattern first" rule, so it becomes both obvious and programmatically detectable that the error is due to it.
>>
>>53828088
import { reverse } from "string-reverse";
let result = reverse("javascript");

:)
>>
I'm not sure if this is the right place for this, but I'm looking to get into game development, using CryEngine 5, but I can't find any decent tutorials or even any real documentation, so I thought I'd ask around here.
>>
File: this article is real and true.png (329 KB, 711x610) Image search: [Google]
this article is real and true.png
329 KB, 711x610
>>53826459
*teleports behind you*
*unsheaths SCIP*
nice try kid
*rm -rf*
>>
>>53828147
js> import { reverse } from "string-reverse";
typein:40:40 SyntaxError: modules are not implemented yet:
typein:40:40 import { reverse } from "string-reverse";
typein:40:40 ........................................^
>>
>>53828088

gnirtS
>>
>>53828173
use Unreal engine instead
>>
>>53828124
Sorry you did not follow instructions we are looking for someone who follows company regulations

>>53828131
Sorry we will get back to you

>>53828147
I am sorry but this is not a programming language
>>
working on a Kerberos implementation in java for a uni project.

But the one thing that fucking gets me is I want to transfer data between clients as strings not raw bytes, so obviously I just create a new string and it's all nice right?

"No, fuck you" - Java

byte[] randomData = { /* some random data */ };
String newString = new String(randomData, "UTF-8");

byte[] convertedBack = newString.getBytes("UTF-8");

//randomData != convertedBack


Even without the "UTF-8" declaration, it still doesn't work. I thought that if I at least keep it consistent, it doesn't matter what the string looks like but I get the same bytes back.
>>
Hey /g/

I need to write data structure, mapping 4GB. My initial thought was a simple non-layered page table. A page size of 4KB would require allocating 4MB for the pointers to each page, which is a bit much, seeing as I'd likely only use a few MB at a time.

Any suggestions? I'm thinking of using a dynamic container of pointers to page tables. I haven't decided on which container, though.
>>
>>53828131
Why is python with its >muh clear code using some weird magic syntax instead of something like .reverse()?
>>
>>53828173
You were right to hold such doubt in your mind as to whether hence lie the answer to your enquiry
>>
>>53828201
how is it not a programming language?
without it you'd have a pretty hard time asking that question being its used to submit the data, in the browser


>>53828175
its 2015+1, use babel or traceur.
>>
>>53828201
I didn't want to work for your gayass company anyway
>>
>>53828194
What makes Unreal any better? I have it installed on my PC, as well as Unity and Cry, but I have yet to really pick which engine i'm going to use.
>>
>>53828173
google:// "tutorial game development using CryEngine 5"
>>
>>53828214
Any language that isn't retarded should complain when you try to do this. Your random data is going to contain plenty of invalid code points.

Not to mention you're trying to work around something that isn't even a problem. Why the FUCK would you NOT just use a stream of bytes to send FUCKING BYTES between clients?

KYS.
>>
>>53828257
Well I know it has a ton of documentation and tutorials and sample projects to download.
Tbh cryengine probably does too, but you didn't even google or went to official docs.
>>
>>53828201
void
swap (void *a, void *b, size_t s)
{
unsigned char *c1 = a, *c2 = b;
for (size_t i = 0; i < s; i++)
if (c1[i] != c2[i])
{
c1[i] ^= c2[i];
c2[i] ^= c1[i];
c1[i] ^= c2[i];
}
}

char *
reverse (char *s, size_t n)
{
for (size_t i = 0; i < n / 2; i++)
swap (&s[i], &s[n - i - 1], 1);
}
>>
>>53828214
strings aren't sequences of bytes, they are sequences of characters, period. And the String class enforces it.
What you could do if you absolutely want to not use a byte array is encode and decode those random bytes into a string with Base64. It will take 4 characters for 3 bytes, but it's bulletproof.
>>
>>53828292
>2016
>using xor swap

would not hire
>>
>>53828088

let rev (s : string) = Array.foldBack (::)
>>
>>53828331
Why? It's 2017, every compiler optimises xor swap.
>>
>>53828292
very nice. it's inplace and efficient, I like it.
>>
>>53828339
*Array.foldBack (::) ""
>>
>>53828231
it's not magic at all if you understand the slice syntax
otherwise there's ''.join(reversed(s))
>>
>>53828348
what do you mean "optimise xor swap"? Is there a faster alternative to xor swap that a very clever compiler can use instead?
>>
>>53828339
*Array.foldBack (::) "" s

This fucking captcha man, makes it fucking horrible when autopost goes too soon
>>
>>53828357
but what if you pass "バカ外人" to it?
2010+5 and not supporting chinese on these mongolian cartoon forums.
>>
>>53828378
no
>>
>>53828378
on a modern computer a temporary variable can actually be faster

one of the reasons you should stop with dumb premature micro-optimizations like that and let your compiler worry about it first.
>>
>>53828418
depends on compiler, optimization (level, or specific optimization or even things like peephole) and data size
but as always, profile and benchmark before premature ejaculation.
>>
>>53828418
>on a modern computer a temporary variable can actually be faster
Wrong
1: Every sane compiler optimises xor swap
2: Without any optimisation xor swap is smaller and faster
3: With optimisation xor swap just looks better
>>
File: code.png (31 KB, 575x175) Image search: [Google]
code.png
31 KB, 575x175
Is it useful for someone who has no knowledge of programming to complete all the courses on codeacademy.com?

Aside from the ones you have to pay for, I mean.
>>
>>53828392
ウィアブー、自分を殺してください。
>>
>>53828449
No the best way to learn programming is to pick up a modern programming book read through the book and complete the review and exercise questions once you get through the basics then build your own small projects and that is when you really start to learn how to do it.
>>
reminder that strings are not just "a sequence of chars"

they are graphs of graphemes
>>
File: malloc.png (1 MB, 1280x720) Image search: [Google]
malloc.png
1 MB, 1280x720
>>53828124
>>
>>53828453
>自分を殺してください
lol

>>53828470
http://stackoverflow.com/a/14879184
Only the first reason on that list is useless.
>>
>>53828447
what you're using simd? or other vectorizations that compilers generally don't do, yet?
>>
>>53828533
3 is not a reason and the rest are the same argument.
>>
>>53828556
No
>>
File: not an argument.jpg (3 KB, 94x124) Image search: [Google]
not an argument.jpg
3 KB, 94x124
>>53828571
>not a reason
>>
>>53828593
>>not a reason
It is not a reason because it is a reply to another argument made in the same thread. So no, it is not a reason.
Did you even read it?
>>
>>53828292
>>53828348
>>53828447
void swap1 (char* a, char* b)
{
char c = *a;
*a = *b;
*b = c;
}
void swap2 (char* a, char* b)
{
*a ^= *b;
*b ^= *a;
*a ^= *b;
}

Compiled with GCC using -O3
(removed setting up stack)
_swap1:
mov edx, DWORD PTR [esp+8]
mov eax, DWORD PTR [esp+12]
movzx ebx, BYTE PTR [edx]
movzx ecx, BYTE PTR [eax]
mov BYTE PTR [edx], cl
mov BYTE PTR [eax], bl
ret
_swap2:
mov eax, DWORD PTR [esp+4]
mov ecx, DWORD PTR [esp+8]
movzx edx, BYTE PTR [eax]
xor dl, BYTE PTR [ecx]
mov BYTE PTR [eax], dl
xor dl, BYTE PTR [ecx]
mov BYTE PTR [ecx], dl
xor BYTE PTR [eax], dl
ret


Which one's smaller and more efficient again?
>>
>>53828602
The second because it uses less mov and mov takes more byte than xor.
I am not going to talk about movzx
>>
>>53828623
1 movzx vs 3 xor
>>
>>53828666
About the same
>>
>>53828623
>>53828684
Confirmed for not knowing shit
8B 54 24 08          mov         edx,dword ptr [esp+8]  
8B 44 24 0C mov eax,dword ptr [esp+0Ch]
0F B6 1A movzx ebx,byte ptr [edx]
0F B6 08 movzx ecx,byte ptr [eax]
88 0A mov byte ptr [edx],cl
88 18 mov byte ptr [eax],bl

Total bytes: 18
8B 44 24 04          mov         eax,dword ptr [esp+4]  
8B 4C 24 08 mov ecx,dword ptr [esp+8]
0F B6 10 movzx edx,byte ptr [eax]
32 11 xor dl,byte ptr [ecx]
88 10 mov byte ptr [eax],dl
32 11 xor dl,byte ptr [ecx]
88 11 mov byte ptr [ecx],dl
30 10 xor byte ptr [eax],dl

Total bytes: 21
>>
>>53828789
movzx takes more cycles.
>>
>>53828789
>>53828621
>>53828666
>>53828684
Benchmark it you shitters
>>
>>53828789
Is there a reference anywhere for assembly -> machine code translation? Wanted to try JITing but could not find a reference
>>
>>53828824
>I'm losing the argument
>oh I know, I'll just start making up shit
>>
    while(i < productionGoal){
sem_wait(&mutex);
sem_wait(&empty); /* wait for the number of empty spots to be at least 1 */
int random = ( rand() % 100) + 1; /* generate a random number between 1 and 100 */
printf("production: %d\n", random);
sem_post(&full); /* increase the number of full spots by 1 */
bufferTop++;
sem_post(&mutex);
i++;
}


is this right? or should i have the mutex on the inside?
>>
File: intel guide.png (58 KB, 1091x684) Image search: [Google]
intel guide.png
58 KB, 1091x684
>>53828824
Do you run a pentium 4?
>>
I'm writing a program in C++ and I want to be able to append information to a string variable from any function, any object module any source file I want. I know I can either use some global static variable, or refactor all of the functions to accept a reference to a string. Someone even suggested using a namespace. What would be the best solution for this?
>>
>>53828907
Yes
>>
>>53828886
>holding the mutex while waiting on empty
I might be wrong but I think this can't be right. Shouldn't the mutex be locked after sem_wait(&empty) and unlocked after sem_wait(&full) ?
>>
>>53828971
Or not locked at all depending on what it protects exactly
>>
>>53828464
The reason I'm doing the courses on codeacademy is because I have no idea which programming language to learn, so I want to learn the basics for a variety of them.

Besides, what programming books do you mean?
>>
>>53828830
I learned everything from decompiling assembly.
There's no good reference as other than the basic instructions, EVERYTHING IS INCONSISTENT.
It's really awful.

I liked using Visual Studio because it gives it in that nice format above. But anything where you can see the assembly as well is fine.
>>
>>53828921
>what is the best solution?
Whatever works. Don't worry too much about that I would say. The reference thing is probably very dumb since the exact same reference is passed over again, so it's actually way to obfuscate the fact that you're using global variable and it's shitty in a lot of ways. Namespace it if that makes sense, it doesn't change a lot. What is this variable for, that you need to access so badly?
>>
Is Recursion a meme? Will I ever use it in real programming?
>>
>>53829105
Any time you're working with trees.
>>
>>53829105
Are trees a meme? I have never worked on any trees in any Software company
>>
>>53828292
xor swap is the worst swapping method to use, even stack swap is faster.
>>
File: functional programming vs.png (2 MB, 1000x3000) Image search: [Google]
functional programming vs.png
2 MB, 1000x3000
>>53826518
C? Ha
>>
>>53829105

Recursive functions are a meme. But the concept of recursion is not.
>>
>>53829177
What do you mean? Give an example
>>
>>53829105
It's not a meme so much as it is a mistake. The whole idea of a call stack and the "function" abstraction is a mistake.
>>
>>53829177
Scheme is nice tho
>>
>>53829234
Coroutines > Subroutines? What do you mean?
>>
>>53829229
I think he means that it's really helpful to think about some problems recursively but you should still implement them iteratively (at least when performance matters)
>>
>>53829276
I need an example in code please and an explanation
>>
>>53829234
Elaborate bb
>>
>>53829177
>be me
>C programmer
>have refcounted singly-linked list like structure.
>"Ah, yes: when in the deallocating function, I decrement the refcount to zero, I'll have to also recursively deallocatr the next element..."
>recognise the terminal recursion pattern
>immediately write a do-while loop
>live happily ever after
Amirite?
>>
>>53829315
See >>53829335
>>
>>53829162
>all FP is Scala
most non-Scala functional programmers agree that Scala has a lot of bloat/problems, and that includes one of the creators of Scala (https://www.youtube.com/watch?v=uiJycy6dFSQ)

While there is some run-time overhead to typeclasses (at least on GHC... I don't know if Rust has this and I have yet to investigate), it should be faster than virtual method lookup (not that this really helps Haskell overcome the speed barrier to being as fast as Java/C#/C++)

like all subreddits, /r/Haskell is a bunch of garbage circle-jerkers who can't take any other opinions in their safe space
>>
File: 1457274399165.jpg (44 KB, 544x529) Image search: [Google]
1457274399165.jpg
44 KB, 544x529
>>53829126
>>53829139
>using recursion for trees
>>
>>53829105
it's not very efficient for the computer, but it is very efficient for the programmer. not a meme
>>
>>53829315
dynamic programming is a great example of it.
here's a pretty good chapter about it: http://jeffe.cs.illinois.edu/teaching/algorithms/notes/05-dynprog.pdf
it illustrates well how starting from a simple recursive function you can write a far more time efficient (but more complex) algorithm
>>
>>53829373
Faggot. Why not? It fits brilliantly.
>>
File: Screenshot_2016-04-02-13-09-11.png (161 KB, 1080x1920) Image search: [Google]
Screenshot_2016-04-02-13-09-11.png
161 KB, 1080x1920
>>53828621
>>53828789

Now let's try with something other than x86...

What is smaller? What is more efficient?
>>
>>53829406
most dynamic programming problems may be solved just by adding memoization without changing the algorithm from being recursive
>>
>>53829416
Stack overflow
>>
>>53829373
Alright, write a preorder traversal without recursion. I bet it won't be pretty.
>>
File: cygwin.jpg (49 KB, 286x567) Image search: [Google]
cygwin.jpg
49 KB, 286x567
The issue I'm having here is understanding why test 3 and 4 do not work.

Why is it that the finite values test works, the mixed test works, but then subsequent tests to not? I simply do not understand what is wrong.

Can only modify array_prod and use only isfinite(). Clearly homework given that restriction.

paste/tSM1KUGz
>>
>>53829373
Are you serious?
>>
>>53829436
Do your own homework, sport.
>>
>>53828088
#include <stdio.h>
#include <string.h>

int main()
{
char str[] = "non reversed string";
printf("original: %s\n", str);

int len = strlen(str);
int len2 = len / 2;

for (int i=0 ; i<len2 ; i++)
{
int temp = str[i];
str[i] = str[len -i -1];
str[len -i -1] = temp;
}
printf("reversed: %s\n", str);
return 0;
}


Can i get the job sir?
>>
>>53829458
He was giving you a problem that is easily solved with tree recursion you dense motherfucker
>>
>>53829428
I don't know arm, but...
Still looks like temporary values, which is exactly what I argued.
>>
>>53829439

By that it not working I meant that test 3 should be around 60,629,760,000. I've goofed something big in the math some how, but several finite values outputs what you'd expect.
>>
>>53828088
require(reverse-a-string)
>>
>>53826391
I am doing my first course in C programming. I have to write functions that do boring shit like copy strings and shit like that for the first assignment. So far, the textbook has covered absolutely no C programing. It just babbles on about networks. I have studied some C programming on my own, but that was a while ago.

Right now I just copied and pasted shit from GitHub to finish my functions because the textbook isn't helping me become a better C programmer. What's the best way to not get caught? Right now I am changing some variable names, but that's about it.
>>
>>53829429
those tend to be more clear with a simple loop though
>>
>>53829473
Recursion is shit :^)
>>
>>53829530
Troll harder please
>>
>>53829514
>I want to be a le coder, but I am lazy
>how do I not get caught cheating?
>>
>>53828447
literally retarded
>>
>>53829559
I have literally no clue how to do this shit in C, and they don't plan on teaching me. I only have one book on C programming and it's too basic to help me.
>>
>>53829514
You find a new degree. You are not in the right mindset to be in the computer world friend.
>>
>>53829428
>eor
was xor taken?
>>
>>53829554
If you actually spent some time learning instead of browsing memes all day, you would learn more about computers you know.
>>
>>53829589
I had a hard time with C too. I just messed around with things until it worked. Seriously, that's what I did
>>
>>53829590
I don't think so. I got good grades in the last courses I just finished. This course sucks. All the programing is in C, but they don't teach intermediate C programming.

>>53829609

Should I buy K&R or is that a beginner's book too?
>>
>>53829589
you didn't write your first post like that, sorry but you're going to have to start from the beginning like everyone else
>>
>>53828088
reverse = lambda x: x[::-1] # :^)
>>
>>53829475

Indeed. I posted that to support your argument. While they may be close in performance on x86, xor swap gets blown out of the water on RISC architectures.

>>53829530

Recursion is fine. It's a natural way to traverse linked data structures, and it doesn't really have any good alternatives when doing something like backtracking (although you aren't going to get any tail call optimization in recursive backtracking)

>>53829514

Anon, go read C Primer Plus, and do the assignment yourself. If you can't do basic string operations on your own, you really should give up programming and pursue another career.

>>53829594

I don't know. Maybe they just wanted to be different.
>>
>>53829599
There are some things that are better done with recursion, why not utilize your stack? I'm just saying, just because you autistic mind thinks something is shit, doesn't mean it can't be applied (rather elegantly I might add).
>>
>>53829632
Wrong post?
>>
making the player character 3d took a week longer than i had hoped but it's so fucking good and totally worth it

it has a freaking sweet ambient lighting effect which actually enhances the game because i don't overdo the effect like some dark as my soul 12 year old wannabe JJ abrams UE4 dev
>>
how do i change this to make it create the file in the same directory as a.out?
 
#include <stdio.h>

main() {
FILE *fp;

fp = fopen("/tmp/test.txt", "w+");
fprintf(fp, "This is testing for fprintf...\n");
fputs("This is testing for fputs...\n", fp);
fclose(fp);
}
>>
>>53829657
> Implying Ruby can reverse a String or copy a string

Remember Strings are immutable guys Superior Java Master race
>>
>>53829657
I can manipulate strings in Python and Java all day, just not in C.
>>
>>53829659
Recursion or indirect Recursion is literally not allowed at my workplace.

It's not "le elegant", it's a meme for new programmers.
>>
>>53829690
Remove the "/tmp/" thing.
>>
>>53829594
Maybe they wanted it to make a bit more sense.

it's Exclusive OR, but most people say it as eXclusive OR
>>
>>53829735
Why doesn't your work allow Recursion
>>
>>53829736
thanks
>>
>>53829755
>most people say it as eXclusive OR
or X-OR
>>
>>53829735
We used it throughout my data structure course, and I found MUCH better solutions using recursion. (Honestly I don't know why I'm arguing this)

You are literally spouting from your ass. Take your autism elsewhere please.
>>
>>53829736
that would put it in the directory you're currently in, not the directory the binary is in
afaik you'd have to extract it out of the first argv
>>
>>53829774
That's what I meant. eXclusive OR, or "X OR"
They wanted Exclusive OR, or "E OR"
>>
>>53829715

Do you know how to use pointers, if statements, and for loops?
>>
>>53829758
Predictable execution, makes it easier to debug and you don't have runaway code
>>
>>53829791
>data structure course
good one dude
>>
>>53829813
Yes.
>>
File: tmp.png (95 KB, 1365x386) Image search: [Google]
tmp.png
95 KB, 1365x386
>>53826391
Rewriting my website in raw Python/Jinja, fuck frameworks.
>>
File: eeyore.jpg (37 KB, 600x600) Image search: [Google]
eeyore.jpg
37 KB, 600x600
>>53829800
>>
>>53828447
not true. in a xor swap, each instruction depends on the results of the previous instruction, forcing it to run serially on a pipelined processor. this isn't the case for a tmp variable swap
>>
>>53829817
>Predictable execution,
Yeah, it'll recurse. Pretty predictable.
>makes it easier to debug
You can argue both ways. I can view the stack and see the previous executation states. This allows me to see when it all went wrong. For example, if I'm expecting, lets say a = 3, and b = 4, and on the 5th stack, I see a = 4, and b = -2, I know something went wrong there and can debug that stackframe.
>and you don't have runaway code
If you hit a stackoverflowexception, you've not implemented it correctly. It's not the recursion's fault. It's like having an infinite loop and blaming linear programming.
>>
>>53829882
you missed his (retarded) point
also stop copy-pasting from wikipedia
>>
>>53829838
get off your horse
>>
Java may not be perfect, but it's literally one of the best languages in existence if you actually want to do anything and not just masturbate with how pro you are for using an early beta language. I'm so sick of this bullshit.
>>
>>53829126
>>53829436
>>53829473
>>53829659
>>53829758
recursion is stupid and dangerous. it's not just me saying it, it's a widely recognized fact by many organizations

there is nothing wrong with using an explicit stack to traverse a tree, it makes just as much sense as using recursion, you just use the stack to keep track of where you are in the tree
>>
>>53829916
get a trip code pls
>>
>>53829229
a loop is a form of recursion. you don't need recursive function calls
>>
>>53829842

Then you know how to process strings. A string is just a pointer to a block of memory containing characters. The last character generally has ASCII value 0. You loop over the characters and process shit.

Here's a simple test for you: given a null terminated string argument, replace all instances of the character 't' with the character 'j'. The string should be mutated in place, and the function should return void.
>>
>>53829916
You're not convincing anyone here prajeet.
>>
>>53829953
>a loop is a form of recursion

No, recursion is a form of loop. Why do you think they call it a call STACK?
>>
people literally died because of recursion
>>
>>53829916
THIS
>>
>>53829916
OutputStreamWriter writer = new OutputStreamWriter(new BufferedWriter(new OutputStream(socket.getOutputStream())));
>>
>>53830003
Prajeet. You are literally the only one in these threads who thinks Java is good. Please don't embarrass yourself the samefagging.
>>
>>53829925
Thanks for an explanation, instead of spouting "YOU ARE WRONG" at every turn. You are the hero we need.
>>
>>53829916
>Javafag getting butthurt even though nobody's talking about Java
Classic
>>
>>53830020
Is Java a lisp?
>>
>>53830025
i consistently type in lowercase with the occasional all caps. >>53829916 is not me
>>
>>53829925
>recursion is stupid and dangerous.
Why? Sometimes it can be great.
>>
File: Java.png (17 KB, 484x402) Image search: [Google]
Java.png
17 KB, 484x402
>>53830033
Javafag was getting butthurt BECAUSE nobody was talking about Java
>>
>>53829797
The first element just returns the name of the binary, not the path in which it's located, if you want to extract the exact path of the binary, no matter from were are you running it, you must rely in system libraries.
>>
>>53829986
Seems reasonable.
Recursion can be re-written as a loop, with an explicit stack if necessary.
It's easy to set and understand the bounds for your explicit stack, to avoid and understand memory bugs, but stack recursion is "infinite" meaning not actually infinite, and you don't really have any control over stopping or even predicting a stack overflow until it's too late.

You'll end up essentially writing a recursive algorithm, just not in a recursive style.
>>
>>53829925
Recursion is powerful because it is provable, in an elegant way.
Inefficient, maybe, but if you have to use an explicit stack you can convert to when necessary.
>>
>>53829261
>>53829317
Recursive functions (not the mathematical concept, but the entities in programming languages) are are not fundamental to programming in any way.

Getting rid of the stack leads to a lot more ways of thinking about programming. Calls are "horizontal" instead of up and down a stack. If you don't have "automatic" local variables, coroutines aren't any more complicated than subroutines.

Exceptions are also tainted by the stack. Errors should interrupt the program in a way that it can be resumed. They should be completely transparent, just like a CPU exception/trap/fault. The "theory" like error monads and CLU/ML exceptions is totally wrong and a big step back from CPU error handling, PL/I conditions (and Common Lisp's which are based on Multics and PL/I), and even BASIC's ON ERROR.
>>
>>53829986
Some languages like D allow you to require a warning for functions that can't be TCOed
>>
buffer[bufferTop%BUFFER_SIZE] = random; /* add item to the top of the buffer */
bufferTop++;

C's the most satisfying language to code in
>>
>>53830123
buffer[bufferTop++ % BUFFER_SIZE] = random;

FTFY
>>
>>53830041
>I deliberately don't properly capitalise my sentences, even though I know I should. This is totally not a shallow attempt to make me appear to be a different person. Really guys!
I would be far more convinced that you were different people if you typed the same. Samefags tend to to do really stupid shit like type in all lowercase, like nobody does deliberately, thinking they'll look like totally different posters.
>>
>>53830146
friendzoned again
>>
>>53829973
void tf(char *s){
while(*s++)
*s == 't' ? *s = 'j' : continue;
}
Thread replies: 255
Thread images: 28

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.