/dpt/ - daily programming thread

"Real Programmers Use UNIX®" Edition

Old (warning! frogpost):

Other urls found in this thread:

zverovich.net/2016/05/13/giving-up-on-julia.html
danluu.com/julialang/
hackage.haskell.org/package/base-4.9.0.0/docs/Control-Exception.html
youtube.com/watch?v=wfMtDGfHWpA
cc.gatech.edu/~turk/math_gr.html
twitter.com/AnonBabble

FIRST FOR C++ A BEST LAGOOGOge

no~~~~ u can't! ;A;

MOOOOODS

That's a fat cock

why is haskell so based

Because it's so pure.

lisp just can't compete, horrendous syntax

Anyone using Julia here? Looks pretty neat, clean, I love the style and the potential.

>implying

zverovich.net/2016/05/13/giving-up-on-julia.html
danluu.com/julialang/

python is slow af. Doesnt make it a bad language. Julia has a better syntax, can import C directly, isn't made by "pythonistic hipsters"

What would be a good casing to make night vision goggles with a raspberry pi and a NOIR camera, lads?

EE here. I'm really new to programming and at them moment I'm doing shit on a Z8.
Anyway, I have this piece of code:
a = ax_curser;
while(a >= 0x02)
{
a;
b++;
}


ax_curser is a single bit that is moved left and right (can be values 0x01, 0x02, 0x04 etc up to 0x10). I want to find out how many times is has been moved relative to the first position (0x01). For some reason, variable 'a' gets stuck at 0x02 and won't bitshift right to 0x01, so it gets stuck in the while loop.

Sorry if it's an obvious problem and thanks for any advice.

You have a typo, a should be a>>=1
It happens to everyone...

>>=

Oh, of course. Cheers mates.

New at haskell, what is the best way of excluding conditions? In this function:
time12 h m =
let hour = h `mod` 12
ampm = if h > 12 then "pm" else "am"
in show hour ++ ":" ++ show m ++ ampm

How would be the best way to show a message then return if the input is invalid, i.e. hours or minutes isn't a sane value.

I thought you could use a guard but i'm not sure how to follow with the whole function after that, or maybe a where? Not sure

Just tried Visual Studio Code. Holy shit that thing is cancerous. Back to vim.

i dont understand. anyone get this?

i know this works: but when comparing signed with unsigned as in , do they get converted to signed or unsigned? and indeed with the right compiler setting it should give a warning

1.5 im talking about and sorry phone flipped to side

I broke my laptop while trying to look at your picture. Fuck you.

...

thanks for the good laugh. Its natural selection

pics please

...

This seems to work fine dunno if the best way but it seems simple enough, could probably do it in one line but I think 2 functions is a bit clearer

time12 h m =
if not (validh h && validm m) then "Invalid input" else

let hour = h `mod` 12
ampm = if h > 12 then "pm" else "am"
in show hour ++ ":" ++ show m ++ ampm

validh h = (h >= 0 && h < 24)

validm m = (m >= 0 && m < 60)

>making scripts for an API that has 0 documentation
>have to rely solely on what the method names are called and guess what it does

Why the fuck do developers release undocumented API's to users? Do they expect everyone to just figure their shit out though painful trial & error?(code monkeying until shit works)

Hell I comment things I make even if I have no intention of releasing it. It's just good habit.

Do you use a custom keymap? If not why?

they're amateur neckbeards

While I don't know Haskell that well, why are you writing it in that style?
It's like you're trying to write procedural code.

I don't know how to do functional, what's wrong with it?

It's defeating the entire point of Haskell.

Why are you doing input validation inside of that function? That returns a String. You want the function to take a String and return a String and that's it. If you want to referee user input do that elsewhere in the actual IO code.

I was just messing around with the interpreter so you can't do that I don't think but you are right that is a more sensible way to do it I was just trying to find out how let works

Why would I? It would just make things painful when using any other computer.

Documentation is a meme.

Even an amateur biker would choose the bike that suits him best.

default keymap suits me best

where is your god now?

That's the most unfit analogy I've ever heard.
I don't know about you, but my custom bike isn't an international standard, and I don't have to use stranger's bikes at my job.

thank you

>that semen stain

Just remember that if its type is "String", the only thing that function can consist of is expressions which result in a "String", so unless you want to return some String like "Invalid input" (which would be silly obviously) you just don't do that. What you could do in such a case, however, is something like:

time12 h m
| h < 1 || h > 24 || m < 0 || m > 60 = "Invalid input, bud."
| otherwise = concat [hour, ":", min, amPm]
where hour = show $ h `mod` 12
min = if m < 10 then '0' : show m else show m
amPm = if h < 12 then "am" else "pm"


if you want to use a guard.

why not use exceptions?

Thanks, that looks a lot better. Does the $ before h `mod` 12 tell show to include all of that, rather than just h?
Exceptions are for when something you can't really recover from happen, rather than just an invalid input, is my thinking.

Exceptions are for IO code. hackage.haskell.org/package/base-4.9.0.0/docs/Control-Exception.html

The $ is an operator that just does function application. It's to make it more convenient to write expressions without a fuckton of parentheses.

show $ h `mod`12 == show (h `mod` 12)

div 3 0 is an invalid input yet it throws.
In this case I'd use a Maybe instead tho.
>In addition to exceptions thrown by IO operations, exceptions may be thrown by pure code
Example:
Prelude> let f x = if x /= 0 then x else error "oops"
Prelude> f 9
9
Prelude> f 0
*** Exception: oops
Prelude>

Yeah, the error function works from anywhere, but if it's outside of IO then you generally only use that for stubs or for a small handful of fuckups that you can't recover from, like using "head" on an empty list.

thanks for the help guys, i looked up the answer and the difference is that

applicative order is post-order, so (test 0 (p)) infinitely calls itself when p is evaluated since p calls itself

whereas in normal order values are expanded with what they stand for until its' maximally expanded, and then reduced to a single solution so, (test 0 (p)) is replaced with the value of test given the arguments 0 (p) so (if (= 0 0) 0 p) so 0

Is double inheritance a really bad thing to use?

I'm in the situation where it's elegant to use it, ie
class Z : public X, public Y {
public:
Z();
~Z();
void Xvirtual();
void Yvirtual();
};

But I'm thinking another solution would be
Class Z : public X {
public:
class ZY : public Y {
public:
ZY();
~ZY();
void Yvirtual();
};
ZY* y;
Z();
~Z();
void Xvirtual();
};


Which one is better?

>Is double inheritance a really bad thing to use?
No

Any inheritance is usually a bad idea.

why would it be a bad thing? my school's beat me over the head with java and i'm just now teaching myself functional language bc i dont want to be a pleb anymore so redpill me

I give up, anyone know how I can sort these files into human readable order with Java?

1.jpg
10.jpg
11.jpg
12.jpg
13.jpg
14.jpg
15.jpg
16.jpg
17.jpg
18.jpg
19.jpg
2.jpg
20.jpg
21.jpg
22.jpg
23.jpg
24.jpg
25.jpg
26.jpg
3.jpg
4.jpg
5.jpg
6.jpg
7.jpg
8.jpg
9.jpg

I was originally using just Arrays.Sort(), but then I found out about a natural order comparator which I've been using yet still these files and others alike fail to sort into alphanumerical order, I'm completely out of ideas at this point.

check if it has only 1 digit in the filename before .jpg and if so change the name to have a 0 before it

Mixing interfaces is one thing. Mixing inheritance... doesn't feel right.

Write your own sort, add padding, or something

or create an array and put them into the location of the number if their filename in the array

Convert file name without suffix to integer and sort on that instead.

When comparing, compare lengths, then if the lengths are equal compare their alphanumerical order.

Why not use composition? IS there a valid reason to make Class Z a X and a Y versus making X and / or Y members of Z?

Typically OOP prefers composition over inheritance unless there is a direct reason to use inheritance.

make a system call and cat them with a pipe to sort -h

cat ... | sort -h

/dpt/-chan, dai suki~

Ask your much beloved programming literate anything (IAMA)

Multiple inheritance is a fair alternative to interfaces (more powerful but more messy)

>why would it be a bad thing?
Diamond

Sauce ?

"avoid success at all costs"

>Be self taught programmer
>Mediocre at best but good enough to do my job
>Friends went to study CS in the university
>Meet up after 4 years
>One of them starts telling us about quantum computing and how it will affect the languages of the future
>Everyone but me struggles a bit but nods along
>I get maybe 10% of what has been said but know enough to realize the incredible utility of the concepts illustrated
>Realize I won't be able to be a programmer in 10 years because the bare minimum skill floor is going to skyrocket
I..it's not like I wanted to be a wizard or anything..

in ten years quantum computing will still be irrelevant

Most CS majors have a popsci level of understanding of quantum computing. They just can't into math.

sort -n
not -h

Everyone else nodding along was probably thinking the exact same thing.

Dat guy is a fake. Quantum computing is very far from replacing daily computing, it's only useful for a very minor set of problems and still today the technology is barely usable (how many quantum computers in the world ? what's their computing power (flops) ?)

I imagine it will be useful just for things like generating high quality random numbers if nothing else. Plus as far as I understood there are a few relatively common calculations you can do quicker with a quantum computer. I know you will be able to do these things via library functions but then you can't make your own when doing so would make sense and you've pretty much relegated yourself to being a code monkey.

they seem to both do the same thing without suffixes though

but yes I guess

This guy explains it rather well for a quick video.

youtube.com/watch?v=wfMtDGfHWpA

Anyone know of any good books for learning...

[sigh's deeply]

...Java?

Also, the only usable quantum computer (D-Wave) is being programmed in ... python !

-h will interpret M and G as size suffix.

This picture made me unreasonably happy. I must be turning into a woman.

It's a real time physics engine. Using composition would require me to use dynamic_cast to identify objects rather than a cast to a mutual base class.

Bjarne BTFO

Risk of ambiguity

the internet

try to program something

when you have a question, google it

it should be avoided at all costs, it's disgusting and never necessary

what kind of math do I need to know to make games?

I've been trying to write an HTTP server in C#, everything seems to work except loading the default document for a browser to render

What kind of game?

Anywhere from simple boolean algebra to linalg to calculus to statistics

geometry
trigonometry
elementary algebra
linear algebra
calculus
newtonian physics

You have a "warning" at line 16. Fix it.

>making a video tagger to tag my "video collection"

Not sure if this is productive or tragic.

So, there's zero good books for Java? Nothing akin to "Javascript: the good parts"?

Really sounds like you've already locked yourself into a design. In the future I'd really look into starting from the onset without a modular approach.

Physics is typically a bunch of properties acting on a set of a data. Honestly, it's better represented as a base set of properties (Position, Velocity, Mass, etc) with a set of functions interacting on them.

>no diffy eq
>no fourier
>no diffy geometry

with a modular approach* Damn auto correct.

Do not that fall under calculus and linear algebra?

>diffy eq
for planets and shit or what do you have in mind?
>fourier
for what purpose
>diffy geometry
explain

That's what I'm thinking as well.

Middle school tier math.
Retards may say you need linear algebra but the mathematics of projection and matrices in 3D environments are all written on some old chalkboard and everyone's been copying it from there ever since.

Kill yourselves.

I know, it mostly complains about a deprecated method of specifying a port number, it works for opening a port nonetheless.

Not usually

you're making a physics engine and you think you only need middle school math? you're delusional

>Retards may say you need linear algebra but the mathematics of projection and matrices in 3D environments are all written on some old chalkboard and everyone's been copying it from there ever since.
just because you don't understand it, doesn't mean others don't understand it, retard

So you're not annoyed by a warning or an error in your code? Fix it.

cc.gatech.edu/~turk/math_gr.html

>Kill yourselves.
fuck you user I said anything from the simple to the more complex

if you are able to read about matrices and apply the maths then you clearly know at least a bit about the mathematics in question

nobody said you had to have a PhD in mathematics.