/dpt/

Previous thread: What are you guys working on?

Other urls found in this thread:

developers.google.com/edu/python/
youtube.com/watch?v=R7EEoWg6Ekk
stackoverflow.com/dev-survey/start/?utm_source=reddit&utm_medium=social&utm_campaign=dev-survey-2018-collection
primesieve.org/segmented_sieve.html
twitter.com/SFWRedditImages

c++ is the greatest language of all time

this
people who can't handle C++ are brainlets

learn both.
developers.google.com/edu/python/

any experienced programmers or software engineers here?

Give this guy advice:

Here's some advice, Brazilians shouldn't exist at all

C#
Stable release
7.2[2]/ November15, 2017; 51 days ago

F#
Stable release
4.1[1]/ March8, 2017; 9 months ago

Is F# kill?

Are macros just too complicated for the average brainlet programmer?

what's a macro lad

They're like functions for Word and Excel you write in Visual Basic

No

anything beyond Hello World is too complicated for the average brainlet programmer
95% of "programmers" are completely worthless and unemployable

Oh, are those too complicated for brainlet programmers?

I am trying to make a plugin (qt) that include a ros component in cmake/c++.
I build it using the add_library(MODULE) and it compiles fine.
When I remove the ros parts, it loads fine too.
But when I add the ros parts, I get undefined function.
nm also lists these functions under U, but so is a lot of other stuff that seems to work fine.

1. Does anyone know what is wrong?
2. Does anyone know a method which will troubleshoot me towards this?
I don't know to debug this.
I will try removing the qt parts now and see but I really don't want to use a different IPC to connect the parts.
Eg ros -> ros/zmq -> zmq/qt.
That would just be bad.

Don't be so harsh on yourself.

>op pic about long compilation times
>first post about c++
pottery

Should you initialize fields at the top of the class where they're declared, or in the constructor? C#, if that matters. It just looks weird to me using 'new' outside of a method, but initializing everything in the constructor kind of clutters it for stuff that actually has to be initialized in the constructor.

what can i do about anal leakage? i thought i would get fiber from granola but it just seems to give me gas

>Should you initialize fields at the top of the class where they're declared
Shouldn't even be possible

>how to into build systems
>how to not abuse templates

? Something like

public class MyClass
{
public List myList = new List();
}


works just fine.

Just put a cork in it. Or alternatively seal the leak up with rubber cement.

Threadly reminder that type theory is a cult.

> tfw pic related

do experienced programmers still have to deal with this shit?

no

Now that the dust has settled, what makes more sense: a dedicated boolean type, or a bool alias over 0 and 1? The latter is really useful for avoiding branching. It's surprising how much you can express in arithmetic.

There are no types, only data.

How does the latter help avoid branching?

is this all you really need for a (practical) small instruction set?
I've written something like this before but it was a long time ago

>inb4 binary literals are a gcc extension
good thing I'm using gcc then

Probably a stupid question, but you know how Visual Studio automatically adds closing quotes/parenthesis/brackets/etc... for you? After you're typing whatever goes between them, is there a quick way to move the cursor to the right of all the automatically added stuff? It seems like there should be a hotkey that does that.

yeah, it's called clicking with your mouse

You can reduce those first few instructions to just conditionally execute the next instruction, and unconditional jump. Might make your VM a bit faster too.

The one two instructions that are needed to be Turing complete are load and add

>having to use your mouse to type

You can get by with only mov
youtube.com/watch?v=R7EEoWg6Ekk

how else are you going to move the cursor, the arrow keys?

wasd

which instructions do you mean?
call and ret handle stack frames so I'd rather not get rid of them even though they're not technically crucial

actually it occurs to me than EQ and NEQ don't need different versions for each type, oops
it was a bit of a mindless copy paste job

>(practical)

end?

>code strafing

Takes you all the way to the end of the line which isn't always what you want. Also not really convenient to reach for unless you have a really long right pinky.

Real programmers write code on their guitar hero guitar.

>Takes you all the way to the end of the line which isn't always what you want.
skip word by word or something or just use the mouse
>Also not really convenient to reach for unless you have a really long right pinky.
get a better keyboard that has it within reach and so you don't have to reach as far for the mouse

I'm using a Model M. Keyboards don't get better than that.

I hope you guys have taken the Stack Overflow survey because I don't want the media to tell me the typical programmer is a lesbian gender-queer JS kid: stackoverflow.com/dev-survey/start/?utm_source=reddit&utm_medium=social&utm_campaign=dev-survey-2018-collection

lol sure enjoy being stuck in the 80s meanwhile people can press end and use the mouse. switch to a terminal editor like vim/emacs which are better suited for retard-sized vintage keyboard use without the mouse

Just have casting?

just use branching you fucking retard
the compiler can use arithmetic where it makes sense anyway

CTRL + ->
?

Most editors which do that allow you to type the matching rune and it won't double on you, instead it will go to the right.

Threadly reminder to ignore obvious type system false-flaggers.

dumb frogposter
by deleting everything on the write and typing it back in on the left like a fucking warp drive

Hey my reddit frens,

couple of days ago I went back to project euler. Solved a few more problems, but still got pic related open. And I can't really wrap my head around it. How would you solve this? Or atleast approach it?

>ctrl+a
>delete
>ctrl+v
>it just werkz

I'm tasked with making a small web server program, but the unfortunate catch is that I have to use OOP to do it, specifically, I have to use a factory method/object pattern at least once.

How about this: the server recieves a request (get, post, etc...), I pass it to some method or class, and it returns a different type of handler depending on the type of request? Is that a good use of the factory patterns?

>is this all you really need for a (practical) small instruction set?
If you're writing babby's first VM, you can just use doubles and get rid of most of that cruft. Also, you might need multiple variations of the load/store instructions if you have registers.

Looks like a problem with search space small enough to try to brute force.
If that's not enough, fuck around with those numbers and try to find a pattern that'd save you some checks.

binary literals are standard as of C++14

irrevocably

>Looks like a problem with search space small enough to try to brute force.
But what would be my upper limit for those primes? And how many replaceable digits are reasonable?

The factory pattern means you can construct the class with some options that generates all the options you need.

>sepples

as close to a single place as possible
i.e. if you know their value at compile time, do it in the class
similarly, if you do validation, do it as close to a single place (setter instead of ctor) as possible
otherwise if you need to expand to multiple ctors, you may need to duplicate code, which is obviously retarded

not when they're not using ancient languages with the one billion dollar mistake

>a dedicated boolean type, or a bool alias over 0 and 1
the first, implemented by the compiler as the second
ffs programmers should not be forced to do the compiler's job, only adds more possibilities for bugs

Just checking my solution for it, here is a rough overview of what I did. It was a while ago though so I'm a bit vague on my thought process.

- sieve over all primes
- for each prime, associate each digit (0-9 in an array) with the position it occurred in the prime (excluding the last, since this can't really change)
- for each position set, construct subsets with a wildcard value that can be anything (i.e. 10)
- for all subsets generated by this prime, check if the subset has been seen previously (use a hashmap), and if so, update the hashmap entry with the new subset
- once we have a hashmap entry with the specified amount required, iterate over and bruteforce the wildcard values with values until all are found (only need to find 8 or so so really quick)

so in summary, bottom up approach generating a mapping from primes -> subsets and then counting common subsets as they are generated

to clarify, subsets look like the following

input prime: 56003

[5, 6, 0, 0, 3]
[*, 6, 0, 0, 3]
[5, *, 0, 0, 3]
[5, *, *, 0, 3]
...


you can discard some sets which are obviously non-prime using some number theory arguments too, but it isn't essential

>?utm_source=reddit&utm_medium=social&utm_campaign=dev-survey-2018-collection
gb2>>>plebbit

I feel like Google helped perpetuate this meme. Everything they write takes years to compile.

I'd sieve up to 10^n and then check all options up to 10^n, extend the sieve and repeat. More replaceable digits actually mean less possibilities here so they're fast to check. Checking numbers where you replace only 1 or digits is going to eat most of your time, so I wouldn't worry about the 6 or more digit replacements and just check them to be sure.

works fine on their machines I suppose

If you need an upper limit and don't have a segmented sieve implementation (look into one or implement one, they are great), using an upper bound of 1 milliion is sufficient.

>But what would be my upper limit for those primes?
infinity
your program may or may not halt, but I assume the problem has a solution
print the number every N iterations, so you know when to Ctrl+C the bitch and go back to the drawing board
>And how many replaceable digits are reasonable?
as little/many as allowed by the problem statement
autism: current problem statement allows all digits to be replaced (if "some" does not exclude "all"), so you can just answer with the first 8 primes with equal digit count

Underrated.


what is vim?

That's actually kind of amazing. It's giving me a gimmicky cryptocurrency idea.

Well yeah that's what I thought.
I might choose thihs approach then.
Have a sieve ready to go and would just sieve to like a million, check every possible replacements of digits with n > 2 (prolly) and if solution is not found then increase upper limit

thanks for the insights, i'll try it!

The problem is stated in a weird way but the replaced digits are supposed to be equal so you can't just autism your way out of this.
Replacing all digits in a 3 digit number would give you 111, 222, 333, 444, etc. so you can have at most 5 primes this way. In that case there's no point to even check. In fact, you can skip every replacement that replaces first digit using this idea. Not much, but it can help a little.

>first digit
fucked it up, meant last digit

this guy is up to something
you should be able to do it as you go, without an upper limit, and just break once you've found your result
you just need to think of the primes as an infinite stream, whether that's explicitly stated in the code or not

>so you can have at most 5 primes this way
ah, even numbers, good catch
>In fact, you can skip every replacement that replaces first digit using this idea. Not much, but it can help a little.
yep, very good point

Turns out the solution is just the tab key. Can't believe I never tried that before.

good to know, cheers

You can also use ctrl+shift+enter to automatically open a new line under your current line without having to have the cursor at the end.

the compiler won't catch all cases, soyboys
if you want something done right you have to do it manually

>primes as an infinite stream
e.g. FP wankery:
def sieve(s: Stream[Int]): Stream[Int] =
s.head #:: sieve(s.tail filter(_ % s.head != 0))

val primes = sieve(Stream.from(2))

def solve(n: Int) = {
// state goes here
for (p

>the compiler won't catch all issues
>why have the compiler do any checking at all, I'll just be the compiler even in the cases where it can save me from bugs or tedium
t. pragmatic software engineer

it's unlikely that the crap you write consistently beats the compiler
all you need is a proper boolean type which is strictly 1 or 0 and use common sense when writing the code

The compiler will catch more cases than the typical programmer. If you don't have extensive knowledge about the specific architecture you're compiling to you probably can't optimize branches better than gcc.
Obviously there are some specific edge cases the compiler will get lost in but they're rare in actual, practical code.

found more soyboys. stick to your high level CoC langs

post an example

>hurrr compiler know more than me
soyboy

wek b80

this is likely suitable for small purposes and is simple which is nice

if you want the fastest possible though, use a segmented sieve. it keeps memory fairly bounded and will also typically be quicker than a traditional eratosthenes sieve due to better cache management. the only issue with this is it only saves a segment at a time, so for linear iteration its perfect, but you will want a full sieve for repeated querying

primesieve.org/segmented_sieve.html

Show me an example where your "optimizations" beat compiler generated assembly consistently.
Something longer than 2 lines of code please, implement a quicksort, for example.

(You)

This is really nice and suprisingly efficient, I like it.

Reminder to ignore false-flagging Rust shills.

>this is likely suitable for small purposes and is simple which is nice
as is tradition for most "the power of FP!" examples :^)

cheers m8, all good points, quality contribution (no sarcasm)
will give it a skim
>This implementation generates the primes below 10^9 in just 0.9 seconds (single-threaded)
wonder how fast the elegant-yet-slow implementation is

pareto analysis'ing the bitch, a viable strat may be:
- write solution with trivial to implement sieve, start running it (program A)
- start swapping out the simple sieve with a segmented one (program B)
- if program A gives a correct result before you can run program B, job's done. Still worth implementing program B for pedagogical purposes
- if not, start program B
- etc etc, profit

>soyboy
reddit meme peddled by pjw-types

>suprisingly efficient
ehh
and I'm the guy who copy-pasta'd it from the first "scala prime sieve stream" jewgle result
is efficient from the dev time's POV, not sure about the runtime. Stream obj overhead, see also , which makes sense for bigger use cases