/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

pastebin.com/60YiEjxi
pastebin.com/Wzhpb5M9.
tour.golang.org
tutorialspoint.com/java/java_methods.htm
twitter.com/NSFWRedditVideo

First for Haskell

Thank you for posting an anime image.

>fixed bug that's been throwing me off for weeks
>didn't even think twice about the solution
>the bug fix was adding a three star array of pointers to pointers to char arrays

I'm a 3 star programmer now!

First for race conditions.

Should I learn Python, Ruby or Javascript? CS major here I know C and Java and some perl.

Neither, learn a functional language

Ruby.

I'd learn JS or Python. Ruby is only good for one thing (RubyOnRails) It's quite literally a one trick pony.

So what are the instructions?

Could hardly be any simpler:
mov al, 42
ret

Disassembly of section .rodata:

0000000000400748 :
400748: 00 00 add %al,(%rax)
...

000000000040074c :
40074c: b0 2a mov $0x2a,%al
40074e: c3 retq

>python
lotta people using this today, but it's only real purpose is to learn programming, quickly prototype things, or write small scripts / apps (e.g. bots)
imo doing anything meaningful in the real world there are better languages out there
>ruby
I use this at work a bit as it is central to one of our tools, but I wouldn't use it outside of that. Like pythong, it can be picked up quickly if you have a decent CS education
>Javascript
shit. I say this having written some things in javascript / nodejs. I dislike it, I dislike the community eclectic-ness of standards. Work is repeated everywhere and you spend more time trying to figure out what library / package / tool / paradigm to use to solve your problem than you do actually writing the code to solve it.

you know C, Go would be easy to pick up
you know java, something like Scala / Clojure would be easy to pickup
Erlang mite b cool

This guy is right, Scala and Clojure are good ideas, just don't get too wedded to either of them.

I'm incredibly bored, and just generally feel like shit right now. Kind of feel like installing debian on my jetson TX1.

I'm trying out pygame for the first time and I'm having some issues. I'm trying to create a list of projectile objects

# Create projectiles , position will be reset later
u_projectile = [Projectile(0, 0) for _ in range(500)]


and then later, in my while loop, accessing those projectiles and setting their position when the space key is hit

# Use arrow keys to move player left & right, space to launch projectiles
key = pygame.key.get_pressed()
if 0

So Javascript then?

retq? what the fuck? is at&t syntax so retarded that it defines return for different bit widths?

No user.

see

So I made a .bat build script for interfacing with cmake on windows. It's really simple and serves just to simplify the process even more. For some reason though, whenever cmake is called from the script, cmake will dump its shit in the root of the project folder, not the designated build directory.

here's the revelant snippet from the script
:build__build_debug_x86
rem build__build_out_dir = build
mkdir %build__build_out_dir%
cd %build__build_out_dir%
cmake -G %build__cmake_gen_name% ..\CMakeLists.txt
cmake --build .. --config Debug
cd ..
goto:eof


pastebin: pastebin.com/60YiEjxi

I find this weird because if I manually execute the same commands in the shell it just werks and everything is dumped in the build directory

just out of curiosity - what languages do you enjoy working with?

This a good book?

Yes.

I read the first edition of that book, the examples predate ANSI C, so you see lots of K&R-esque obtuse programming techniques and it's really distracting.

The writeups are good tho.

I guess I should've stated that I'd like some insight on this as it's either my retardation or windows sucks more dick than I previously thought

The first line under the label is commented out, but you refer to it in the next three commands.

Fuuuug, I'm retarded, but not in the way you think: I set build__build_out_dir at the beginning of the script; thus it's value is indeed set. I made that comment to inform you all what build__build_out_dir equals.

a

Third edition came out in 1998, so I imagine that's not too much of an issue
Think I might try pic related first anyway, since it looks a lot less dense

I'm working in scheme and was wondering if I had a pair, could I map all the left hand values to the corresponding right hand value?

Like for example if I had:
((a . 8) (b . 6))

could I turn this into:
a = 8
b = 6

I tried with define and let but it doesn't like me using car and cdr

const char main[] = "\x55\x48\x89\xe5\xb8\x0b\x00\x00\x00\xc7\x45\xfc\x00\x00\x00\x00\x5d\xc3";

guys I feel like I'm slowly getting the hang out of the pythonic way

import math
def peaceful_yard(yard, min_distance):
print (yard, min_distance)
ind = [(a, b) for a, i in enumerate(yard) for b, x in enumerate(i) if x in 'LRM']
return all(p >= min_distance for p in
[math.sqrt(pow(ind[0][0] - ind[0 + i][0], 2) + pow(ind[0][1] - ind[0 + i][1], 2)) for i in
range(1, len(ind))])

My eyes

I started learning java three days ago.
My tutor gave me a homwork and I'm trying to finish the mini rectangle calculator..

please, please tell you're just shitposting

36th for Go

It works perfectly fine.
I'm totally new to programming so tell me if I did something terribly wrong..

At least you know your place.

thats the point

I spent my first week programming doing stupid shit like calling main() from within main because the teacher though he was doing us a service by not teaching us loops of any kind.

Then I was confused as to why my menu program wouldn't quit every time I selected quit.

Needless to say, i quit that shit after one semester and self-studied from that point forward.
Don't go to college for computers.

Dunno about Scheme, but you can do it in CL with mapcar:
(mapcar (lambda (x)
(cons (cdr x) (cdr x)))
'((a . 8) (b . 6)))

You'll need a macro.

alright Sup Forums, what's should be my next app? I already programmed a calculator and a space shooter gaymen for Android.

suicide methods for android users

just to clarify before making more remarks, are you calculating multiple areas? because I'm confused why you're to multiple widths and lengths

cheese pizza detector

Have you double-checked all your paths, making sure for example that the working directory at that point in the script is what you expect it to be? Because if the wrong value is stored in either build__build_out_dir or in the working directory environment variable, that could have happened somewhere earlier in the script.

No, it's just a simple homework, assuming the user can get the value of the area of one rectangle.

I'm totally a beginner so my tutor wouldn't expect me to write more complicated codes in this first week.

doesn't that just make another pair out of them? I want to create a variable "a" in this case and set it to the number 8

I'm not sure how I'd go about this, psuedocode?

What is the best language to create a Stock Control and Sale program?

The indentation is getting screwed up, so I'm just going to give you a one-liner. Here it is in Scheme:
(map (lambda (x) (cons (cdr x) (cdr x))) '((a . 6) (b . 8)))

There's probably a better solution though.

It looks like it only gets one width and length. Most of the code there is an extremely verbose way of getting just the width from the user.

But to noobanon If you really need this ridiculously verbose code for reading doubles from the command line, you should at least put it in a function so that you can reuse it when you get the length.

Oh, disregard then. I guess you could use let or something.

So, how can I do it? I only started learning code three days ago so I only know few things..Of course I would be expected to make more practical codes later on, but I want to get better.

Here's the full script, if you care to look: pastebin.com/Wzhpb5M9. I've comed through it many times, and I'm still at a loss.

tour.golang.org

Why would I want to learn Go if I know Lisp?

you're right he's retreiving input in a weird manner

what do you know user?

>I've comed through it many times

Sounds like you need a girlfriend.

dunno. does it hurt to learn yet another lang, specially one that is quite easy to learn and has some nice features?

diff xs ys = foo xs ys ++ foo ys xs
where foo = foldr (\y -> filter (/=y))

and yes, since you care about unique and not how many it has

Not really. I'm not trying to be a dick about it, it was an honest question.

tutorialspoint.com/java/java_methods.htm
basically, you write what the function returns, is called, and takes, then you basically copy all the code you have to read the input into the function's body and replace where it currently is with calls to it. think about how you can make the function general-purpose, what would need to change before you could use this function to get any kind of data, and what it would need to take to accomplish that
(I didn't really read through the linked tutorial carefully so it might have some issues, but it's a pretty self-evident concept)

not a lot..just basic stuff like if statement and while loop and continue/break , switch, and scanner object. What did you mean by " put it in a function so that you can reuse" ? How can I do it?

>some nice features
Go has no nice features. Reevaluate your programming choices.

see

>If you import a library or declare a variable, but do not use it, your program will not compile even if everything else is valid.
>Composing functions that return multiple types is a mess.
>Go's error type is simply an interface to a function returning a string.
>Go lacks pattern matching & abstract data types.
>Go lacks immutable variables.
>Go lacks generics.
>Go supports the nil pointer. This is similar to C's void *, an enormous source of bugs.

Oh, thank you

What I meant was, you currently just copy your width code almost verbatim to get the length - at least, I assume so.
What would be better would be to do something like:

private static double GetUserDouble(String label) {
double userInput;
System.out.print(label);
//Do your loop, hasNextDouble, etc. to actually place the value in the userInput variable
return userInput;
}

Then your main function can be much simpler, and do something like:
dblWidth=GetUserDouble("Enter the width(cm) : ");
dblLength=GetUserDouble("Enter the length(cm) : ");


I haven't written in Java for years, so you might need to tweak the syntax a bit, but that should give you the idea.

And this way, if you need to change the way the user input works, you don't have to change it in multiple almost identical copies. It's just in one place. Better for readability, maintainability, and extensibility.
If you find yourself copying and pasting a bunch of boilerplate code, it's often a very good sign that you should be moving that code to a function.

Thank you, user!
My tutor told me to never use other methods or functions that I didn't learn from the lessons with him. He said using few tools to solve a problem would help me to think more computationally. But I think knowing a lot of methods is also important to save time.

your tutor is a retard

>Ruby is only good for one thing
Sinatra
Metasploit
Anything involving creating DSLs...

Rails a shit, but Ruby is nice.

>easy af concurrency + channels
>improved C + features taken from other langs
>gofmt
>no OOP
>[...]

>no nice features
t. elite of /dpt/

Haskell does all of those things better except gofmt, which is pointless.

why should i learn lisp?

There's one thing they're both good at, and that's not being used by anybody!

>Haskell does all of those things better

no bias at all ofc

To make yourself a better programmer.

name 1 popular haskell program
>inb4 popularity != good
also
>compiler requires downloading 1 GB of files
top kek

just keep believing you are an elite programmer m8
in reality, no one gives a shit about you, programming elites, or haskell

Ruby is just her name, she doesn't actually use the language.

>bitter tears of a programlet

Very simple language. Lisp macros can't be beat. Prefix notation.

>>bitter tears of a programlet
>implying I'm a highly specialized technician that prides himself of not even having a social life, aka, a code monkey
I prefer to do useful shit for your clients, laugh at you programmers and make easy money

This, it's amazing how freeing such a simple feature is.

Functional?

>lying on the internet

Okay, that looks good. Thank you so much!

Learn Elixir/Erlang. It just works.

woah I though ruby was a guy (male)?

Yes, as opposed to dysfunctional.

Yes. They all support functional programming.

How do I git gud at lock-free programming Sup Forums?

Read memory-barriers.txt

Then read it again until you understand all the subtleties in it.
See you in a couple years!

>what is infosec

No, she just pretends to be sometimes.

Something you don't work in.

I've written at least a little bit of everything I mentioned sans erlang and clojure

right now I like golang a lot and in the past I was pretty enamored with scala
I still work with ruby, python (work), nodejs javascript (personal web stuff)

mostly I when I want to do a project, work or personal, I try to figure out what language will be best to accomplish the task and then learn / use that

where are da proofs?

Any good books on learning C and assembly? I'm studying to hopefully become a pen-tester one day. Thinking maybe a focus in RE and binary exploitation and that kinda thing. Obviously being able to read and interpet assembly is important for disassembling binaries but C also seems to pop up a lot.