/dpt/ - Daily Programming Thread

Previous thread: What are you working on, Sup Forums?

Other urls found in this thread:

ncbi.nlm.nih.gov/pmc/articles/PMC4368388/
en.wikipedia.org/wiki/Greater_fool_theory
stackoverflow.com/a/13503614
twitter.com/SFWRedditVideos

cats suck

Second for Jeff Dean

you too

How come every article that uses pictures of code in the header uses minified jQuery?

your mom sucks for $5

It's pretty much just a const std::string&, except that for some reason they decided to turn that concept into its own class.

drinking kills programming, it's true
makes me regret becoming a programmer desu, I like it a lot

Bitch I suck for free

You need stimulants instead.

It kills more than just programming, it kills your brain and your personality in many ways.

Well it also works for char * which means you don't have to convert to std::string type.

still no one's interested

It's not funny because you don't get it.
You actually think I'm criticizing dynamic typing.

Did I say I *offer* to suck for free?
No.
I said I *do* suck for free.
It's not a proposition, it's a claim

eh
I miss the feeling of getting completely shitfaced with your buds and passing out on someone's lawn naked

I see absolutely no reason why you couldn't program while doing that.

Do you need to love programming to get a job in it? At a crossroad in my life and I want to make a livable wage.

no

Your IQ, if it was above average, permanently drops 1-2 points every time.

I highly doubt that, I would be a potato right now.

I'm sure more than half of the codemonkeys hate it.

>if it was above average

ncbi.nlm.nih.gov/pmc/articles/PMC4368388/

What about startup brocultures where people drink whiskey every week thou

I'm truing to get two radio buttons display in column. I tried to write both GridLayout(0,1) and GridLayout(1,0) and they still show on one row. What gives?

public class MenuPanel extends javax.swing.JPanel {
public MenuPanel(){
super();

javax.swing.ButtonGroup group = new javax.swing.ButtonGroup();

MenuOptions burger = new MenuOptions("Burger");
MenuOptions fries = new MenuOptions("Fries");
javax.swing.JPanel menuColumn = new javax.swing.JPanel(new java.awt.GridLayout(0,1));
this.add(menuColumn.add(burger));
this.add(menuColumn.add(fries));
}
}

I'm not sure what broculture is but drink up man.

>I would be a potato right now.
As compared to being a brilliant world transforming PhD that you were destined to be, maybe you are a potato right now.

No, I'm pretty sure I would doing the same thing. I would just be complaining on /dpt/ about alcohol instead of drinking.

I think I like my choice better.

try new GridLayout(0, 2)

Wait, I misread that. try GridLayout(2, 0).

>looking over lecture slides on sorting algorithms
>its just tons of uncommented code
>merge sort is particularly bad
>university refuses to video lectures to inflate attendance
>youtube videos are better material than the resources of a 9k a year learning institute

Higher education was a mistake

You suck

Are you kidding user? Alcohol and whores are pretty much mandatory for php webdevs such as myself. The stress would've killed me by now if not for those two

>In our over all analysis, abstainers did not differ from light consumers of alcohol in IQ. Abstainers have previously been shown to be a special group regarding factors of sociability (low), emotional stability (low), and psychiatric diagnoses (high)

[Citation needed]

Ok, it did turn you into a potato.

Reminder that dynamic typing is shit. Programs should run without user input.

If you don't understand the connection between the two, you don't get the joke.

>Abstainers have previously been shown to be a special group regarding factors of sociability (low), emotional stability (low), and psychiatric diagnoses (high)
L M A O
literally Sup Forums dot org

Every stack implementation in C I've seen with linked lists leaks memory.
What's going on?

I'm learning android with udacity courses

>light consumers

Still doesn't work. I probably messed up somewhere else

>light consumer masterrace
why can't I get a gf then ?

I could learn to live with this.

It's probably just example code and they didn't bother cleaning up.

Shouldn't this clean all the memory?
int main()
{
struct data d;
d.number = 0;

struct stack *s;
s = initStack();

long i = 0;
while (!full(s) && i < 100000000) {
push(s, d);
i++;
}

printf("press enter to pop all...\n"); getchar();

while(!empty(s)) {
d = pop(s);
}

printf("press enter to quit...\n"); getchar();
}

What do you think about having a compiler on a production server?

feest u eyes
#include
#include
typedef struct cons {
void *first;
struct cons *rest;
}* stack;
stack *mkstack(void) {
return calloc(1, sizeof(void *));
}
int stack_empty(stack const *s) {
return !*s;
}
void push(void const *v, size_t n, stack *s) {
struct cons *c = malloc(sizeof(*c));
c->first = malloc(n);
memcpy(c->first, v, n);
c->rest = *s;
*s = c;
}
void gettop(void *v, size_t n, stack const *s) {
if (*s) memcpy(v, (*s)->first, n);
}
void settop(void const *v, size_t n, stack *s) {
if (*s) {
(*s)->first = realloc((*s)->first, n);
memcpy((*s)->first, v, n);
}
}
void pop(stack *s) {
if (*s) {
struct cons *c = (*s)->rest;
free((*s)->first);
free(*s);
*s = c;
}
}
void rmstack(stack *s) {
while (*s) pop(s);
free(s);
}

disclaimer i wrote this on a phone and haven't tested / even tried compiling

What about the result of initStack()?

justify this sepplesfags
#include
#include

int main()
{
std::function x;
std::cout

Baka, that's not how you do functions in C++.
#include
int main() {
printf("%zu\n", sizeof(void(*)()));
return 0;
}

8

that the fucking point, retard

Try the pirated udemy course, it has much more content.

So you mean the point is that there's literally nothing wrong with function values in C++?
got it

I'm asking what the hell they're smuggling in a std::function besides a function pointer and an environment pointer

But why would you want to know that when std::functions are shit and you shouldn't use them?

>what are they smuggling in to std::function to make it so big
your mom

This is a recurring theme - anything in the c++ std library is trash and you should avoid it.

I didn't say anything about element type
you seem to be mad because you have trouble understanding english
you're quoting "can't declare an array" like you're going to refute that but your post doesn't have any array declaration; how dumb are you?
>I remember you
of course, I've been smacking you for years, here comes some more
>what kind of data structure does p point to
it points to an uninitialized object; an uninitialized object is not a data structure
>Does it have a name?
allocated uninitialized object
>I'm not saying it's anything, user
of course, you know you're a retard and are taking precautions now
>what one might call a sequential collection of elements with indexed random access
slice? vector? buffer? there are many names one might use
>that sort of thing is called an "array"?
maybe in some languages, but not in C; in C, there's this document called "standard" which precisely defines the meaning of "array", you can't just randomly call whatever you want an array

Yeah, obviously, but C++ is a good language.

>muh zero cost abstractions

Idris or Agda lads?

>you seem to be mad because you have trouble understanding english
You literally suggested that arrays should store their length so that you get the length of an array if you need it, and that the compiler could just optimize out the storage if the length is never used.

If you really are talking about getting the length of an array, and not that of any of the several things an array can become when you pass it around, that suggestion is blatantly stupid, because the length of an array is always available at compile time.

Agda pretty fucking obviously

>because the length of an array is always available at compile time.
VLAs

>You literally suggested that arrays should store their length
I made no such suggestion, you are confused again; go back and read the reply chain

considering reading through the c99 specification
thoughts? anyone done it? is it a good read?

deprecated

what am I supposed to justify here

It's more of a reference, not something you just read. It's boring.

>what the hell they're smuggling
Just look, you dumb fuck, it's all in the header; that's how templates work!

Let me make this very clear. Computer programming is hard. Really hard. It is a long road from where you are, little butterfly, to the top of the mountain. A programming expert. A real guru. Right now you're not even an amateur, don't you dare put that on your resume. You're nothing. You think you're some shit, no, you're a script kiddie who downloaded some warez of the internet and pushed a button. So listen carefully - before you begin writing your first lines of code, get familiar with basic concepts in abstract algebra, discrete mathematics, and computational complexity theory. Don't even dream of getting a job before you've mastered the polynomial hierarchy. Read all 8 volumes of "The art of computer programming". Do all the exercises. Then read "Concrete mathematics", and then read the proof of the PCP theorem, from start to end, in one go. If you don't understand it, go to step 1 and repeat. Invent your own assembly language, and write a C compiler with it. Then run it by hand. On the linux kernel. Step by step, pen and paper. And when you've finally reached the end of the boot sequence, get started on a python interpreter. And when you've had your first dream in MIX, wake from that dream and write that down come to me. If it compiles , you're ready to begin your journey. You're not an expert in programming by any means, but you've mastered the basics. You're worthy of touching a compiler. A job as a programmer? that's decades away. Maybe a few lifetimes. If you even get there. But lets celebrate the small victories.

Anyone code something related to cryptos? I feel like I'm being really retarded by not trying to ride this once in a lifetime opportunity to riches.

#include
#include
#include

int main()
{
std::unique_ptr x;
std::cout

>Computer programming is hard
stopped reading right there

It's a fucking bubble lmao

kanpai!

Yeah, you're right. When I said: (which was my first post in the conversation)
I was responding on the assumption that you were the guy who said this: However, looking back through the conversation, I see you aren't.

Anyway, my point *to that guy* still stands:
>for a compiler to determine whether an arrays length is ever used, it would have to be able to follow the array through all these possible transformations, which would AT BEST amount to running the whole damn program.

What if I have unironically done all of those things?

en.wikipedia.org/wiki/Greater_fool_theory

Besides I'm not talking about investing in or holding cryptos long term. I'm talking about making something and tricking idiots into investing in it (read: give me money).

You're objectively wrong. A programmer is not an expert in programming, a programmer is one who programs. So there's absolutely nothing wrong with pursuing a job as a programmer when you're not an expert. There's a big difference between an expert and a professional, especially in areas of expertise sufficiently large and difficult to be called fields of study, such as computer science. Plenty of professional programmers are script kiddies, and there's literally nothing wrong with that, because people have families to feed and even something as small as what you call "nothing" is a valuable skill that employers need and look for.

Anyone here actually works a programming job or are you all just hobbyists/NEETs

I'm going through a Software Design course and having to lead a development team of students is HELL. I feel like I have to check through everything they do because they manage to fuck up the simplest things even though we went over everything a million times. And we haven't even started programming yet; I dread the end of midterms when I'll have to deal with them again.
Is it like this out in the field or is it just a clueless college kids thing? It's a matter of life and death so please answer with that in mind

>Is it like this out in the field

Yep.

dumb frogposter

Problem:
Write a program where the input is N. The program has to find X, where X is the possibly smallest number of which multiplication of digits gives N. (any language)

Example:
N = 12
X = 26 (because 2*6 = 12)

N = 54
X = 69 (because 6*9 = 54)

...took me a while desu.

So, looking for some ideas/help.
Now that the education is done and i've worked for a great company for awhile i have tons of energy.

Now I want to start programming on my free time. And I have an idea i want to execute, but i have no idea what tools i should use, so i'm looking for input:

>I want to make a simple base-management game. Think X-Com rather than clash of clans.
>Not neccessarily multiplayer.
>Text based.

Easy enough. But:
>I want to display it on my webpage
>I want it to be able to evolve into an "actual" game down the road.
>Memes aside doing it object or ECS would be nice, so i want to avoid JS as far as possible
>Some server input/logic

What tools do i use? I've played around in 20+ languages and know 5-6 at a professional level, but all my solutions are really really clunky.
For the web and potential "home" distribution doing a model-view-controller setup is quite obvious and easy it being text based, but i haven't gotten any further than that.

Any ideas appreciated.

Hey Alex

Hi, I'm a programmer IRL. I have worked at companies where this was a problem and I have worked at companies where it wasn't a problem. Both kinds of companies had junior programmers, but they differed in how they managed them.

The way to avoid this is to have all programmers (not just the junior ones) demonstrate that their work is correct before they submit it for code review. There are a number of techniques for this, and it makes sense to adopt several. Here are a few. Pick and choose the ones that apply to the type of development you do.
- manually testing sample scenarios
- unit tests
- integration tests
- system tests
- model checking
- type checking

On a small team of experienced developers, these things aren't so important. On a large team or a team with inexperienced developers, these techniques are critical to avoid wasting the time of managers, senior devs, and the QA team.

Also, you have to accept that junior developers won't always write the best code. Point out the problems during code review and have them fix it. Don't worry about small style problems; focus on architectural issues.

Why don't people understand different OSes are good for different kinds of people?

Windows is an affordable technical solution that requires minimal technical know-how and offers only moderate functionality. Ideal for rednecks and normie brainlets (minimal technical know-how) who have no muns (affordable) and need a computer for their classes or jobs (moderate functionality).

Mac is a very expensive toy that requires only moderate technical know-how and offers minimal functionality. Perfect for rich snobs who have no need for productivity because they're already rich (minimal functionality) and see computers as nothing but fashion accessories (expensive) that reflect their high opinion of their own intellect (moderate technical know-how).

Linux is an early 90's piece of garbage that's completely free and offers maximal functionality but only by requiring maximal technical know-how. It's best for literal autists who can't get a job because of their social disability (free) and need to figure out how to be self employed so they can live (maximal functionality) and also happen to know computers inside and out because they're autists (maximal technical know-how).

And believe it or not, that pretty much covers the range of kinds of people there are.

That's right: literally everyone is terrible.

But that's beside the point.

>know 5-6 at a professional level,
>but all my solutions are really really clunky.
sounds about right
literally anything can transpile to js these days, just pick your favorite language.

k tard. wrong thread.

...

Good try. A was the right start though.

I'd rather avoid doing that for the simple reason that it brings alot of unknowns into it. Don't want to spend hours working around that X isn't possible to compile properly etc.

Thanks for raising my spirits, user

is there a way to execute php commands in a command line argument? e.g. php "echo hello world;"

stackoverflow.com/a/13503614

no run-time requirements is easy-mode
for i in range(N, N**2):
if reduce(lambda s,x: s*int(x), str(i), 1) == N:
return i

got it, -r

php -r "echo 'hello world';"