/dpt/ - Daily Programming Thread

Old thread: What are you working on Sup Forums?

Other urls found in this thread:

pastebin.com/yi6hU1gz
community.schemewiki.org/?amb
edx.org/course/how-code-systematic-program-design-part-ubcx-spd1x
web.mit.edu/6.005/www/sp16/
twitter.com/SFWRedditVideos

cara

Either going to write a brainfuck -> C transpiler or an assembler + emulator for some architecture
still deciding

>What are you working on Sup Forums?
It's a Sunday, I ain't working on anything.

Just write a befunge to C transpiler.

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

t. Raj Muturi

I'm not that good/determined

Learning muh algorithms

Algorithms are fun

Why not a bf to assembler? It should be easy as fuck.

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

You finished it in 25 minutes?

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!

Noice. Care to pastebin it?

I made a gist but apparently those links are too spammy for moot

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

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.

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

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

(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

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

int main(void)
{
static const char *lut[UCHAR_MAX] = {
['>'] = "++ptr;",
['

What a shitty way to implement a dictionary. I like it.

>dictionary
Pybabby, please go. It's a lookup table.

I don't even use Python. I'm pretty sure the term "dictionary" isn't from Python either

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?

you have to initialize the pointer to null
struct s {
struct r *p;
int a;
};

//...
struct s thing = {NULL, 5};

Serious question: what makes this code shitty? What could be done to make this better?

Why doesn't the compiler initialise it to None by default>

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

>None
Kill yourself.

>shitty
Nigga that works perfectly and gets the job done. O(1) lookup time.

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

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.

None, null, nil, same thing. If you were a function in C, you would be fgets, because it sounds like faggot.

Which is why you use some sort of hash
Not that it really matters here

A hash would still be O(1) :)

bad

A proper hashtable would be just as wasteful as this lookup table, if not moreso.

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?

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

it has already been said that in this case it is fine
calm

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.

Yes, the switch is fine.
I just like my way better because it has less duplicated code.

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?

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)

>Is this C99?
Yes.

#define offset '+'
#define max ']'

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

For "case", "break", and "fputs" I suppose, lol
I do like your implementation though

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.

winrar
rename 'offset' to 'o' so there's less duplicated code xd

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

sexy, though I'm not convinced that a switch wouldn't be faster.

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.

wrong thread

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

.file "lut.c"
.def __main; .scl 2; .type 32; .endef
.section .rdata,"dr"
.align 8
.LC0:
.ascii "#include \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.

Are you going to program nude together :3

Hah, not likely.

Are you over 25 or do you guys not love each other anymore anyway?

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?

sounds neat
can't wait to hear how it goes

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.

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

Yes?
Your statement is factually correct and so is mine.

It contributes absolutely nothing, friendo

#include
#include

int main(void)
{

puts("#include \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 '

Neither does your question, memeboy.

Ill give it a shot when the time comes just to see the look on her face.

Over 25!

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?

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

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.

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.

>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)

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

>static const char *lut[UCHAR_MAX] = {
> ['>'] = "++ptr;",
wait, what the fuck is this?

C99 designated initialisers.

thanks for the info

Best way to program in python on windows?

PYCharm
IDLE
Linux VM

Thank you.

Pycharm if you really have to stay on windows

but preferrably dual-boot for OS X or Linux for their dev environment

Notepad++ works just fine for me desu

Thank you.

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

These. I don't want to be a noob anymore, but as I am quickly discovering, I still very much am.

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.

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

lets try it

Is call/cc essentially just GOTO?

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.

If I'm right about what call is, does it not add an address to your call stack? Goto just jumps afaik

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

...

Tail call

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
>community.schemewiki.org/?amb

Invoking a call/cc continuation jumps. Lots of implementations use longjmp.

TCO
Making Recursion Great Again

nvm that is going to take hours fuck that

Start with How to design programs Part 1, 2, and 3
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: 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.