/dpt/ - Daily Programming Thread

What are you working on?
Previous:

Attached: 1525898109187.png (934x1000, 389K)

Other urls found in this thread:

github.com/rust-lang/rust/issues?q=is:open is:issue label:I-ICE
github.com/rust-lang/rust/issues?q=is:open is:issue label:I-ICE label:regression-from-stable-to-stable
pastebin.com/iwy5BFWY
en.wikipedia.org/wiki/Least_common_multiple#Computing_the_least_common_multiple
youtube.com/watch?v=FoTYV22qZTg
twitter.com/NSFWRedditVideo

Programming is fun unless it is your job.
Share something fun for other anons to do! (p.s: not your homework)

Trying to think of a project to self teach C# and ASP .NET Core 2.

Perl 6 'grammars' are amazing.

s o y f a c e

Attached: Screenshot_20180511-061511~2.png (861x1167, 654K)

any thoughts?

I'm trying to write software for a microcontroller but my stack is getting unbalanced somewhere, and I can't figure out where.

Make a website that shows a random image from a random booru on every reload. Heroku has free hosting for 3 out of 4 weeks every month.

How to make learning to program not so boring? I can grasp the concepts easily but it's just so fucking boring and end up leaving the book after a chapter

it's because YOU are boring.
you have no reason to learn it, or apply it.

find a new hobby.
programming is 95% dry reading.
If you don't enjoy it, it's not for you.

I know absolutely nothing about C#, and can hardly understand this wall of text, but

grid[1, 4] = "X";

This is just an assignment, is it not? Shouldn't you actually output as side-effect?

Programming is just a means, not an end per se.

Like writing: one would not simply 'write', but you would 'write about something'.

github.com/rust-lang/rust/issues?q=is:open is:issue label:I-ICE

Write organized code and you will rarely go wrong.
Start by seperating tasks into methods.

YIKES

yes. the loop was supposed to re-display the new
however, i had the print in the wrong place.
fixed it.
/feeling dumb

is there a good resource to truly understand how to style the code? i really want to learn.

why is f# so comfy bros

See I want to make programs and such but every time I try to push myself to read more than a chapter or so I get bored. Is it really not for me?

So does any of what I'm describing sound "normal" to C people here? I'm relatively new to C (I originally learned it for embedded stuff when I did EE but here it's used for some pretty heavy computation) and it's not really my job, but this shit looks terrifying. And surprisingly enough it runs really well which is even scarier.

I mean the thing I'm looking at now is technically a daemon; I can believe that. Probably Ba'al-berith.

It depends on the language. Good style is really just playing into the idioms of the language and allowing the tools do the work for you.

You are recreating the aray on every loopmy dude.
grid is a new empty object everytime so you should move it outside the loop.

Nearly all affect only the nightly or the beta compiler, though. The bad ones are these:
github.com/rust-lang/rust/issues?q=is:open is:issue label:I-ICE label:regression-from-stable-to-stable

> is there a good resource to truly understand how to style the code?
Think about the problem, and split it naturally as you see it.

C# is OOP, so consider an actual physical Connect4 game; what objects do you have? What does each do?

Sup Jow Forums, I am an Android noob and I have an Async in a different java class file. In this async, I have an doInBackground and another method. Now I want to pass the result of doInBackground to the other method in the async class, and then put the result in a list in main activity.

Is this the way to do it or is my reasoning wrong?

The closed to open ratio is amazing but they should really do some more considerations.

is there a "for dummies - C# style guide" anywhere?

i did. that's how i fixed it. but thank you.
got the creation happening before and the re-display on each loop.

I've no idea; I know zero C#. Just generally observing.

C# is OO, so you want to be across that. The book of four design patterns is good to know as well as MVVM/MVC for UI stuff. Dependency injection is also really in vogue right now in the C# world.

Apart from that, a lot of good looking C# code is really down to knowing what libraries are available. It's an exceptionally feature rich language and most of the stuff you want to do likely exists in a library somewhere already.

I have worked a lot with C# and I can feel when something about the design is not right.
Your problem is where you declare your variables and not following the single responsibility principle.
Learn about scopes and access modifiers to decide the proper life time and accessibility of the objects
Learn about single responsibility principle to make your code efficient and readable.
e.g: if the array exists the entire lifetime of the program (one class in your case) make it a static field.
Make a method to print the contents of the array instead of doing that in an already bloated while loop.

thanks. i'll be absorbing these inputs.

Attached: guidosicp.png (601x623, 100K)

Look at C# libs on github and especially nadekobot (though it is a bit advanced)
It will give you an idea about the DOs and when to.
You can also imagine your program as a 3rd party lib that you are using. It should push you to make things easier and clearer from a user point of view.

>so full of s o y he coudlnt play it off as a joke and had to channel his inner woman
christ how embarrasing
pythonlets have less diginity than anime watching, wolfgirl vn playing neets

Get off twitter and read your SICP, Guido.

Attached: sicp.png (400x400, 889)

>install someones binary release from 2017
>it's not reliable and slow
>recompile the same source with a modern compiler
>it's now reliable and fast
Remember to appreciate the work done by compilers.

>tfw you can do this in C# 8
Enumerable.Range(1, 100)
.Select(n =>
n.IsFizzBuzz ? "FizzBuzz" :
n.IsFizz ? "Fizz" :
n.IsBuzz ? "Buzz" :
n.ToString())
.ToList()
.ForEach(Console.WriteLine);

Attached: excited.gif (430x238, 652K)

I like your boss approach. Doesn't feel like a hack at all. It is C -- you either make fast shit and using right or not making fast shit and using it wrong.

push(&root,5);
void push(struct StackNode** root, int data)

I dont understand why they pass the address of the pointer and not the actual pointer. Anyone with a brain understand why?
pastebin.com/iwy5BFWY

Attached: 5128caaab9b70981821f824928c0cd82_full.jpg (1024x728, 142K)

Reminder Guido von Python literally tried to remove lambdas from his language.

so that they can modify the pointer itself instead of only what it points to.

*root = stackNode;

He probably should because in their current state lambdas in Python are very limited and useless for most use cases.

*root = stackNode;

Because it gets reassigned so the root variable outside the function is now the new root.

If you want to change a value you pass a pointer to the value, so naturally if you want to change a pointer you pass a pointer to a pointer.

Thank you lads so much.

I'm not too good at programming, but could someone help me with this?

How do you replace a value in a list in python?


for x, y, img in background_xy:
x = x * tileWidth
y = y * tileHeight
x += x_change
y += y_change
background(x, y, img)
#I want to change x and y in the list to the values they got changed to

all releases of C++ have actually been experimental and C++29 will be stable and backwards compatible with C89

because it is deprecated c
void push(struct StackNode*& root, int data)

Attached: freegrug.jpg (371x338, 34K)

by making a new list. You cannot replace values in a list

>non const reference
yuck

>being a moron

Ah, okay. Thank you for telling me that, I've been searching for how to do it for a while now.

doing some project euler to learn haskell
factor :: [Integer] -> [(Integer, [Integer])]
factor = go 2
where go c n
| all (==1) n = []
| any (\x -> mod x c == 0) n = (c, n') : go 2 n'
| otherwise = go (c + 1) n
where y = \x -> if mod x c == 0
then div x c
else x
n' = map y n

pe5 = foldr (*) 1 $ map fst $ factor [2..20]

Again, thank you. This has all clicked now. Wish I could buy you coffee.

you could make a special rule for go 2 (so it calls go 3) and then do go (c + 2) n

wait is it more than just primes? if so nvm

it's basically the table method shown here
en.wikipedia.org/wiki/Least_common_multiple#Computing_the_least_common_multiple

Will even numbers other than 2 ever show up?

Fresh me::.

Attached: dmrw81h277x01.png (1920x2160, 3.54M)

>3.54 MB
kuso kisama

Satire needs a basis in reality. People on Jow Forums that are too retarded to learn programming is not a good indicator of what tools you should use.

Rust does not have this problem.

Sounds like he did not know what flags were.

>As a general computational algorithm, the above is quite inefficient. One would never want to implement it in software

It's based in reality tho.
t. been writing C++ professionally for 6 years

(You)s are a better stimulant than coffee anyway.

Attached: you.jpg (1202x752, 567K)

Is it difficult depending on external attention or is it a non-issue today with the internet?

poor programmers blame their tools

of course, if I wanted efficiency I'd just use
pe5 = foldr lcm 1 [1..20]

poor programmers make shit like msvc

saved

>blaming tools for internal errors is a sign of poor programming ability

Attached: 1513233658559.jpg (250x250, 19K)

neither does C++

Well I can give you sufficient yous and coffee. I think you deserve both for kindly helping an user. If you need to know anything about Ireland, ask.

>If you want to change a value you pass a pointer to the value, so naturally if you want to change a pointer you pass a pointer to a pointer.
Specifically
>if you want to change a pointer you pass a pointer to a pointer
Is the easiest way I've heard to explain this, in English.

I don't know what it is but, I understand pointers but have a hard time explaining them to people without code examples. Outside of saying "the easiest way to think of it, is that a pointer points to something, that's all"

lambda are useless in python because of nested procedure.

I can function without stimulants, it just puts me in a better mood to have helped someone, particularly if it's on an anonymous board where there's no identity or presence to maintain and I can just swoop in and out like the Tooth Fairy.

the entire point of a lambda is that you don't need to give a lambda a name

What's /dpt/'s take on this?:
youtube.com/watch?v=FoTYV22qZTg

Attached: sBJG8sT.jpg (1294x478, 60K)

I generally prefer Bing to Google but if I search for C stuff on Bing the results are almost exclusively C# and C++ whereas Google results tend to be C with a bit of C++ mixed in.

Any advice other than just sticking to google for those searches?

wrong. the entire point of lambda is to be an expression which is required for declarative programming. python being imperative, guido doesn't care.

Really? It is quite the opposite for me. Google gives result for C++ most of the times so I have to type "C lang"

Attached: bingo.png (763x992, 140K)

>add "clang"
>get twice as many C++ results
bjarne ruined programming

I do a lot of
"c -c++"
- will prioritize results without the following string.

What's the best way to have "private" members of a C struct? i.e. ones only used internally in functions meant to manipulate the struct

Putting them in a struct hidden behind a void pointer? Just giving them a some prefix and a comment that the user shouldn't be touching them?

The latter is preferred.
>Putting them in a struct hidden behind a void pointer?
Putting them behind a forward-declared struct is probably better if you're taking this route.

.c?

I'm qsorting strings with C's built in qsort.

It throws this error
malloc.c:2427: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
with a string longer than 24 characters and this
free(): invalid next size (normal): 0x00007fdfac008410 ***
for strings longer than 30 characters

What the fuck is going on?

Right now I basically do:

/* foobar.h */
struct foobar {
Foo foo;
Bar bar;
void *private;
};

/* foobar.c */
struct PrivateState {
All all;
My my;
Private private;
Stuff stuff;
};


And I just assign a struct PrivateState to the private pointer internally and deal with it there.

>Putting them behind a forward-declared struct is probably better if you're taking this route.
What's the advantage over keeping it completely opaque?

It's more idiomatic that way. If you have a struct declared as
struct foo
{
int x;
int y;
int z;
Impl *pimpl;
};
People know what they're dealing with. It also means less casting for you - as soon as Impl is made complete by defining it, you'll be able to access the members directly.

>What's the advantage over keeping it completely opaque?
What's the advantage of keeping it opaque?

>What's the advantage of keeping it opaque?
ABI compatibility. I can change the struct without clients needing to recompile.

the attributes being now hidden by a set of operations (the interface), you can now do all kind of interface abstraction techniques (a.k.a design patterns). you should have learnt that in your software engineering introduction class.

no we were taught functional programming instead

You could just have a field, which you can acces from the main activity, and set the field from the doInBackground method.

You could also have the main activity as a field, and pass it in the constructor to be able to access it from inside the doInBackground or the other method

software engineering is not specifically about functional, or procedural, or declarative, or imperative, or ...

hiding implementation details and preventing invalid states, e.g. if you had a list type that also included length, you wouldn't want people to be able to set a false length

Is it actually possible for a forward declared struct pointer and a void pointer to be a different size? It's my understanding that changing the struct implementation would only break ABI compatibility in such a scenario.

Legitimately asking, I've never considered this and always assumed forward declared structs to be just as opaque as void pointers, just with a name.

You could have a larger stuct composed of your public and private data, on your side you use the union of public and private data, on the clients side you pass a pointer to the public part. when receiving the public data on your side you can freely cast back to your private data as long as the public data is the first in public_private_data, such that taking the address of the public data in public_private_data just gives you back the address of public_private_data.
#include

struct private_data {
int a;
int b;
};

struct public_data {
int x;
int y;
};

struct public_private_data {
struct public_data pub;
struct private_data priv;
};

int main() {
struct public_private_data dat = {
.pub = (struct public_data){
.x = 3,
.y = 5,
},
.priv = (struct private_data){
.a = 10,
.b = 11,
}
};
printf("%d %d %d %d\n", dat.pub.x, dat.pub.y, dat.priv.a, dat.priv.b);

struct public_data *public = &dat.pub;
printf("%d %d\n", public->x, public->y);

struct public_private_data *casted_public = (struct public_private_data *)public;
printf("%d %d\n", casted_public->pub.x, casted_public->priv.a);
}

Not him but reminder that there's literally nothing wrong with being onions.

I am a somewhat overweight man with glasses, some facial hair, a love for a slow-ass hipster scripting lang (Ruby), an interest in gayming, a noticeable effeminate leaning in my behavior, and a tendency to be captured in pictures with my mouth hanging open, and I defy you to find flaw with this. Citing any of the things I just said about myself verbatim does NOT count as a flaw. You have to JUSTIFY why it's a flaw if you want me to buy it.

>inb4 can't defend self because too onions
I'm a blackbelt actually. I can defend myself just fine. I'm not very strong, but self defense doesn't have to be all about brute strength if you know how to do it right. Besides, these days, there's such a thing as a gun. A small child could easily hold his own against a sumo wrestler with one of those.

>inb4 not alpha
You don't have to be alpha to get other guys. The whole alpha/beta thing is turned on its head in the gay community.

>inb4 if people take photos of you with your mouth hanging open all the time then clearly you are not photogenic
Well I mean yeah. But what exactly is wrong with that?

>onions
i meant onions