/dpt/ - Daily Programming Thread

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

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

/!\ ** Read this before asking questions ** /!\

mattgemmell.com/what-have-you-tried/
catb.org/~esr/faqs/smart-questions.html


What are you working on ?

Other urls found in this thread:

mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169?l=Lvld4EQIC_2706218949
en.wikipedia.org/wiki/Include_directive#C.2FC.2B.2B
blog.eventsourcing.com/your-functional-programs-are-imperative-pumpkins-d722ec1358b7#.m374znqtw
twitter.com/NSFWRedditImage

How do I start programming?

I'm a beginner and poorfag.

>www.youtube.com
>Bucky [your language here (Java, C, C++, C#, Python, or anything else)]
>Take it from there

So two questions.


When do i want to declare my variables before my main function

And i sort of get .h header files but whats the actual point of having them?

I'm learning elisp.
What do you want to program?

dont. pick up a drug addiction or something this shit is maddening

Bucky's horrendous though. He programs terribly, uses contrived and pointless examples and promotes bad practices.

>When do i want to declare my variables before my main function
What do you mean? Declare them anywhere before usage. It's a good idea to have a single block at the start of file with all globals. Also, globals should be avoided when possible.
>And i sort of get .h header files but whats the actual point of having them?
Header files store declarations of functions, structures (classes in C++) and constants.

From a Microsoft Windows perspective:
Get Visual Studio 2015 Community Edition (which can pretty much support anything if you can find the plugin).

It is free but you do have to login. I know, it's retarded. On the otherhand, you could also use SharpDevelop (which supports C#, VB.NET, C++, Ruby, Python and some others).

In terms of education: apply for financial aid and go to a local community college that has some amount of CS. Shit is cheap and hasn't costed me anything except money for transport but I could easily just take the bus for a dollar to and from class.

Adding to my post...
Learning online is a fucking pain in the ass. In my personal opinion, learning how to program in a school-like setting is preferable because you can get help from people who are there in person.

Is it bad form to use structs all the time in C++? I'm mostly just using it as C with closures so making fields private by default just trips me up more than it helps when it comes to encapsulating things.

If you're thinking of choosing C# as your first programming language, this is the best place to start:
mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169?l=Lvld4EQIC_2706218949

That's probably confusing for other people. In C++ typically structures are used for simple aggregate data containers without any methods.
Have you considered D?

But why declare them way before hand

(as say void variable and later call it as int variable)

Also why not put the header in the cpp? It reduces the amount of calls each file has to make at the beginning?

Is there any practical purpose to anagram and palindrome problems?

No.

>But why declare them way before hand
>(as say void variable and later call it as int variable)
I'm not sure what do you mean, can you give an example?
>Also why not put the header in the cpp? It reduces the amount of calls each file has to make at the beginning?
Huh? Maybe have a read about includes: en.wikipedia.org/wiki/Include_directive#C.2FC.2B.2B

>Also why not put the header in the cpp?
because multiple files may need to know the prototypes

Working on my terminal emulator, thinking about what to work on next now that rendering and control code handling seems to be complete as far as every program I use goes.

Either gonna work on the vi-like interface for pasting/selecting/URLs or rendering font ligatures.

Picture related, some testing stuff.

Outside of int main something like

#include iostream
Using namespace std

Void a

Int main (){}

Or something along those lines, it was in one of the bucky c++ tutorials (which i actually think are a bit average and slow but ill stick with them till the end because of how far i am)

palindrome = (==) reverse

tabs support would be nice
also being able to configure clickable links with a modifier key so say urls can only be clicked and opened if ctrl key is down
and configurable mouse hover highlitg for links

Looks good, user. Is this in rust? Do you have your code anywhere?

>tabs support would be nice
Not going to happen, it's useless, use a terminal multiplexer.

>also being able to configure clickable links with a modifier key so say urls can only be clicked and opened if ctrl key is down
Not going to happen, URL opening will be handled like in vimperator.

>and configurable mouse hover highlitg for links
Not going to happen.

Yes, it's written in Rust, and it's on GitHub, just search for "github rust cancer".

>Not going to happen

well it's nothing then

There are a billion terminals with support for tabs, go use them.

I'm making this one because I want it to behave in a certain way, not to appeal to every user.

why would i care about your blog then
let me unsub

Are you new to /dpt/ or something user?

>Void a
What?

If you want to learn C++, go read a book like the C++ programming language by Bjarne.

I have experience with basic syntax of methods and return statements, but this one kind of baffles me since I don't really know too much C#. What exactly is happening in the return statement? Do you need any more info to explain it?

private static char[] createCharArray(int length, char defaultChar)
{
return (from c in new char[length] select defaultChar).ToArray();
}

It's LINQ.

in c++ should you separate the default and parameterized constructors?

Thanks man, I'll read up on this!

Not the other gut but are you talking about defining a function before main like

Void a();

Int main(){

Does a terminal emulator do background/foreground tasks? Or is that already handled?

That's the job of the shell, a terminal emulator only handles control codes and renders things appropriately, and handles keyboard input and encodes it into control codes the programs running can understand.

Once i met a guy that said his sister abused him so much and forced him to take estrogen and become a trap. he then got surgery and got a D cup now.

He tried to ERP with me but i told him to fuck off.

Just to be clear, am I understanding this correctly? (converted to java)

private static char[] createCharArray(int length, char defaultChar)
{
char[] charArray = new char[length];
for (char c : charArray) {
c = defaultChar;
}
return charArray;
//return (from c in new char[length] select defaultChar).ToArray();
}

Yep, that's right

Yes.

ERP is essentialy "things I wish that happened".

Thanks bruh

No need to sudoku user. I really respect people who admit their mistakes.

In Android Studio, how do I use the design view for content_main.xml?

It's only letting me drag and drop views in activity_main.xml.

Forgot to add, can't drag and drop views in a TableLayout.

### Sup Forums board & thread image stripper ###


from urllib.parse import urlparse
import urllib.request
import json
import os


board = ""

#target directory for pictures
target_folder = ""
os.chdir(target_folder)

# breaks Sup Forums url into parts #
def create_target_link(url):
link_component = urlparse(url)
# checks for valid Sup Forums link #
if link_component.netloc != "boards.Sup Forums.org":
print("Not a valid link!")
return None

# split path into list: [blank, board_name, thread, thread_id] #
list_params = link_component.path.split("/")
url = "i.4cdn.org/%s/%s%s" % (board, picture_id, extension)
image_urls.append(url)
return(image_urls)

def download_image(link_dict):
for image in link_dict:
urllib.request.urlretrieve(image, (target_folder + "/" + image[20:]))
print("downloading %s" % image)

def image_downloader(target):
step_1 = create_target_link(target)
step_2 = retrieve_json(step_1)
step_3 = find_image_id(step_2)
step_4 = create_image_link(board, step_3)
step_5 = download_image(step_4)

print("please enter your Sup Forums link:")
input_string = input()
image_downloader(input_string)

my first mini project attempt, feedback/abuse is always welcome

Why ask for input when you can just pass it as argument when calling the script?

The header IS put into the cpp by the preprocessor, the include directive is a shorthand for doing that so you don't have to copypaste the header to all the cpps you're using it in.

>board = ""
Board doesn't have to be a global.
>return None
You can do just return.
>return(data)
What? Why not "return data"?
>step_1 = create_target_link(target)
>step_2 = retrieve_json(step_1)
>...
That's hard to read.
>input_string = input()
How about use sys.argv instead?

Problem solving skills on a simple application that can be applied to less straightforward ones

Alright guys, be COMPLETELY honest, no meming
If I'm primarily programming in higher level languages (C# for example), would I benefit from learning a text editor like VIM or EMACS?
Can they display the same functionality?

If so, which should I learn?

I'm all for problem-solving skills training, but these seem just like problems from puzzle-fetishists.

>Can they display the same functionality?
Same as what?
>If so, which should I learn?
Emacs.

Thanks, never used argv before but i'll get down to it

Well, anagrams have been used in cryptography to encrypt messages, and I'm sure there are other uses out there.

They're very straightforward problems, there aren't many practical application problems that are straightforward that aren't super easy, but giving you an assignment like "make a file sorting system" to someone on the second day of class isn't really reasonable.

The same functionality of IDEs.

Relative newbie here, learning by making a game in python.
Is there any reason I shouldn't make an object for fucking everything it'd be even remotely coherent with? They're really useful.

That changes my view on it, the h is there to access from wherever, and is seperate from a spefic cpp so that it can be called without calling the function, and that cpp is seperate so that the function can easily be called and control c control vd right?

>not using an IDE for every language

This is what I am doing
I was wondering if VIM and EMACS were memes or if they actually could increase productivity

>wasting time on learning ancient, deprecated editors only hipsters use unironically

The only reason you might need to learn cmd editors is when you're editing something directly on a server. Nano is objectively the best option for that because it's easy.

is there a way I can get scroll to top without infinite scrolling on this tumblr theme?
Or just a second corner image? Because whenever I try to add any code that should get the second image on my tumblr theme it just shows the broken image symbol and I can't seem to get around that
I'm new to coding so I may not know a lot about it but I've tried all of the codes that I've googled about this and I still get the same problem

pastebin.com/AZwGT3WV

blog.eventsourcing.com/your-functional-programs-are-imperative-pumpkins-d722ec1358b7#.m374znqtw

haskell fags btfo

Forget to read any more than the title?

yes

you don't have to learn VIM/EMACS, you can try Atom which is a normal text editor that supports plugins.

I haven't done C# so I don't know how much it relies on IDE (probably 100% needs VS on windows), but languages Python/C/C++/JS definitely do not need the benefits of an IDE. Java is a maybe, the language seems to have been designed to prefer IDE, especially if you are working with others.

Why does Sup Forums try to move away from IDEs and go for text editors instead?

Like seriously, what is/are the reason(s)?

Simplicity and productivity.

IDEs are bloated, slow and most of the time very specific.

As soon as you start using more than one programming language using IDEs becomes impossible because you'll have to use more than one of them depending on the languages you have to work with.

With a well designed text editor you get the good stuff you get from IDEs (completion, navigation, go to reference, etc.) without the bloat and without the need to learn a billion different IDEs and different ways to build things with them.

Sup Forums loves shit languages with no IDES

>people who still don't understand that purity just means refining your effects rather than letting any effect happen at any time

### Sup Forums thread image stripper ###


from urllib.parse import urlparse
import urllib.request
import json
import os
import sys


def process_link(url):
link_component = urlparse(url)
# checks for valid Sup Forums link #
if link_component.netloc != "boards.Sup Forums.org":
print("Not a valid link!")
return

# split path into list: [blank, board_name, thread, thread_id] #
list_params = link_component.path.split("/")
url = "i.4cdn.org/%s/%s%s" % (board, picture_id, extension)
image_urls.append(url)
return(image_urls)

def download_image(link_dict):
for image in link_dict:
urllib.request.urlretrieve(image, (target_folder + "/" + image[20:]))
print("downloading %s" % image)

def image_downloader(target):
target_link = process_link(target)[0]
json_data = retrieve_json(target_link)
dict_img_ids = find_image_id(json_data)
list_img_urls = create_image_link(process_link(target)[1], dict_img_ids)
download_image(list_img_urls)

def main()
user_input = sys.argv[1]
print(user_input)

target_folder = sys.argv[2]
print(target_folder)
os.chdir(target_folder)

image_downloader(user_input)

main()

I need to store RSA public and private keys in arrays in C++. Is an RSA public key and private key the same length, and if they aren't, are there any upper bounds to the public key size given the private key is 4096-bit?

whoops its broken

Well, shit. An actual answer that puts me in my place. Well done and thanks, maybe I'll consider it now.

imperative programming is subsumed by declarative programming
you can declare that one thing happens after the other quite naturally

using imperative keystrokes ;)

I'm pulling my hair here. I need to write a function in python that takes in 2 parameters (width, height) and outputs an asterisk block. so drawBlock(4,2) would draw a 4 by 2 block of asterisks. I tried using a for loop but nothing works. My code is here. Please explain it to me in a way that I can actually learn and do it myself, I don't just want you guys do do it all for me.

def drawBlockOfStars(width, height):

for i in range(height):
print("*" * width)

>you can declare that one thing happens after the other quite naturally
Also known as imperative programming.

yes
but much like a square is a rectangle, not all rectangles are squares

>nothing works
could you give a little more detail?

When they apply in a sort of differentiable manner. So, for instance, when you have a set of variables that will constantly be changing. If your functions never use constant information and rely on a steady header of variables from which to retrieve information then you want to have them available as close to the point of retrieval as possible to keep the machine running well. There are reasons for using variables between functions, probably not to do with performance and a more aesthetic quality of performance like noise induction, but none of them really come to mind. Besides that last one, of course.

You want to keep a 3 dimensional mindset open for these kinds of things so that you understand your data table focus has changed and that your old data table is no longer available, kind of thing. So instead of seeing some physical thing manifest in front of you, expect that a different 2d map is being used, and so it's almost like you're iterating through a 3d object, desu yo?

by nothing works I mean I tried to sent the parameters to the loop so that it can draw and print the block. so typing drawBlockOfStars(4,2) in the shell would put 4 and 2 in my loop and print the asterisk block. I feel like a retard because I can't seem to find what I'm missing.

Btw, the answer I gave in 413 is the same for both your problems, except sort of interpolated. So, rather than doing that whole thing with variables, you go 4d and do it with programs, after you've done it for variables, where programs are collections of functions.

the code looks fine and i can call it just fine on my machine. do you get an error?

Also, learn to avoid people that talk like this. They are worse than any kind of addiction.

Keep in mind IDEs aren't inherently bad, if you're lucky (or unlucky depending on your point of view) enough to be able to work within a bubble, then an IDE can make things easier.

By bubble I mean developing in a single language (or languages that works together well) and a single platform (Windows only, macOS only).

For example if all you do is build programs for iOS and macOS all you need is XCode, then you just use Swift or Obj-C.

If you only build programs for Windows go with Visual Studio and C# or whatever.

But as soon as you leave the bubble, you either move away from IDEs or you find yourself in trouble.

tee hee that's cute

I don't know what language that is but even haskell doesn't let you add more of something by multiplying it. You have to add it by a number that is factored into the equation.

What language is that anyway? I'll take a look at the specification.

How do I implement a quarternion FPS style camera in OpenGL?

I'm using GLFW3 and GLM, which has built in quaternions

I don't really understand quarternions. I get how 2d imaginary vector multiplication works, but I don't understand how it's supposed to happen in 3d.

That's because Haskell doesn't pretend that addition and concatenation are similar.

They both use lines, though! Hooray.

You've got to be kidding me. I've been stuck for an hour and now it magically started to work. I don't even know what I did to make it work, I am a bit retarded. Thanks for trying to help tho.

python, babbys first language

is OOP and working with APIs, aka code monkeys, declarative programming??

well it is, by that logic, but there's no reason to call it anything but imperative programming

why

But then what is pointer arithmetic if concatenation is strictly for strings? Wait, what am I saying! You've got me confused now!

Make a new curve after momentum is applied. But do not assume a constant trajectory, just add it to the blit.

I sort of get what you mean but its an interesting way of explaining it

why would a camera have momentum