/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/
gist.github.com/anonymous/464b3adb0ae21477dd2d1d240edfdc68
ideone.com/VkV223
twitter.com/SFWRedditVideos

Fist for C++ generic programming deliciousness.

first for the glorious C programming language

Writing some Windows API toy programs to refresh my memory. The last time I programmed in Win32Api was 15 years ago. Then I switched to Linux but now I'm back to the superior OS.

Feels good to have an stable API that doesn't break every version and that works exactly the same after all these years.

literally nothing glorious

>no new tools to help you kode
>do everything by hand like it's 1970's
>glorious

>superior OS.

Airline Pricing Engine built on top of an ancient engine. And it's full of so much bad practice garbage I'm surprised no one has leaked the bad state of the coding within the engine. Someone already leaked the internal bugs to our customers. It's only a matter of time everyone finds out the source.

>do everything by hand like it's 1970's
You mean calling functions where appropriate and writing your own solutions where appropriate?
As you should in every other language.
Then yes.

Bumping for all of the dudes who needed help with their C problems.

So my parents always struggle with restarting the WLAN on our router if it's bugged again so I though I was gonna write them a small script that automates the entire process. basically what I have to do is log in to the router configuration site and click a few buttons in a row. I guess that's doable right ?

Can anybody recommend me a Python module that does this ?

>As you should in every other language.
There's no point handrolling your own custom data structures unless you have a hard performance requirement that you're failing to meet and your benchmarks prove that the data structure is a significant bottleneck.

Anything else is premature optimization.

If you want to do this the super easy way, you could probably use Selenium.
But I guess you might be able to use curl as well, if you wanted to.

>premature optimization.
Most problematic phrase used in programming.

I don't understand pointers.


Should I kill myself?

What about them don't you understand?

I've been programming for years.

I've never used a pointer in my entire life.

Impossible, except if you're doing pure FP.

>I don't understand pointers.
You've probably been taught poorly. They're quite easy.
Describe pointers to me.

You almost certainly have, even though it has tried to disguise itself as something different.

Absolutely nothing.

A pointer is the location of a variable in the memory.
Beyond that I don't get a single thing about it.
I can't even tell the difference between & and *

Right, I understand that.

You should understand what I'm saying; I've never personally used a pointer myself, even though I'm aware that they are used in the underlying mechanics of the high-level language I program in.

>Feels good to have an stable API that doesn't break every version and that works exactly the same after all these years.
lolwat
examples of breaking changes in linux please, 10$ says you're just a m$ fanboy

It's fucking numbers, addresses in the memory. That's it.

No, you don't get it. DO you do OOP ? As soon as you pass something to a function that can modify your something you're directly using a pointer.

>examples of breaking changes in linux please
HAHAHAHAHAHAHAHAHAAHAHAHAHAHHAAHHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHA

& and * are opposites of each other.
& means take the address of a variable. * means get the value that is being pointed to.
int x, y, *ptr;
x = 10;
ptr = &x; // Give me a pointer to x.
y = *ptr + 1; // Add one to the value that ptr points to.

It really depends on what "click a few buttons" does. If it triggers some JavaScript handler you need to inspect what they do or just use Selenium. If each button just triggers an HTTP request you can just use urllib or requests to fire off the appropriate series of HTTP requests.

What an argument!

But why do I need to use * in order to assign the location of an integer to another variable?


If I do:

int i=5;
int x=&i;

Why does it have to be int* x ?

Again, I understand precisely what you're trying to tell me. It's semantics.

I also remember being 16 many years ago, trying to show random people how they're technically wrong.

>tfw i chose to use mongodb for a personal project that involves money
Anyone else hate their life right now?

No it's not semantics. You just use improperly the word pointer. Pointer is not just C pointer, it's everuything that act as a C pointer. SO, except if you're doing pure FP, you're using pointers.

"ok"

sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/

Old, but relevant.

dumb frogposter

char var1 = 'Y';
char var2 = &var1; // !
This code makes no sense. var2 holds a single character. A character is clearly not the same as a memory address! In the same way, a memory address is not the same thing as an integer.
char *var3;
This means "the value at the memory address specified by var3 is a char". Or more simply, "you get a char by doing * to var3". So now you can put your pointer there.
var3 = &var1;

what would you do different? Its a shopping list

int condition = 1
while (condition == 1)
This can simply be replaced with
while (true)
Also, you should indent after you open your curly brace for the while loop.
while (true)
{
doStuff();
}

i didnt know how to turn off the loop at the end, if i do it with an int i can change the int to terminate the loop

How can a memory location be a char?

Sorry if it sounds too stupid asking this, but I really suck at it.

break;

>A pointer is the location of a variable in the memory.
Correct
>I can't even tell the difference between & and *
& is the address of operator. It's a unary operator (only takes one argument unlike things like + that take two) that returns the memory address of any given variable.
The * is quite heavily overloaded in C, it can be multiplication as I'm sure you know, it's used to declare pointer and it's used to dereference pointers. Imo the two last overloads are confusing to newbies but you get around it quickly.
Example:
gist.github.com/anonymous/464b3adb0ae21477dd2d1d240edfdc68

Now maybe you have more questions. Ask them.

A memory location -can't- be a char. That's the point.
char x;
x is a char.
char *y
y holds the location of a char.

Also, you should indent after you open your curly brace for the while loop.

what does that mean?

Actually I should probably have posted this instead.
ideone.com/VkV223
Makes more sense to not have you set up a project right now.

So pointers have to be of the same type as the variable I'm pointing it to?

Pointers have a pointer type of the variable you're pointing to. When you dereference a pointer you get the type you were pointing to back.

Why would I need to dereference a pointer?

Actually, now that I get a bit more how pointers work I don't really know why I would use them.

//bad
while (true)
{
doSomething();
}

//good
while(true)
{
doSomething();
}


Also there's a common trick for expressing "for every line of the input". I'm not sure how it looks in C#, but it should go something like this.
while ((String currentLine = Console.readLine()) != null)

Anyone have any good resources for learning VHDL?

the only good
void tmpfn()
{
if(cond) {
int x, y;
fn( &x,
&y);
}
}

I mean first of all, why would I declare a pointer when I can always use the & operator?

Forget sepples references dumb fuck.
Use pointers only.

Dereferencing retrieves the value that is pointed to.
A pointer which cannot be dereferenced is fairly useless.

The easiest example to understand is a "swap" function.
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}

int main()
{
int x = 4;
int y = 7;
swap(&x, &y);
}

Where do you keep it?

When I pass a variable by reference, do I always use * for each variable inside the procedure?

The number of branch statements a programmer uses is inversely proportional to their skill level.

No that's stupid. I could do everything in one while loop and one switch case. And according to your post I would be an awesome programmer.

Yes. In C you must explicitly state to follow the reference.
int *x;
x = y; // The pointer has changed - it may be pointing to a new int.
*x = z; // The pointed-to int has changed, but it's the same int.

you make a pointer because sometimes passing arguments by value makes a copy of that value and is expensive, so passing just one memory address is cheaper and lets you modify that value inside the function.

another reason for declaring pointers is that you not always want the address of a variable, sometimes you want to create arrays, like this:

/*this means that str is pointing to a sector in
memory where the value of ten characters
are stored continiously*/
char* str = malloc(10);

References (C++) are syntax sugar for pointers.
I think the best way to actually learn when to use pointers or references is to program something and learn from your mistakes.
No it depends enough on the current problem to be completely irrelevant to programmer skill. Some problems have very nice algebraic solutions. Others simply don't.
Some have algebraic solutions but you'd be a fool if you use them.

reference everything, fuck pointers.

if user is struggling with the basic ideas of pointers, it may be unwise to introduce arrays and pointer arithmetic

kys yourself

There is nothing wrong with programming python. Python is incredibly useful for some tasks.

>python
>a programming language
pick one

There's nothing wrong with programming COBOL. COBOL is incredibly useful for some tasks.

>There's nothing wrong with programming FORTRAN. FORTRAN is incredibly useful for some tasks.

There's nothing wrong with programming node. node is incredibly useful for some tasks.

COBOL is incredibly useful for making 400k, so yes, you are correct/

There is nothing wrong with programming brainfuck. Brainfuck is incredibly useful for some tasks.

There is nothing wrong with programming Haskell. Haskell is incredibly useful for some tasks.

>Feels good to have an stable API that doesn't break every version and that works exactly the same after all these years.
Yeah I agree, programming for the linux kernel is pretty great.

except that's wrong fagooooooooooooooooot

Nice argument.

any good book about c++ expression templates?

>premature optimization.
No such thing.
All optimization is good optimization, and if the result is that you're no longer able to comprehend the problem, that simply means you're a brainlet.

thanks

I guess that random shitposter retard #61374595 is smarter than that brainlet Knuth then

>just because guy is know for something makes everything he says automatically true

Well, yes, because Knuth is actually Trump, and there's literally no one who isn't smarter than Trump.
You see, in C, it's impossible for more than one object to have the same name.
Such as the name "Donald."
Naturally, this also means Donald Duck is actually Trump.

nice english retard

dumb frogposter

Considering starting some open source node contributions do you get banned if you're not very good?

no you don't understand
that picture is you
you are the dumb frogposter
i am not even a frogposter

FOY

Are you talking about C++ references?
In general, you should only use pointer when you can't use references.

>post frogs
>not frogposter

bad advice

Fuck off Ctard.

but I like C++

Fuck off Bjarne.

...

This is good advice
If you write a test that passes that implies you've already implemented the module the test is meant to be testing which is the wrong order of doing things because you should have written the test first so you don't lose sight of what your module needs to accomplish

people like you create poorly designed, error riddled code

Well then you should agree with my advice.

You wouldn't do this in C++ code:
void foo(int *x) {
*x = something;
}

When a reference would be way more suitable.

Sepples references are a bit restricted, you can't change where they point to, so they can't be used everywhere.
And my advice was, where they can't be used, or where pointers would result in cleaner code, then use pointers.
And when you DO use pointers, consider smart pointers first, and fallback to raw pointers.

If you disagree with this, you're not programming C++ properly.

>designed
what design?

no u
people like me create code that works and does what it's supposed to do and doesn't do anything extra
your code categorically either doesn't work or does too much because you didn't program in what your aim was before you started aiming for it

This is correct. How am I supposed to know if my function works without testing it? And if I'm gonna test it, may as well automate what I'm gonna do in the reply anyways.

Unit tests are absolutely hopeless at spotting bugs or even proving that the implementation works.
They are an utter stupid waste of time.

>Sepples references are a bit restricted, you can't change where they point to
You can't really do this in C either
void foo(int *x) {
x = somewhere;
}

The function foo is now effectively a no-op