/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

mgattozzi.github.io/2016/10/01/haskell-rust.html
wayback.archive.org/web/20090525150626/http://blog.garbe.us/2008/02/08/01_Static_linking/
web.archive.org/web/20081228101359/http://9fans.net/archive/2008/11/142
web.archive.org/web/20091107230144/http://9fans.net/archive/2002/02/21
nth-dimension.org.uk/pub/BTL.pdf
yegor256.com/2014/11/03/empty-line-code-smell.html
twitter.com/NSFWRedditImage

>no cat op
shit thread

how do i only take the parts of a library i want from a bigger library so i can use only those files

for example, i want to take only the boost filesystem library, is there an easy way to do this without copy pasting all the files by hand?

For what purpose, user? Why can't you use regular boost installation?

actually screw that

I'm a rust missile now since it can be FFI'd in Haskell easily

mgattozzi.github.io/2016/10/01/haskell-rust.html

right your low level shit in rust

i don't want my program to be 1.5gigs

Do you understand how compilers and linkers work?

>I'm a rust missile
>right your low level shit in rust
>right

i started c++ today. am i misunderstanding this entire thing? is c++ smart enough to figure out that i'm only using certain parts of the boost library?

>is c++ smart enough to figure out that i'm only using certain parts of the boost library?
Only functions and classes you actually use will be compiled (and linked) into your binary, yes.

If you don't believe me, try including a bunch of headers and see that the binary size doesn't begin to grow until you start calling functions defined in those headers.

What's the best book for learning programming as a concept using languages as a tool, rather then just a quick rundown © of a language's documentation?

C++ is a language, it's not smart at all. You should ask your compiler.

that's great news but now i'm really confused. what's the point of DLLs? and why can i download a library in binary format? i thought those formats existed to be shipped alongside an .exe?

>that's great news but now i'm really confused.

>what's the point of DLLs
Because in some cases, it's redundant to include even that stuff. glibc, for example, GNU's implementation of the C standard library, is usually dynamically linked, because it's the same for ALL C programs you might use and therefore redundant to statically link with all your binaries.

For C# and other .NET stuff, all the .NET stuff is always the same and usually present on most Windows installations, so instead of creating a binary with those statically linked, they just dynamically load those DLLs.

>and why can i download a library in binary format?
You can. And these may be dynamically linked libraries, or they may be object files that you link in statically.

>i thought those formats existed to be shipped alongside an .exe?
Not usually to be shipped, they exist so in order to make your .exe smaller.

Look at it this way: Dynamic linking has the upside of multiple binaries being able to share the same code, so you save disk space (and in some cases, memory space). The downside is that it's clunky to use and you need to make sure that the correct version is present.

Static linking has the benefit of you not needing to declare any dependencies to external library files (such as DLLs), but the downside is that your binary might grow and if you have many programs that use the same routines, you duplicate that routine multiple times unnecessary and "waste" disk space.

There's no point in DLLs. Dynamic linking was a mistake.

wayback.archive.org/web/20090525150626/http://blog.garbe.us/2008/02/08/01_Static_linking/

web.archive.org/web/20081228101359/http://9fans.net/archive/2008/11/142

web.archive.org/web/20091107230144/http://9fans.net/archive/2002/02/21

nth-dimension.org.uk/pub/BTL.pdf

I know none of you bitches can answer this, cuz I'm the only real programmer here even though I've been graduated for 9 months and am still unemployed, but:

I'm trying to enable my custom Windows shell extension by adding the appropriate keys to the registry. I want to enable it for text files, so I want to put the key in

>HKEY_CLASSES_ROOT\txtfile\ShellEx...

BUT since I have txt files associated with Notepad++, I have to put the key in

>HKEY_CLASSES_ROOT\Notepad++_file\ShellEx...

Otherwise, the shell extension won't be enabled for my txt files, which is ridiculous, because if I then associate txt files with a different program, my extension will stop working. So, where the fuck can I put my key so that my extension will work for text files no matter what program they are associated with?

>it can be FFI'd in Haskell easily
nice

>Still using the C ABI
Why don't you try write a Haskell module or whatever that directly interacts with the Rust ABI?

Bruteforce calculator in python3, did try to make it tell you in seconds how long it'd take the average pc but it got buffer overflows
#!/usr/bin/python3
charsetlen = 0
print("Does your password contain lowercase letters? [y/n]")
choice = input(">>> ")
if "y" in choice:
charsetlen = charsetlen + 26
if "n" in choice:
charsetlen = charsetlen

print("Does your password contain uppercase letters [y/n]")
choice = input(">>> ")
if "y" in choice:
charsetlen = charsetlen +26
if "n" in choice:
charsetlen = charsetlen

print("Does your password contain numbers? [y/n]")
choice = input(">>> ")
if "y" in choice:
charsetlen = charsetlen + 9
if "n" in choice:
charsetlen = charsetlen

print("Does your password contain special characters? [y/n]")
choice = input(">>> ")
if "y" in choice:
charsetlen = charsetlen + 33
if "n" in choice:
charsetlen = charsetlen

print("How long is your password?")
length = input(">>> ")
length = int(length)
charsetlen = int(charsetlen)
for i in range(length):
charsetlen = charsetlen*charsetlen

print("Number of possible combinations")
print(charsetlen)

please tell me how I could improve

Actually, looking it up, Rust doesn't even have a defined ABI.
What a joke.

>pipe operator
>Haskell

You could remove a pair by using apply prior to many'.

I also suspect that you missed the sarcasm in my post.

depend of the cpu ?

doing some request to test reactivity of the hardware

if "n" in choice:
charsetlen = charsetlen

This does nothing, and answering something other than y or n just skips both blocks.

>Does your password contain special characters?
Needs some definition of which special characters you count. Do you count ¿ for instance?

for i in range(length):
charsetlen = charsetlen*charsetlen
Just wrong. This results in a value of charsetlen^(2^length), when what you want is charsetlen^length. Python has the ** operator for powers, so no reason to use a loop.

x |> f = f x
think it's & in Data.Function
(imho Data.Function shold be put in Prelude)

Oh fuck, I killed the formatting. Ah well.

yes? boost is a collection of libraries, you can link only the parts you need

You mean '&'. And why on earth would you use that instead of apply? I think F# has been rotting your brain.

Here, more words.
f x y = liftA2 selfCons (fmap pure x) $ many' $ liftA2 (on mappend pure) x y
selfCons = (join .) . (:)

>why on earth would you use that instead of apply
because it's an operator and parses differently

(&$&$&$) is an operator that parses differently, if you choose to define it.

'|>' is not in Data.Function: you would have to define it yourself. Whereas '$' is exactly the same with the arguments in a more logical order, and '&' is in Data.Function if you're desperate to have the arguments flipped.

I'd recommend using the defaults.

So I should use def whatever(): then add an else so if it doesn't have y or n it sends them back to the def

>powers
fuck I didn't know the name, I was googling how to do ^ in python and that didn't help

thanks for all the help user

I have a 2d array of button in c#

how would I write a method that takes the currently pressed button as a parameter and performs some code using that buttons position in the array

say the button that was pressed is array[4,3]

I want to check if the background colour of array[x+1, y+1] is a certain colour and return true if it is

thanks

Wow, thanks for the info!

No worries. You're right that you could consider apply to be a kind of 'pipe' with its arguments flipped, but it's best to be idiomatic (rather than using F# concepts).

You are just butthurt that it is used in F#.
& is not very different to $

lolwat
Are you the guy who thought |> was in Data.Function?

Look, I get it, it's your first day outside of reddit, you've just come here from r/Haskell and you want to show off that everything done in F# is inferior.

But you're expected to actually read posts before replying to them

c++ might just as well not have a defined abi

f x y = liftA2 (on () pure) x y |> many' |> liftA2 ((join .) . (:)) (pure x)
where (|>) = flip ($)

There's nothing wrong with F# idioms, there's just no point wasting a line.

>Year of Our Lord 2017
>still can't infix arbitrary expressions in Haskell
bloody roundhead traitors

i've been trying for an hour to get including external files in qt working

garbage like this is literally 99.9% of trying to learn c++, it's all terrible, terrible garbage

Maybe we shouldn't use haskell

seriously, why can't it be as easy as putting the path to a header file into include? what am i doing puting paths in some places and running qmake and then editing some .pro file? what the fuck is this?

it's called c cruft needed to backwards compatible bullshit, notice how new languages basically include all the normal shit for you officially now (rust, go, swift, etc.)

I'm making a gaem

>v/v/>>Sup Forums ebin mandcchild xd :^)

pls

no help for frogposters
you probably can't even program
bet you're using unreal or unity or game maker or something

no, i'm making a gaem in C with opengl

Stop posting frogs and start posting code you fucking homosexual

Is there a way to search for projects on GitHub via one of project's files (kinda like a reverse image search on Google) or partial blocks of text (like a function, or anything) from one of the files?

I'm finally going to start my CS course in March. Any tips for a freshman?

You won't learn anything unless you program as a hobby.

I'm actually studying Python by myself until March and I already know the basics of C. I have some future projects I plan on doing as a hobby once I get good enough.

Besides programming in general, is there anything I can do so I don't become a shitty computer scientist?

Currently going through Cracking the Coding Interview.

whats an easy way to know when you're over-engineering something

What's the type signature of anime?

Your code has empty lines to separate "sections" of code.

yegor256.com/2014/11/03/empty-line-code-smell.html

Read the textbook. Yes, it's expensive. Yes, you should get it if you can. Yes, it's fine to pirate it so long as you read it.

No one cares that you know something before the professor explains it; exploding about it makes you look like THAT KID. This has become a personal grievance because I'm taking night classes after work and there's THAT KID who is the embodiment of neo-Sup Forums (2012+) autism and plebbit's shitty "le random" humor who spouts random technobabble about Gentoo and programming concepts. Waves around some Japanese LN about Trump he bought because it's "so random". Fuck him. Don't be that guy.

If the professor wants you to do something a certain way even though there are better ways of doing it, he's got good reason for having you do them. Well, most of the time - it depends on how good your professor is at teaching. He's the one giving you a grade at the end of the day.

If you're a student without responsibilities, please do yourself a favor and start grinding projects. If you have an idea that you like and its reasonably doable, spend some time and make it real. Build a portfolio now.

Thanks for the tips. I already studied Calculus by myself, so I'll be skipping that as I already have the books, etc. I'm not an attwhore, so I'll not be THAT KID.

About the textbook, I should buy only two in the first semester: Introduction to Algorithms and any book about C I find good (I'm thinking about Modern C, by Jens Gustedt).

Nice one

Working on an implementation of a paper on a fast Bounding Volume Hierarchy builder called Bonsai.
Wanted to parallelize it neatly so I started out making a thread pool, then building various task schedulers on top of that to do different things, and eventually I realized they were doing mostly the same to I was able to reduce it to a single generic parallel for loop (replacing the concurrency::parallel_for from the PPL) and a multiple producer/multiple consumer job scheduler.
It's the best feeling when you're able to unify massive slabs of almost identical code into a single generic implementation that leaves you with only a fraction of the LOC you had before.

And it's pretty cool to fully rebuild the BVH of an entire scene in real time. Currently at ~30ms for a ~330K triangle scene.
Real time path tracing will soon be reality I hope.
No more ugly rasterizers. Only elegant light simulation.
And it's funny because with the ever increasing amount of triangles they want to push, ray tracing will eventually be theoretically more efficient than rasterizing because of a lower complexity bound.

CuteT Pi ()

...

explain to me why this fag thought I was trolling in pic related.

Context is a guide on C++

On an i5 2500K that is, so on modern CPUs it will run significantly faster. It also scales pretty well with the number of cores (heaviest part of the algorithm even scales linearly)

probably because 19 out of 20 times its a sign of design issues with your code

Holy shit this is retarded.

>a constant is a design issue

that has nothing to do with what i asked about tho

I have a problem in SQL that is probably common.

The group "Administrators" has an entry in alist.
I want to replace this entry with entries for every member of "Administrators" (there is, of course, a table which assigns members to groups).

E. g., what I have now is :
Administrators CanRead

What I want is :
Paul - CanRead
Jessie - CanRead
Martin - CanRead

I have to do so through the table:
Paul - Administrator
Jessie - Administrator
Martin - Administrator

Probably, there is a term for such problems, like "recursive query".

the cpp / h split is, hands down, the most retarded forced feature of any popular language.

>inb4 "no, its OOP"

static void allocPages(int page, int n)
{
assert(n > 0);
u32 addr = page * 4096 + KMALLOC_OFFSET;

for (; n > 0; n--, page++, addr += 4096)
{
virtualMapKernel(addr, physAllocPage(), PAGE_PRESENT | PAGE_WRITE);
heap.setUsed(page);
}
}


>HUR DUR DUR DUR MUH EMPTY LINE DUUUUUUUUUUUUUUUUUUUUUUUUUUR
It's called making your code neat you fucking poo in loo

ftfy
static void allocPages(int page, int n)
{
assert(n > 0);
u32 addr = page * 4096 + KMALLOC_OFFSET;
for (; n > 0; n--, page++, addr += 4096) {
virtualMapKernel(addr, physAllocPage(), PAGE_PRESENT | PAGE_WRITE);
heap.setUsed(page);
}
}

>creating global variables for no reason isn't a design issue

Why in god's name would you try to correct a C++ guide if you're this much of a C++ novice?

If you cared about neat code you wouldn't put braces on a new line, NEET.

I advise you to take a ten minute break, and reread your post with a glass of water to ensure you don't die of embarassment.


>extern const double PI;

>>DESIGN ISSUE! NOT ENOUGH OOPATTERNS!

Fucking disgusting

I put braces on a new line BECAUSE I care about neat code.
Get your disgusting taste out of here nigger.

both fags

If you're not using extern there to make that variable accessible from other modules, you're using extern wrong.

This has nothing to do with "OOP patterns" or whatever, it's about you polluting the global namespace for no god damn reason.

What about the non-retards who use "//" for single line comments?

if (
condition
) {
Statement

.h
namespace constants {
extern const double e, pi, sqrt2, ...;
}


.cpp
namespace constants {
const double e = 2.71, pi = 3.15, sqrt2 = 1.41, ...;
}

It's not always true.
Sometimes you need a function to do several things at once.

>2017
>Not going full Martin

You repeating the same thing a lot, I would change the "Do you have a X? if so +Y", into a function, and then sum over the results.
so this is how i made it


def get_inc (char_inc):
print("Does your password contain {} [y/n]".format(char_inc[0]))
return (input (">>>") == 'y') * char_inc[1]
def main():
characters =(("lowercase letters", 26),
("uppercase letters", 26),
("numbers", 9),
("special characters", 33)
)
charsetlen = sum(map(get_inc, characters))
print("How long is your password?")
charsetlen = charsetlen ** int(input('>>>'))
print("Number of combinations {}".format(charsetlen))

if __name__ == '__main__':
main()

Now you're making a namespace for no reason.

Why are you so against just declaring the member variables of a class within the header? Everything just works and you don't have to constantly pull bullshit out of your hat to cover up all the issues you're causing.

Unless C++ is different from C you don't need to declare them to be extern (the are implicitly extern).

>code full of magic numbers
>using assert guards instead of declaring your parameter as unsigned
>for with several increments on the same line
>talking about "neat code"
This has got to be a troll.

What is wrong with the example I gave?

if that's correct then nevermind

C++ const does imply internal linkage by default.

>Magic numbers
Which one? 0 or 4096?
Any experienced programmer should have no trouble figuring out that 4096 is the size of a page.
If it's 0 your talking about, then you should just quit programming now.

Welp.

It doesn't really matter whether you define the stuff in the header or not. If people need to know the exact value for whatever reason it should be in the header file though. If the exact value is not really necessary it might be good to keep the stuff out of the interface file.
Opening an issue on Github about it is a waste of time though.

Actually, I would say that as long as you are honestly interested in the topic and pursue both 1) reading and 2) programming in your spare time, you can't really go wrong.
Make sure you finish your projects, and do your best to be well-rounded. Personally I find tooling boring as hell, but you can't neglect areas like this.

If it's in the header it can cause linking issues

>tfw your 2500K is no longer felt to be modern

What Rust can do that other languages can't:
struct X {
y: Y
}
impl X {
fn y(&self) -> &Y { &self.y }
}

This defines an aggregate type containing a field y of type Y directly (not as a separate heap object). Then we define a getter method that returns the field by reference. Crucially, the Rust compiler will verify that all callers of the getter prevent the returned reference from outliving the X object. It compiles down to what you'd expect a C compiler to produce (pointer addition) with no space or time overhead.

As far as I know, no other remotely mainstream language can express this, for various reasons. C/C++ can't do it because the compiler does not perform the lifetime checks. (The C++ Core Guidelines lifetime checking proposal proposes such checks, but it's incomplete and hasn't received any updates for over a year.) Most other languages simply prevent you from giving away an interior reference, or require y to refer to a distinct heap object from the X.

This is my go-to example every time someone suggests that modern C++ is just as suitable for safe systems programming as Rust.

I know man. Can't believe my system is 5 years old already. It's getting time to upgrade.

To be honest, is it really worth it? Moore's law is dead.

Maybe just one more upgrade...

Nobody cares.

why does this work perfectly fine


void btnEvent_Click(object sender, EventArgs e)
{
if (((Button)sender).BackColor == Color.CadetBlue)
{
((Button)sender).BackColor = Color.Red;
}
//Console.WriteLine(((Button)sender).Text);
}


but this doesnt do anything?


void btnEvent_Click(object sender, EventArgs e)
{
if (((Button)sender).BackgroundImage == Properties.Resources.banana)
{
((Button)sender).BackgroundImage = Properties.Resources.apple;
}

}


i have both an apple.jpg and banana.jpg in the Resources folder and my buttons have banana images on them but they dont change to apples when clicked