[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: 26
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>54545017

What are you working on /g/?
>>
>>54555253
cara
>>
>>54555253
Either going to write a brainfuck -> C transpiler or an assembler + emulator for some architecture
still deciding
>>
>>54555253
>What are you working on /g/?
It's a Sunday, I ain't working on anything.
>>
>>54555273
Just write a befunge to C transpiler.
>>
>>54555253

im gonna copy DOOM and sell it to cancer patients as a false cure

t. Raj Muturi
>>
>>54555290
I'm not that good/determined
>>
>>54555253
Learning muh algorithms
>>
>>54555379
Algorithms are fun
>>
>>54555273
Why not a bf to assembler? It should be easy as fuck.
>>
>>54555537
I don't know any assemblies.
And I just finished my bf to C, it's actually exactly as simpler as an interpreter in C is
>>
>>54555549
You finished it in 25 minutes?
>>
>>54555572
yep
 →  ls
bf2c.c hw.bf
→ cat hw.bf
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
→ gcc bf2c.c -o bf2c
→ ./bf2c hw.bf
→ ls
bf2c bf2c.c hw.bf out.c
→ gcc out.c -o hw
→ ./hw
Hello World!
>>
>>54555591
Noice. Care to pastebin it?
>>
>>54555637
I made a gist but apparently those links are too spammy for moot

http://pastebin.com/yi6hU1gz

It honestly shouldn't take anyone more than 25 minutes, I wasted some time watching tv of course but it's no race
>>
>>54555687
Well shit. Yeah that should've only taken 25 minutes. I guess I got fancy when i wrote my interpreter. I think I used a dynamic array instead of statically allocating some large number of registers.
>>
File: image.png (15 KB, 256x64) Image search: [Google]
image.png
15 KB, 256x64
public class Prime {
public static void main(String[] args){
int[] primes = new int[1];
primes[0] = 2;
int number = 2;
int n = Integer.parseInt(new Scanner(System.in).nextLine());
System.out.printf("0 1 2");

while(number <= n){
boolean isPrime = true;
for(int i = 0; i < primes.length; i++){
if(number % primes[i] == 0){
isPrime = false;
}
}
if(isPrime == true){
System.out.printf(" " + number);
int[]temp = new int[primes.length+1];
for(int i = 0; i < primes.length; i++){
temp[i] = primes [i];
}
primes = temp;
primes[primes.length-1] = number;
}
}
}
>>
>>54555784
Yeah when I did my interpreter way back when I did that too, as I think the official spec is an unlimited amount of memory
>>
>>54555848 (me)
I wrote this to make it feel comfy
#! /usr/bin/sh
bf2c $1
gcc out.c
rm out.c


comfy as fuck:
 →  ls
cellsize.bf
→ bf cellsize.bf
→ ls
a.out cellsize.bf
→ ./a.out
8 bit cells

>>
>>54555687
Here is a reimplementation of your program (although it's not exactly equivalent), because I felt like writing it.
#include <stdio.h>
#include <limits.h>

int main(void)
{
static const char *lut[UCHAR_MAX] = {
['>'] = "++ptr;",
['<'] = "--ptr;",
['+'] = "++*ptr;",
['-'] = "--*ptr;",
['.'] = "putchar(*ptr);",
[','] = "*ptr = getchar();",
['['] = "while (*ptr) {",
[']'] = "}",
};

puts("#include <stdio.h>\n"
"int main(void) {\n"
"\tchar array[30000] = {0};\n"
"\tchar *ptr = array;");

int c;
while ((c = getchar()) != EOF)
if (lut[c])
printf("\t%s\n", lut[c]);

puts("}");
}
>>
>>54555872
What a shitty way to implement a dictionary. I like it.
>>
>>54555878
>dictionary
Pybabby, please go. It's a lookup table.
>>
>>54555899
I don't even use Python. I'm pretty sure the term "dictionary" isn't from Python either
>>
>>54555253
I have a structure in a C program which has a pointer value to another structure in it. How come when I initialise the structure the pointer is not null?
>>
>>54555917
you have to initialize the pointer to null
struct s {
struct r *p;
int a;
};

//...
struct s thing = {NULL, 5};
>>
>>54555878
Serious question: what makes this code shitty? What could be done to make this better?
>>
>>54555928
Why doesn't the compiler initialise it to None by default>
>>
>>54555931
He uses an array of size UCHAR_MAX (most likely 255) to hold 8 values. In other words, his program unnecessarily has 248 unused char pointers for no reason
>>
>>54555946
>None
Kill yourself.
>>
>>54555878
>shitty
Nigga that works perfectly and gets the job done. O(1) lookup time.
>>
>>54555931
>what makes this code shitty?
As the author of the code, I think it's very elegant. It's just an array of char *'s which map each character to a string.

>>54555956
That's the price of using a lookup table. It does use more memory, but it's only a single array access to get the data.
If I didn't make it UCHAR_MAX, the program could index past the end of the array if it's given the wrong characters.
>>
>>54555967
None, null, nil, same thing. If you were a function in C, you would be fgets, because it sounds like faggot.
>>
>>54555981
Which is why you use some sort of hash
Not that it really matters here

>>54555980
A hash would still be O(1) :)

>>54555987
bad
>>
>>54556002
>>54556002
A proper hashtable would be just as wasteful as this lookup table, if not moreso.
>>
>>54556024
Obviously. As I said in my first post, it's a shitty implementation for a dictionary, but here, it doesn't matter/is fine.
If you care about space though, I think the switch is best, maybe?
>>
>>54556032
>for a dictionary
Again, it's a fucking lookup table. There is a difference.
LUTs are have VERY quick accesses, and are very efficient if it's range is mostly full. It only wastes space if you're only defining a few things over the whole range.
However, over the range of chars, the wasted space is completely trivial. My code only wastes ~2KiB on a 64-bit system. Such a sparse lookup table over the range of integers would be incredibly stupid however.
>>
>>54556064
it has already been said that in this case it is fine
calm
>>
>>54556064
Wouldn't a switch statement be O(1) as well?
It's not like the number of possible operators is ever going to increase in size.
>>
>>54556084
Yes, the switch is fine.
I just like my way better because it has less duplicated code.
>>
>>54555872
I know you can refer to struct members in initializers, but I didn't know you can refer to specific array indexes like that.

Is this C99?
>>
>>54556084
I don't think that's a valid way to say something is constant, by saying that the 'n' will always be 8
switches are usually binary searches I think, so you could argue it's O(logn)
>>
>>54556099
>Is this C99?
Yes.
>>
>>54555872
#define offset '+'
#define max ']'

int main(void)
{
static const char *lut[max - offset] = {
['>'-offset] = "++ptr;",
['<'-offset] = "--ptr;",
['+' - offset] = "++*ptr;",
['-' - offset] = "--*ptr;",
['.'-offset] = "putchar(*ptr);",
[','-offset] = "*ptr = getchar();",
['['-offset] = "while (*ptr) {",
[']'-offset] = "}",
};

puts("#include <stdio.h>\n"
"int main(void) {\n"
"\tchar array[30000] = {0};\n"
"\tchar *ptr = array;");

int c;
while ((c = getchar()) != EOF)
if (c >= offset && c < max && lut[c-offset])
printf("\t%s\n", lut[c-offset]);

puts("}");
}
>>
>>54556091
For "case", "break", and "fputs" I suppose, lol
I do like your implementation though
>>
>>54556109
That has a more complicated conditional, so every access will be minutely slower.
It also relies on implementation defined behaviour, as to what the character set is, as nitpicky as that is.
>>
>>54556109
winrar
rename 'offset' to 'o' so there's less duplicated code xd
>>
>>54556109
I think I see what you did here.
Nice.
>>
I don't know any assembly but shouldn't it be rather simple to go straight from brainfuck to machine code, or at least assembly, since there are only 8 instructions, you just have to know the assembly equivalent for each of them? i.e., instead of doing '+' => "++*ptr;", you do "+" => "\tmobv $b -1(%rbp)\n\tmovzbl -1(%rbp), %eax\n\taddl $1, %eax\n" or whatever it's supposed to actually be
>>
>>54556109
sexy, though I'm not convinced that a switch wouldn't be faster.
>>
>>54556185
array access is literally faster than a binary search
>>
Anybody here know how to use WireShark to read in coming network packets for a specific video game to use as the basis for a video game hack?

Really fucking specific I know, but basically I want to read the data coming in from a network stream them use ESP off that data stream however I'm a little loss.

I'm having a hard time decerning what any of these seemingly random 4 digit/letter indicators are and google-fu isn't helping me here.
>>
>>54556200
wrong thread
>>
>>54556214
Actually I did mean to post it here, this is what I'm programming atm, a little lua script attached to wire shark that will tell another program what pictures to overlay on my monitor.

Just having issues finding anyone that knows anything about this, if there is a more releveant thread I am not seeing it
>>
>>54556185
    .file    "lut.c"
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.align 8
.LC0:
.ascii "#include <stdio.h>\12int main(void) {\12\11char array[30000] = {0};\12\11char *ptr = array;\0"
.LC1:
.ascii "\11%s\12\0"
.LC2:
.ascii "}\0"
.section .text.unlikely,"x"
.LCOLDB3:
.section .text.startup,"x"
.LHOTB3:
.p2align 4,,15
.globl main
.def main; .scl 2; .type 32; .endef
.seh_proc main
main:
subq $40, %rsp
.seh_stackalloc 40
.seh_endprologue
call __main
leaq .LC0(%rip), %rcx
call puts
.p2align 4,,10
.L2:
call __getreent
movq 8(%rax), %rcx
call getc
cmpl $-1, %eax
je .L9
subl $43, %eax
cmpl $49, %eax
ja .L2
leaq lut.2958(%rip), %rdx
cltq
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je .L2
leaq .LC1(%rip), %rcx
call printf
jmp .L2
.p2align 4,,10
.L9:
leaq .LC2(%rip), %rcx
call puts
xorl %eax, %eax
addq $40, %rsp
ret
.seh_endproc
.section .text.unlikely,"x"
.LCOLDE3:
.section .text.startup,"x"
.LHOTE3:
.section .rdata,"dr"
.LC4:
.ascii "++*ptr;\0"
.LC5:
.ascii "*ptr = getchar();\0"
.LC6:
.ascii "--*ptr;\0"
.LC7:
.ascii "putchar(*ptr);\0"
.LC8:
.ascii "--ptr;\0"
.LC9:
.ascii "++ptr;\0"
.LC10:
.ascii "while (*ptr) {\0"
.align 32
lut.2958:
.quad .LC4
.quad .LC5
.quad .LC6
.quad .LC7
.space 104
.quad .LC8
.space 8
.quad .LC9
.space 224
.quad .LC10
.space 8
.quad .LC2
.ident "GCC: (GNU) 5.3.0"
.def puts; .scl 2; .type 32; .endef
.def __getreent; .scl 2; .type 32; .endef
.def getc; .scl 2; .type 32; .endef
.def printf; .scl 2; .type 32; .endef

Really doubt it. I'll post a switch method and the disassembly.
>>
Learning python because the wife is taking IT in September and its their "intro" language.
>>
File: Cute!.webm (2 MB, 924x520) Image search: [Google]
Cute!.webm
2 MB, 924x520
>>54556250
Are you going to program nude together :3
>>
>>54556266
Hah, not likely.
>>
>>54556289
Are you over 25 or do you guys not love each other anymore anyway?
>>
>>54556289
It's what I'd do with my hypothetical wife, but you do you
>>
I'm going to be studying sound programming soon. Anything specific for that field that I should learn?
>>
>>54556322
sounds neat
can't wait to hear how it goes
>>
>>54556322
Every discipline of programming requires something different.
For example, you don't need linear algebra to write device drivers, but to make a 3D game engine, you do.
>>
>>54556365
What kind of fucking response is this?
"Thinking of baking a cake, what sort of ingredients should I consider?"
"Different foods require different recipes. For example, you don't need cheese for a simple brownie, but you might need it for pizza."
>>
>>54556377
Yes?
Your statement is factually correct and so is mine.
>>
>>54556389
It contributes absolutely nothing, friendo
>>
#include<stdio.h>
#include<limits.h>

int main(void)
{

puts("#include <stdio.h>\n"
"int main(void) {\n"
"\tchar array[30000] = {0};\n"
"\tchar *ptr = array;");

int c;
while ((c = getchar()) != EOF) {
char *s;
switch (c) {
case '>': s = "++ptr;"; break;
case '<': s = "--ptr;"; break;
case '+': s = "++*ptr;"; break;
case '-': s = "--*ptr;"; break;
case '.': s = "putchar(*ptr);"; break;
case ',': s = "*ptr = getchar();"; break;
case '[': s = "while (*ptr) {"; break;
case ']': s = "}"; break;
default: s = "";
}
printf("\t%s\n", s);
}
puts("}");
}


GCC pretty much makes the lut for you, the code is rather obtuse, don't know whether the contortions it goes through is faster or not. It's definitely larger.
http://pastebin.com/Qn4WcPEc
>>
>>54556398
Neither does your question, memeboy.
>>
>>54556309
Ill give it a shot when the time comes just to see the look on her face.

>>54556294
Over 25!
>>
>>54556409
Darn, I was hoping it would help you understand that contributing absolutely nothing was something you should avoid doing, guess I failed at that
>>
Is there some sort of programming 101 somewhere?
What are the most useful programming languages to sell yourself nowadays?
>>
>>54556498
depends on what you want to do?
webshit? JS (node, angular, whatever), python (django, flask, whatever), ruby (on rails or not)
meme companies (google, amazon, facebook, microsoft)? JS, Java, C++, maybe C# for MS
>>
>>54556322
Signal theory will define most of what you do.

Music theory is useful, as are psychoacoustics depending on what you want to do with it.

But if nothing else read a book or at least play some wiki golf around signal theory.
>>
>>54556512
I'm actually looking for what to do.
Midlife crisis, I want to drop my current shitty job, and the only advantage it gets me is free time at work, a lot, so I want to use it to learn to "program" (as vast as this may seem) and get some useful skill to find a new job.
So whatever's the most requested in general.
That could be a good start to see how all of this work and maybe later try to make some more personal work/creation.
>>
>>54556548
>and get some useful skill to find a new job.
Web dev has been in high demand for a while and will continue to be as such for at least the next five years. Everyone being honest with themselves will admit it's basically a bubble and it's going to burst one day. Systems programming has been a slow grower but tends to be a bit steadier.

Honestly if you're looking for money go the mobile or web routes, there's not a lot of craftsmanship in it but it pays damn well for the qualification you need to get a job in those areas (having a pulse, primarily)
>>
>>54556548
Web shit is easy for jobs I think, not really sure.
If your current job is even somewhat tech related that will help a lot, if not, you're out of luck
>>
>>54555872
>static const char *lut[UCHAR_MAX] = {
> ['>'] = "++ptr;",
wait, what the fuck is this?
>>
>>54556706
C99 designated initialisers.
>>
>>54556717
thanks for the info
>>
Best way to program in python on windows?
>>
>>54556783
PYCharm
IDLE
Linux VM
>>
>>54556800
Thank you.
>>
>>54556783
Pycharm if you really have to stay on windows

but preferrably dual-boot for OS X or Linux for their dev environment
>>
>>54556783
Notepad++ works just fine for me desu
>>
>>54556539
Thank you.
>>
>>54556783
If you want an IDE with autocomplete and shit, PyCharm.
Otherwise, Notepad++ works fine.
>>
Do you have to be good at recursion to use functional languages?

I had fun zipping and mapping through lists of lists of lists but recursion just fries my brain
>>
File: Programming-Projects-for-N00bz.jpg (311 KB, 1261x1000) Image search: [Google]
Programming-Projects-for-N00bz.jpg
311 KB, 1261x1000
>>54555253
These. I don't want to be a noob anymore, but as I am quickly discovering, I still very much am.
>>
>>54556965
Not being good at recursion is a serious disadvantage. You should do all the exercises in chapter 1 of SICP and you'll become pretty good at recursion.
>>
>>54556965
It's important to make sure that if you learn recursion, you try to make it TCO because one of the reasons it's not used as much is due to its effect on the stack
>>
>>54556976
lets try it
>>
Is
call/cc
essentially just GOTO?
>>
>>54556965
Yes. You absolutely have to be good at it.

Learn Scheme first. The nested parentheses help you understand everything returning a value back into a single evaluation. There's a page in SICP that illustrates in very visually.
>>
>>54557051
If I'm right about what call is, does it not add an address to your call stack? Goto just jumps afaik
>>
>>54557051
Kind of, you use it to call a function in Assembly. The address of the next instruction is then pushed onto the stack until ret is used in the called function, at which point the address popped off back into EIP
>>
>>54557066
>>
>>54557102
Tail call
>>
>>54557051
It's like goto on steroids. The continuation you save is a lot more flexible because you can call it anywhere and pass it around.

Check this out
>http://community.schemewiki.org/?amb

>>54557073
Invoking a call/cc continuation jumps. Lots of implementations use longjmp.
>>
File: 1454878286406.jpg (31 KB, 600x600) Image search: [Google]
1454878286406.jpg
31 KB, 600x600
>>54557115
TCO
Making Recursion Great Again
>>
>>54557042
nvm that is going to take hours fuck that
>>
>>54556498
Start with How to design programs Part 1, 2, and 3
https://www.edx.org/course/how-code-systematic-program-design-part-ubcx-spd1x

Because it concentrates on doing tests and learning how to make large programs, which is essential to wherever you'll end up working.

Once you get half way through go through the 'Reading List' here: http://web.mit.edu/6.005/www/sp16/ that's a crash course in pro software development again how to write tests ect. The section they have explaining how git works is awesome.

After you're done that course go get a book on any typical commercial language in use like Clojure or Ruby. Go on stackexchange and start replying to questions about Racket/Ruby/Clojure whatever you're doing. Find open source projects and start testing the code/finding bugs or writing new features and submitting them. I went to Github's public source and started going through the Issues list and answering them faster than the staff and they offered me a remote job when I first started as "Support Engineer" which paid a ridiculous amount of money.

Then you just continue your education while working by reading CLRS, SICP, The Art Of Software Security Assessment (TAOSSA), ect.
>>
>>54557149

Infinite recursion: making infinite recursion great again.
>>
>>54557115
Couldn't they define fact-iter, so that
fact n
returns
fact-iter 1 n
which returns
fact-iter 1*n n-1
etc until the right param is 1? It's TCO as well
>>
>>54557115
How would you implement this strategy in code? This example >>54557102 looks like:
int factorial(int n)
{
if (n == 1)
return 1;
else
return n * factorial(n -1);
}

would work, but I don't see how you would reformat it to be TCO. Or is it already TCO?
>>
>>54556539
wouldn't psychoacoustics be more suited more for sound design rather than sound programming?
>>
>>54557051
call/cc is so cool but I'm not clever enough to think of a good use for it outside of escape continuations. Like there's amb and coroutines but those are already libraries.

Someone should tell me a cool thing to design with call/cc
>>
>>54557269
Like this
int factorial(unsigned int n, unsigned int accumulation) {
if(n == 1 || n == 0)
return accumulation;
else
return factorial(n-1,accumulation*n);
}
>>
>>54557269
>Or is it already TCO?
afaik, it's not, you have to calculate
factorial(n-1)
before
return n*factorial(n-1)
can be resolved
>>
>>54557269
int factorial(int n, int fac)
{
if(n == 1)
{
return fac
}
fac *= n
return factorial(n - 1, fac)
}

Or something like that
>>
>>54557269
Well C isn't TCO optimized. That's handled on the compiler level.

A tail call in Scheme carries the function's current value at any given iteration as well as the value of n.

So it'd look like

(factorial (* n new-value) (- n 1))

for
 (factorial new-value n)


instead of

(* n (factorial (- n 1)))
>>
>>54557331
>That's handled on the compiler level.
You have to compile it anyway. Does the standard say it doesn't have to compile with TCO?
>>
>>54557331
>Well C isn't TCO optimized
It is with O2
>>
>>54557272
Well, like I said, depends on what kind of programming but as long as your anticipate human listeners (which most of what we'd call "sound programming") psychoacoustics is relevant.
>>
R8 this tail call optimized factorial:
(define (fact n k)
(if (= n 0)
(k 1)
(fact (- n 1) (lambda (m) (* n (k m))))))


>>54557331
>compiling without -O2
Although even then gcc doesn't offer the guarantee of TCO. I think only recursive calls are TCO'd.
>>
Is it worth picking up a few certs (A+/Network+/Linux+) while getting my SE degree?
>>
>>54557379
Same question but with a CS degree.
>>
>>54557378
>2 params for a factorial function
Just do the normal thing where it calls a separate iterator
>>
>>54557402
That's not just a factorial function though. It's in continuation passing style. Well except the * isn't but ehh I decided to leave the cps-* out of that snippet.
>>
>>54557418
What do you put in k initially? fact itself? Not sure I understand how it terminates
>>
>>54557463
You put in your continuation. If you just wanna call fact from repl your continuation is nothing, so you put in identity.
(define (identity x) x)


If you wanna do (+ 2 (fact 3)) in CPS what you do is:
(fact 3 (lambda (x) (+ 2 x)))



This seems useless but it is more useful than you'd think. Chicken compiles all its code to CPS because CPS removes the need for a program stack. This allows tail call optimization to occur simply by garbage collecting.
>>
>>54557489
I got almost none of that, but it sounds really interesting
>>
>>54557378
>R8 this tail call optimized factorial:
But we're only up to R7!
>>
>>54555808
Put a break after
isPrime = false;
.
That doesn't let it check for other divisors if it's already found one. Also, why do you have a primes array if you never use it? Even if you would use it, it's a performance bottleneck to create a new array for every prime.
>>
>>54556976
Roll
>>
>>54556976
Too easy, roll
>>
>>54556976
roll
>>
>>54557502
call-with-current-continuation as the name implies also has to do with continuations. I think the first 2 sections of https://docs.racket-lang.org/reference/eval-model.html explain continuations best. Note that it doesn't necessarily have to do with recursive functions.

Continuation-passing is what this guy is doing: passing the continuation to the redex wrapped in an anonymous function.
>>
>>54557502
Continuations are essentially the code that remains to be executed. You can think of them as a function that takes 1 argument, the thing that just was executed.

So take (+ 1 (square 3))

The continuation of (square 3) is
(lambda (x) (+ 1 x)).

Continuation passing style folds code inside out so (+ 1 (square 3)) becomes
(cps-square 3 (lambda (x) (cps-+ 1 x identity)))


Where those functions are defined as follows:

(define (cps-* x y k) (k (* x y)))
(define (cps-+ x y k) (k (+ x y)))
(define (cps-square x k) (k (cps-* x x identity)))


The neat thing about continuation passing style is it's always always tail call optimized.
>>
File: 1460939813312.jpg (56 KB, 520x401) Image search: [Google]
1460939813312.jpg
56 KB, 520x401
>>54557598
>tfw you realize you're dumb
>>
>>54557598
I'll try and dissect this later, thanks
>>
The smuggest way to write an infinite loop:
(define k-saved '())
(begin (call/cc (lambda (k) (set! k-saved k) (k 1))) (k-saved 1))
>>
>>54557489
>Chicken compiles all its code to CPS because CPS removes the need for a program stack.

http://home.pipeline.com/~hbaker1/CheneyMTA.html

That shit's dank! Thanks chickenbro
>>
File: feel guy smiling.gif (13 KB, 633x758) Image search: [Google]
feel guy smiling.gif
13 KB, 633x758
>tfw when Schemers take over the thread

Good feel
>>
Do I need anything more than sdl the create a game? Like can you draw triangles without opengl
>>
which lisp is the best to learn first?
I'm already intermediate in haskell, so I have xp with fp

I heard about racket

I'd prefer a mature language though
something as mature as C such that it has many libs and job offers
>>
>>54558167
yeah SDL will suffice, it's split into a few modules, like sdl_image, sdl_ttf, sdl_mixer and stuff and you can use it to load fonts/images, render them, and such
>>
who /luafag/ here?
>>
>>54558354
>many libs and job offers
Clojure is at the center of a bubble as it seems, and it has all the libs of Java. Plus it has interesting ideas in it.
>>
File: braveclojure.png (104 KB, 900x900) Image search: [Google]
braveclojure.png
104 KB, 900x900
>>54558354
http://www.braveclojure.com/
>>
C programmer here, I've been learning C++.
I've looked into the usual OOP stuff, templates, exceptions, C++ style memory allocation.
Any other useful C++ stuff I should look into?
>>
>>54558949
Vectors.
>>
>>54558958
Already done those.
>>
>>54558949
RAII
>>
>>54558949
>C programmer here, I've been learning C++.
Do you find yourself completely disgusted yet?
>>
>>54559013
No. I actually feel enlightened.
C++ has a lot of useful stuff, to deny that is just being fucking retarded.
There are some things that procedural programming just cannot solve easily, while OOP and templates can easily solve.

Also, the C++ standard library is also really useful, like std::vector for example.

The C++ hate is just a bandwagon, new programmers who want to be special and hip reject C++ for application development and make their lives harder by using only C for everything. But you eventually grow out of that. C++ and OOP is not disgusting if you understand what's happening under the hood.

Don't get me wrong, C is a great language and I love doing low level stuff with it like making virtual machines and simple operating systems. There are some things that only C can do (I'd like to see a bootsector in C++, it could be possible).
But for userspace application development, C++ makes things a lot easier.

I'm not saying you should go full OOP either, only what is necessary.
Encapsulation is a meme.
>>
I need help

Why am I getting error

public class DotComTest{
public static void main(String[] args){
int randomNum = (int)(Math.random()*100) % 4;
int[] arr = new int[3];
arr[0]=randomNum;
arr[1]=(arr[0]+1) % 4;
arr[2]=(arr[1]+1)%4;
for(int i : arr){
System.out.println("\nNum : " + i);
}
SimpleDotCom c = new SimpleDotCom();
c.setLocationCells(arr);
c.print();
}
}
class SimpleDotCom{
int[] location=new int[3];
void setLocationCells(int[3] arr){
try{
int i;
for(i=0;i<3;i++){
location[i] = arr[i];
}
}catch(IndexOutOfBoundsException e){
System.out.println("\nError : " + e.getMessage());
}
}
void print(){
for(int i : location){
System.out.println("\nValue : " + i);
}
}
}

>>
>>54559130
>Encapsulation is a meme.
kill yourself idiot

any decent library/api even in C uses encapsulation
>>
Here is the error
DotComTest.java:18: error: ']' expected
void setLocationCells(int[3] arr){
^
DotComTest.java:18: error: ')' expected
void setLocationCells(int[3] arr){
^
DotComTest.java:18: error: ';' expected
void setLocationCells(int[3] arr){
^
DotComTest.java:18: error: illegal start of type
void setLocationCells(int[3] arr){
^
DotComTest.java:18: error: <identifier> expected
void setLocationCells(int[3] arr){
^
DotComTest.java:18: error: ';' expected
void setLocationCells(int[3] arr){
^
DotComTest.java:24: error: illegal start of type
}catch(IndexOutOfBoundsException e){
^
DotComTest.java:28: error: class, interface, or enum expected
void print(){
^
DotComTest.java:31: error: class, interface, or enum expected
}
^
9 errors
>>
>>54559152
the type is int[], not int[3]
>>
>>54559148
Literally the only reason encapsulation exists is to hide members in the autocomplete window when typing out names in an IDE.
There is absolutely no other use for encapsulation. Completely useless.
>>
>>54559130
OOP is fucking awful, and shouldn't be used in any situation. It doesn't model anything well, and only leads to designs which don't fit the problem and are very inefficient.
Encapulation only works well at a library/module level.

As to why C++ is fucking shit, ALL C++ like to do is hide state and side effects from you, and sprinkle tonnes of stupid shit like << in your code.
>>
>>54559174
kys idiot
>>
>>54559182
nice argument.
>>
>>54559163
still getting errors.If I put the second class in separate file then all works fine.
>>
>>54559181
kill yourself dumbfuck Ctard

stick to your shitty fizzbuzz tier CLI neckbeard apps
>>
>>54559163
This
>>
>>54559197
have them in separate files or put one class as a nested class inside the scope of the other class
>>
>>54559199
You clearly don't know anything about anything.
Have you ever tried thinking critically about anything you've done?
Do you not appreciate elegance or correctness at all?
>>
>>54559163
Thanks. It worked. int[] is parameter.
>>
File: [tilting increases].png (27 KB, 500x500) Image search: [Google]
[tilting increases].png
27 KB, 500x500
>>54559222
stay delusional

C doesn't even have user-defined namespaces lmfao
>>
>>54559230
>user-defined namespaces
That only fucks with the ABI. C doesn't need that shit.
>>
>>54559239
k tard
>>
>>54559244
You clearly don't understand anything about the advantages that C has (and always will have) over C++.
C's ABI is simple and stable. Any feature that fucks with that won't become a part of C.
Why do you think that every library that isn't complete shit only exports a C ABI?
Why do you think that you have to download a different binary for every different compiler when you download a C++ library, and that can break when you upgrade your compiler?
>>
>>54559222
>C
>elegance
>correctness
good one m8
>>
>>54559285
Sure, but that's not a reason to use only C.
>>
Is there ever a reason not to use self in a Python __init__?
class App:

def __init__(s, m):
s.cat = 2
dog = 4


Are there specific situations where one should pass a non-self attribute through a function as opposed to calling it from inside the function?
>>
>>54559222
consider my fedora tipped
>>
>>54559504
Yeah, if you don't need to use self.
>>
I know it's not really encryption, but did i do anything wrong here? I'm just getting into C so there are probably a few things that could be done better.
#include <stdio.h>
#include <stdlib.h>

#define length 1024
int main()
{

char input[length] = {0};
printf("Input text to encrypt:\n");
fgets(input, length, stdin); //Get Input
int i; //Iterator for loop
int c; //Where to store the char as an int
for(i = 0;i < length;i++)
{
if(input[i] != 0) //Encrypt if not zero
{
c = input[i];
printf("%d", c * 1337);
}
}
}
>>
>>54558862
The book is solid intriduction, except the examples.
>>
Family, why is it so hard to write proper documentation?
// A website implements a HTTP server.
type Website struct {
}

^ makes no sense
>>
>>54559647
>printf instead of puts
0/10
>>
>>54559711
You're writing Go, there's much more to worry about that makes no sense.
>>
>>54559723
Le smiley with carat nose.
>>
File: digimon.png (881 KB, 1142x837) Image search: [Google]
digimon.png
881 KB, 1142x837
What did he mean by this?
>>
if i decalre a const char array in a function, will it be null terminated?
>>
>>54559174
>has never read a book on SE.
lel, k tard.
>>
File: do_you_even_vape.webm (1 MB, 640x360) Image search: [Google]
do_you_even_vape.webm
1 MB, 640x360
Ask your much beloved programming literate anything (IAMA).

>>54559721
It's optimized into a call to puts anyway.
>>
>>54559857
>>54559711
>>
>>54559857
how can uni-directional logic architectures be brought to command line applications?
>>
>>54559857
How can I be a hardcore github hipster who contributes to lots of >1k star projects?

I do a lot of my own stuff but never really find anything on github that I both

A: use and want to make better
and
B: someone else isn't already fixing and making better
>>
>>54559934
>printf("Input text to encrypt:\n");
>printing an integer
>>
>>54559934
Fucked up a code tag. Reposting:

>>54559721
He's using it to print an integer though.
puts only does strings.

>>54559647
>int i;
You can include that inside the for loop like
(int i = 0; i < length; i++)


>int c;
You can get away with not having this variable.
printf("%d", input[i] * 1337);

Due to integer promotion (i.e. chars and shorts are converted to ints before any computation), this code will work correctly.

Also, a way you could write your program without the need for buffering would be one character at a time:
printf("Input text to encrypt:\n");
int c;
while ((c = getchar()) != EOF && c != '\n')
if (c != 0)
printf("%d", c * 1337;

However, there is nothing wrong with the way you're currently doing it, I was just posting an alternative. Your way is better if you plan to do something with the string besides print it out immediately.
>>
>>54559951
Just following the example, mate.
I know it's not actually encrypting anything and I think the original poster knows too.
>>
>>54559954
Thanks for the feedback famalam. I'll probably be posting more stuff today.
>>
>>54559949
It also doesn't help that the main language I use at work is C# which isn't usually found in the OSS world so much.
>>
int maxTimers = 5;
Timer timer[maxTimers];


Why does this shit not work in C++? And how can I make it work?
>>
>>54559978
Hardcore github hipsters only fork projects and fix typos.
>>
>>54560003
Because C++ doesn't have variable length arrays. The array length has to be a constant expression.
>>
>>54559949
Even the most well developed projects have issues. That being said, trendy new projects from /r/programming or hacker news tend to have lots of bugs. There's also nothing stopping you from making plugins and scripts for programs you already use. Little to no creativity required there. You can even make bots for chat programs you use. I don't think there's a program on my computer I haven't scripted in some way. It's fun and you get lots of those tasty green squares. Also, make a repo for your dotfiles and colorscheme. I'm on day 101 and I see no chance of stopping this week.
>>
File: istheremoretolife_chew_.jpg (1 MB, 2592x1936) Image search: [Google]
istheremoretolife_chew_.jpg
1 MB, 2592x1936
>>54559869
>>54559711
>Family, why is it so hard to write proper documentation?

Because you haven't learned how to write self-documented code yet.

"Besides a mathematical inclination, an exceptionally good mastery of one's native tongue is the most vital asset of a competent programmer." -- Dijkstra

"Produce no document unless it's need is immediate and significant." -- Uncle Bob

"The best documentation for a computer program is clean structure. " -- Kernighan & Plauger

"Show me your code and conceal your data structures, and I shall continue to be mystified. Show me your data structures, and I won't usually need your code; it'll be obvious."

"Smart data structures and dumb code works a lot better than the other way around." -- ESR

"""
git actually has a simple design, with stable and reasonably well-documented data structures. In fact, I'm a huge proponent of designing your code around the data, rather than the other way around, and I think it's one of the reasons git has been fairly successful […] I will, in fact, claim that the difference between a bad programmer and a good one is whether he considers his code or his data structures more important.
""" -- Torvalds

>>54559949
http://www.codetriage.com/
https://www.codemontage.com/
http://contribhub.org/
https://openhatch.org/
https://www.bountysource.com/
https://bountify.co/

>>54559914
>uni-directional logic
explain
>>
>>54560015
const int seems to work indeed.

Damn, I thought I hated Java. Now without variable length arrays C++ is making me rage. I'm having so much trouble doing some simple OOP.
>>
>>54560003
constexpr unsigned int MaxTimers = 5;
Timer timer[MaxTimers];
>>
>>54559978
If you can read documentation and know basic logic structures, congratulations, you now know how to speak every C-like language made in the last 30 years.
>>
>>54560032
>uni-directional
http://redux.js.org/docs/basics/DataFlow.html
>>
I think I just realized the biggest drawback of using full-blown IDEs instead of modular text editors.
The fear of trying new languages.
>>
rate my nigger rigged strdup implementation
char *_str_dup(const char *base)
{
if (!base) return 0;
int len = 0;
int i = 0;
while(*(base+(i++))) len++;
char *str = malloc(len+1);
if (!str) return 0;
for(i=0; i<len; i++) *(str+i) = *(base+i);
*(str+len) = '\0';
return str;
}
>>
>>54560103
Why not just
char *strdup(const char *base)
{
int len = strlen(base);
char *dup = malloc(len);
memcpy(base, dup, len);
return dup;
}
>>
>>54560051
Well yeah I know that, I just mean if I was going to do anything complex I'd have an easier time of writing it in C# at the moment.

For example I'm not up to date on ES6 promises and can't be fucked putting the time in just yet.
>>
>>54560103
>Reimplementing strlen
>Reimplementing strcpy
>Not just assuming that the argument is non-null
>>
>>54560135
You have to put the time in, there is no other way to be good at anything.
>>
>>54560040
you use vector in that case m8
>>
>>54560156
You are completely missing the point of anything I'm saying here buddy, but okay.
>>
File: 94fMJPU.jpg (105 KB, 734x960) Image search: [Google]
94fMJPU.jpg
105 KB, 734x960
>>54560068
I don't see the big deal, it looks like the producer/consumer concept except that some webdevs put a buzzword on it. CLI applications are already using that through streams: something like
 cat foo.txt | grep ... | sort ...
is an unidirectional data flow (cat -> grep -> sort)
>>
>>54560164
vector is not in Arduino unfortunately. And malloc and the bunch are highly discouraged.

I'll just limit the timers to a fixed value.
>>
who here uses Go in production, and what do you use it for? curious...
>>
>>54560206
wtf?
http://stackoverflow.com/questions/16224746/how-to-use-c11-to-program-the-arduino

don't see how java will help since it would be on the heap over there as well
>>
>>54560173
What am I missing? All I'm hearing is that you want to make lots of contributions without any effort or putting the time in. inb4 more excuses
>>
>>54559785
Depends how you initialise it, so no since it's not automatical.
>>
>>54560190
Side effects most definitely aren't a consumer/producer concept, nor is piping devoid of side effects.
>>
>>54560231
Can't do that as the program will be used by newcomers. They won't be able/have the time to make those changes to the IDE.
>>
File: 1408674927746.jpg (65 KB, 640x640) Image search: [Google]
1408674927746.jpg
65 KB, 640x640
>>54557239
I also bang my head on the wall repeatedly.
>>
>>54560103
base[i++]
please sugar up your syntax. Fun fact: you can also write i[str] if the mood takes you.
>>
>>54560253
I'm absolutely fine with putting the effort in, however I have to use C# for my dayjob anyway, so if possible it would be nice to use that, but I'm really not fussed, it would just be easier than learning random specialism X.

The problem I actually have is finding the right projects to contribute to.
>>
>>54560306
why exactly do you want to contribute to OSS projects on GitHub?

is it for career advancement? to make the world a better place? to see what it's like to work on a big distributed team of volunteers?

at some point you will have to get good enough at something besides C# to make useful contributions, and it will take a lot of time.

if you're using ES6 promises as an example of something that you don't have time to learn, it doesn't really suggest that this is going to work out very well. you should be able to learn about those in a weekend at the most.
>>
>>54560306
>The problem I actually have is finding the right projects to contribute to.
I wonder why that is.
>>
>>54560341
Largely the second two, and, ironically, to learn new things.

I think I've conveyed most of what I've said incorrectly, and probably come off as a retard who wants to very easily become github famous, which isn't it at all.

The es6 promises are probably a bad example, but essentially what I mean by this is that I'm under no illusions that I'll be able to pick up an expert understanding of say, goroutines or the BEAM vm, in a short period of time and do a better job at working on projects involving them than people that already do those aspects for their day job.

And I really do want to put the time in to learn these things, but I don't want to be a burden to those who are already putting forth their free time to improve OSS projects.
>>
I don't get that thing supporters of functional programming say about the 'state' failing. What is the problem with state failure, it just makes it harder to debug/maintain code?
>>
how to average 2 ints in c?
>>
>Write C
>/dpt/ shits on you for using C and not C++
>Write C++
>/dpt/ shits on you for using C++ and not C
>>
>>54560671
Just use Rust :^)
>>
>>54560671
Now we're gonna shit on you for caring what we think
>>
>>54560671
Just use Ruby :^)
>>
>>54560732
>>54560743
Memes.
>>
>>54560671
Using C++. What a joke.
>>
>>54560637
package main

import "fmt'
import "math"

func main() {
fmt.Println(int(math.Max(float64(5), float64(6))))
}
>>
>>54560637
package main

import "fmt"
import "math"

func main() {
fmt.Println(int(math.Max(float64(*&*new(int)), float64(6))))
}
>>
>>54560671

You are now realizing that /dpt/ is more than one person.
>>
>>54560985
Bullshit.
>>
File: cl.jpg (12 KB, 195x245) Image search: [Google]
cl.jpg
12 KB, 195x245
Going slowly still through the beginning with pen and paper. It's really good.
>>
File: redbjarne.png (7 KB, 59x59) Image search: [Google]
redbjarne.png
7 KB, 59x59
>>54560773
>>
>>54560773
>>54560671
Given the choice between the two, why would anyone choose C over C++?
>>
>>54561126
It's easier for a novice and taught in most shitty colleges as an intro to programming course. I'm learning lisp though.
>>
>>54561126
C is a clean, simple, and well-designed language, that has a focus.
C++ is a clusterfuck of random features, and tonnes of duplicated functionality.
>>
What are some fun projects I could do over the summer to keep me fresh and ready for sophomore year of CS?

I was thinking of doing a Rubiks cube solver in C++ using a 3D array as the cube for shits and giggles.
>>
>>54561126
Because C is correctly designed compared to C++.
>>
#include <stdio.h>
#include <stdlib.h>

#include <limits.h>

typedef unsigned int DIGIT;

typedef struct num NUM;

struct num {
DIGIT digit;
NUM *next;
};

DIGIT adddigit (DIGIT a, DIGIT b, DIGIT *c) {
DIGIT r;
DIGIT nc;
r = a + b + *c;
nc = r < a || r == a && *c != 0 ? 1 : 0;
/* fprintf (stderr, "# %u %u %u -> %u %u\r\n", a, b, *c, nc, r); */
*c = nc;
return r;
}

void freenum (NUM *n) {
if (n != NULL) {
freenum (n->next);
free (n);
}
}

NUM *pushdigit (NUM *n, DIGIT d) {
NUM *nn;
nn = malloc (sizeof (NUM));
nn->digit = d;
nn->next = n;
return nn;
}

NUM *addnum (NUM *a, NUM *b, DIGIT c) {
DIGIT da;
DIGIT db;
NUM *r;
if (a == NULL && b == NULL && c == 0) {
r = NULL;
} else {
r = malloc (sizeof (NUM));
da = a == NULL ? 0 : a->digit;
db = b == NULL ? 0 : b->digit;
r->digit = adddigit (da, db, &c);
a = a == NULL ? NULL : a->next;
b = b == NULL ? NULL : b->next;
r->next = addnum (a, b, c);
}
return r;
}

void fprintnum (FILE *fd, NUM *n) {
if (n != NULL) {
fprintnum (fd, n->next);
fprintf (fd, "%u ", n->digit);
}
}

void printnum (NUM *n) {
fprintnum (stdout, n);
}

int main (void) {
int i;
NUM *p;
fprintf (stderr, "# UINT_MAX %u\r\n", UINT_MAX);
p = malloc (sizeof (NUM));
p->digit = 1;
p->next = NULL;
for (i = 0; i < 100; i++) {
NUM *tp;
printnum (p);
printf ("\r\n");
tp = addnum (p, p, 1);
p = addnum (tp, p, 0);
}
free (p);
return 0;
}
>>
>>54561272
>C
>clean, simple, well designed

This is historical revisionism to the highest degree. Not even Ritchie talked about it like this.
>>
>>54561403
At least you have a trip that helps me to recognize and ignore you.
>>
>>54561418

I'm just here to make sure people realize they're talking a complete load of bollocks when they say C is "well-designed".

The only reason C exists is because Ritchie & Thompson needed something to write Unix in.
>>
>>54561379
Have some substance behind that assertion? Give me examples. I only know relatively high level languages and was about to start teaching myself C++ with Bjorne's Programming: Principles and Practice, but I'd like to hear the case for C instead.
>>
>>54561126
The choice is neither, nothing in <current year> should be written in either C/C++ which is why we have Go (C) and Rust (C++).
>>
>>54561458
When you call a function in C++ there is a MANDATORY call to copy constructor. Which prevents inlining. There are MANDATORY call to copy constructors everywhere. Why do you think they invented move semantics? C has introduced no feature that change its semantics (except those stupid and useless things which are likes by non C89 believers). Because C was properly designed.

>>54561456
STFU OSGTP, you suck at coding and understanding things. I know that you sucked at math during school.
>>
>>54561375
rewrite the linux kernel in haskell
>>
>>54561470
Why do people keep comparing Go to C? It's not even remotely similar.
>>
>>54561500
That's too hard
>>
>>54561375
stockfighter.io
>>
Fucking Google, why is their crap always trying to connect to Google Analytics in the background, even when I'm not using the damn phone?
I'm glad there's still /etc/hosts to block that, at least they're not Microsoft-tier evil.

W/GAv4-SVC(10569): Network compressed POST connection error: java.net.ConnectException: failed to connect to ssl.google-analytics.com/127.0.0.1 (port 443) after 60000ms: isConnected failed: ECONNREFUSED (Connection refused)
u0_a75 10569 3989 1228720 83228 ffffffff b6e78e18 S com.google.android.gms
>>
>>54561502
this, rust replaces both C/C++, Go replaces Java.
>>
>>54561518
Stockfigher, the guys who've been promising us they'll release Jailbreak "next saturday" for the past several months. Awesome.
>>
>>54561528
Google is microsoft-tier evil, they just hide it better. They basically have browsing history for every naive computer user through their analytics, imagine the shit they do with that.
>>
>>54561498
>I know that you sucked at math during school.

I've done just fine with everything, LinAlg, Calc I & II & III.

Never really been a problem.
>>
>>54561565
>I've done just fine with everything, LinAlg, Calc I & II & III.
Everybody can do that. Did you integrate a prestigious school, like Harvard or something like that? No, because you suck.
>>
>>54561557
Yeah but at least they're upfront about it and they let you disable it if you care.

Microsoft?
They write a kernel driver that bypasses /etc/hosts so you can't block their shit,
They don't allow you to really disable "Telemetry",
And if you try, they'll just re-enable it behind your back.
And no, you don't have a choice to just stay on Windows 7, you HAVE to upgrade wether you like it or not.

Google is no saint, but FUCK microsoft.
>>
>>54561502
Because the designers of the language Rob Pike and Ken Thompson set out to completely replace C and told everybody this in the design specs.

It's similar to C in syntax and portability but that's about it, but the goal was a memory safe language that could replace networking stacks.

>>54561537
Java replaced C++ as it's OOP/typesafe.
Don't believe me read the 6.005 MIT lecture notes
>>
>>54561593
You still can use an internet box under linux to filter packets.
>>
>>54561616
Oh great! I have to use ANOTHER FUCKING SYSTEM for filtering because I can't even control MY OWN GODDAMN COMPUTER???

Not evil at all. No siree.
What the HELL is wrong with them.
Thread replies: 255
Thread images: 26

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.