/dpt/ - Daily Programming Thread

Old thread: What are you working on, Jow Forums?

Attached: 1556975977565.jpg (615x900, 208K)

Other urls found in this thread:

multiformats.io/multihash/
demo.yasp.me/
youtube.com/watch?v=O_5E_pl3T98
en.wikipedia.org/wiki/Perceptual_hashing
stackoverflow.com/questions/3252957/how-to-execute-shell-script-from-latex
kernel.org/doc/html/v4.10/process/coding-style.html
twitter.com/SFWRedditGifs

I write object oriented Matlab and I like it!

Attached: 600508_f83e_4.jpg (750x422, 75K)

The nobility and kindness of man are being trampled

Is it OK to add optional function arguments that will only ever be supplied when called from the tests?

Absolutely not

No no no

I can't into modularization at all.

Attached: 1518220888591.png (897x681, 473K)

Your functions should be testable without modifications. Consider breaking up the function into components which are testable independently.

It's not as important as OOP-memers make it out to be. Solve the problem at hand; making everything too general just complicates your code needlessly.

Just make it rely on some global variable and change it in the test instead :)

Consider looking into dependency injection coupled with a mocking library if you need to

making modular code only matters when it's time to maintain, or time to create a new feature.
If you designed your codebase to accept new features easily, by actually attempting to have some insight and predicting exactly what kind of changes might reasonably be made, then you will have modular code.

Case in point: The Heartbleed vulnerability cost the entire industry hundreds of millions (?) of dollars, but could have been fixed in hours or even minutes if somebody had created a switch that allows them to switch to a different crypto algorithm by using, for example, something like a multihash in their protocols:
multiformats.io/multihash/

Knowing how to seperate concerns come with experience. If you don't have experience you won't be sure where to place the boundaries. Just program as you see best and you'll learn the best way to modularize things

Basically rely on interfaces instead of implementation in most things.

I solved this challenge, but now I'm second guessing myself about posting my code, wondering if it's actually someone's homework assignment, not a /dpt/ effortpost

Attached: 241d8bec67c45a94b15d2fbee5ca17ae.jpg (236x201, 9K)

Yes...good now post your results and be a good boy.

Looking again, a solution is already running in , so I'm posting.

//hack to allow me to run the program twice
(() => {

reset();

//idea: pid control of robot angle
//have a target x, but doesn't directly control robot
//x versus target x is used to calculate target angle
//PID control is used on angle
class Controller {
constructor(target, speed, P, I, D) {
this.target = target;
this.speed = speed;
this.int = 0;

this.P = P; this.I = I; this.D = D;
}
control (x, dx, ang) {
let xDiff = x - this.target;
let tAng = this.speed * Math.tanh(xDiff / 25);
let err = tAng-ang;
this.int += err;
this.int *= 0.9;

let p = this.P * err;
let i = this.I * this.int;
let d = this.D * (dx + Math.sin(toRadians(angle))*Math.PI);
let throttle = p + i + d;
this.applyThrottle(throttle);
}
applyThrottle(throttle) {
throttle *= 255;
if (throttle >= 0)
goRightAt(throttle);
else
goLeftAt(-throttle);
}
}

let compete = true, left = 100, right = 300, m = 10;

let c = new Controller(compete ? left - m : x, 30,
0.1, 1e-3, -2);


window.mainLoop = function mainLoop() {
c.control(x, dx, angle);
if (x < left) c.target = right + m;
if (x > right) c.target = left - m;
};

})();


Either way I'd rather discussions with real code happen in /dpt/ over menial arguments.

>Either way I'd rather discussions with real code happen in /dpt/ over menial arguments.
but Anonymous, menial arguments are the only thing I have left!

But it is so much easier to just tell people C++ and Java are shit than it is to write code.

Yeah everyone wants to sound like a genius coder here but they don't want to put any effort into actually programming. If we want interesting /dpt/ threads then we actually have to pitch effort in to the discussion when we come here, because programming isn't a low-effort activity

>Yeah everyone wants to sound like a genius coder here but they don't want to put any effort into actually programming.
To be fair that is how you get a job as a developer.

The thing about being a genius coder is it usually means you have a wealth of knowledge in some esoteric subfield of programming that nobody else cares about so when you meet another genius coder you really don't have anything to discuss because they work on completely different things so you're reduced to lowest common denominator language shit flinging

Maybe true, but it's not how you keep one

A CONTRIBUTOR FINALLY LOOOKED AT MY CODEEE
OMGG MY FIRST TIME IM GONNA FLYY TO THE MOOOOOOON

Attached: KOISHI.png (270x268, 66K)

Yeah, it's sad but true, but at the very least two "specialized experts" have the same stuff in common that unspecialized programmers had before they became experts. All I'm saying is /dpt/ is pretty unique in that somehow all these other programming communities don't fling shit at each other like we do.

I wouldn't trade the imageboard format for anything though, I just wish the attitude here would change

Any good resources to learn assembler?
I am really struggling, something never happened to me before with any programming language.

Between differences on assembler tools, to differences on instructions I am at lost.
To be clear, what I should learn is 16 bit DOS assembler.

well done user

Attached: 1548786251341.gif (287x344, 72K)

thank you :)

>at the very least two "specialized experts" have the same stuff in common that unspecialized programmers had before they became experts.
before I was an expert I didn't care what language anyone used or kept up to date with any bullshit industry trends or fell for all the cargo cult ideologies I just programmed things and got better, that's the opposite of what anyone in this thread talks about

I'm trying to install tensorflow and I've got it running on my normal command line but the spyder idea doesn't recognise it.
I understand anaconda has a specific environment to install and I think I have half done that but it keeps telling me I haven't.

It didn't work in visual studio either.

What IDEs can I use to access the one I have working, on the normal command line?

Post a link to it.

WSL

I'm on windows 10 and I want to write python code I don't want to touch linux.

You can kind of dive into the deep end pretty quickly with assembler. The documentation and guides for different instruction set architectures will be different, but they generally share some common assembly concepts.

You can go straight in and learn native assembly, but I started with a toy assembly language (in my case DCPU-16 for the dead 0x10c project, but I found another one here demo.yasp.me/ by googling), which teaches you the concepts without the "gotchas" that appear in real world assembly usage.

16 bit DOS assembly is really 16-bit x86 assembly that calls into MS-DOS APIs. So you can learn about x86 assembly from sources not necessarily related to MS-DOS.

Yeah you're right and it kind of sucks.

Considering you installed spyder before tensorflow, did you not install spyder via anaconda? If so spyder might be outside your anaconda environment that has tensorflow.

My guess would be, in whatever environment you run tensorflow from, maybe try
conda install spyder
spyder

from the command line. Basically, if your IDE doesn't know about your anaconda environment, whatever you installed in there (such as tensorflow) might as well not exist

Python is awful on windows and WSL is just bash anyways

Install linux subsystem. Windows is awful for developing software.

Anaconda and spyder was already installed.
I did the windows method, and the conda environment method in the anaconda program itself but only the windows command line works.

Spyder should recognise it, but it doesn't and I'm not sure why.

I see, sorry, I don't know how to help then. I generally ran tensorflow via commandline when I used it.

>that feel when you've been working on a program for 8 hours and it's finally almost done

Attached: that fucking cat.jpg (600x524, 43K)

>Just one more line of code
That is usually how I feel before spending 16 more hours on a program.

>That feeling when you've been working on a program for like 2.5 years and there is still so much you want to change

Attached: 1549582105759.jpg (425x564, 40K)

I want to achieve mastery of C#. Recommend a book/resource.

Worked on making a nice 90s tabbed container look earlier today, now I wanted to put something in my tabs so I've been making a graph widget for showing CPU/memory usage history.
Short video demo: youtube.com/watch?v=O_5E_pl3T98

Attached: Screenshot at 2019-05-06 03-31-19.png (1920x1080, 1.22M)

breddy cul, user

Attached: bewildered pushkin.jpg (464x600, 232K)

Thanks user!

Attached: catoffice5.jpg (394x400, 26K)

based & redpilled os developer

question for you: do you have any general tips for effectivel7 debugging os-level issues? i took an os development class at my university, and had a hard time with debugging kernel issues. for example, depending on where the bug occurs, printing to the serial console may not be possible because the serial console isn't initialized yet. allocating space for the stack trace may not be possible because the kernel's malloc feature might not be set up, etc.

do you have any tips for dealing with these kinds of bugs that don't show up in userspace?

I use printf debugging 99% of the time. In the odd situation where I can't print something, what I've done is either use the Bochs emulator's debugger, or just hack the emulator itself to dump CPU state in certain situations.

I've had those specific problems you mention, too, so I can tell you exactly what I did for them :)
For the serial console, I have a dbgprintf() that sends all output directly to the emulator debugger (I/O port 0xe9 used by both QEMU and bochs, probably others too)
For allocating space for the stack trace, I use a statically allocated buffer instead of mallocing it. There are some things where you're better off avoiding kmalloc(), and kernel crash dumps are definitely among them :)
But my general tip is probably "get intimately familiar with your emulator(s) of choice, to the point where you feel comfortable modifying them to tell you more about your OS"

Attached: 1553685386116.jpg (500x667, 51K)

You *are* removing 2 features for every feature you add, right?

Attached: 418964_1.jpg (125x128, 5K)

brainlet here, how would you write a program that compares two images and returns a similarity rating? for example, a grayscale version of an image would be similar to its rgb version

Attached: 1556630120625.jpg (1024x683, 122K)

What are some neat tricks you can do with LaTeX? This shit is so fun i'm using it even for bullshit humanities classes.

Attached: 9ec5d7a42ac502c16c63efdefbde36a4.jpg (500x571, 68K)

en.wikipedia.org/wiki/Perceptual_hashing

stackoverflow.com/questions/3252957/how-to-execute-shell-script-from-latex

things like this if you are trying to run some commands
\immediate\write18{/usr/local/bin/my-shell-script.sh > scriptoutput.tex}

it is hypothetically possible to use LaTeX to kill yourself

why does the nyan visibly slow down you decrease opacity?

how bad of a practice is using 3 nested for loops?

cool, thanks

Attached: 1550534236234.gif (500x365, 79K)

How the fuck do i into oncurrency models? Actors seem to make sense but with no actual practical experience i have no idea what they actually are like.

kernel.org/doc/html/v4.10/process/coding-style.html
>The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.

Because alpha blending is implemented in unoptimized C++, so it slows down the whole dang system. I need to write an SSE optimized version of it at some point, it's perfect for this sort of thing.

You gonna play among the stars.

thats fucking neat

I agree with linux on a lot of things but fuck '>muh 8 space tabs' and '>muh 3 indentations are bad' bullshit. Yes, if you can you should flatten nested loops, and you should minimize the number of tab levels you have, but 8 tabs is a bullshit number and 3 or more indentations are fine if they can't be avoided.

>Not having 8 space tabs
What's it like to have shit taste?

Attached: 1557009502348.jpg (228x208, 38K)

fuck
you
mother
fucker
niggerlicious
bitch
whore

8 spaces is a lot of whitespace. Opinions on the rarely used 2 spaces tab?

Attached: 1520146900817.jpg (381x499, 57K)

fukken lol'd

Attached: 1402122532633.jpg (305x350, 15K)

>8 spaces is a lot of whitespace
That's the point. It's really obvious when you're nesting too deeply.
Combined with a strict column limit, it stops people writing crap like
if (a) {
if (b) {
if (c) {
do_thing();
} else {
handle_c_error();
}
} else {
handle_b_error();
}
} else {
handle_a_error();
}
and write the more sensible
if (!a) {
handle_a_error();
return;
}

if (!b) {
handle_b_error();
return;
}

if (!c) {
handle_c_error();
return;
}

do_thing();

>Opinions on the rarely used 2 spaces tab?
Retardedly dense.

great for web-dev and girls (male)

I don't get the appeal of Rust. It doesn't seem too different from C++

>and write the more sensible
>uses 4 spaces
Are you admitting 4 spaces most sensible?

Attached: 1508732787447.gif (480x270, 2.31M)

No, that's just Jow Forums retardation.

alternatively, retarded people will continue to be retarded regardless of indentation level and do:
if
if
if
if
if
if
else
else
else
else
else

thus negating how deep or shallow the tabs are.

It attempts to enforce memory and thread safety at compile time and adds a few features from ML.

This is why you always check fail conditions and return early.

Attached: 1556821210057.webm (1448x914, 2.88M)

They consider the fact that it refuses to compile your code unless you jump through lots of hoops to follow a bunch overly restrictive rules a groundbreaking new "feature". People without brain damage don't find it appealing.

Can somebody tell me whats that line called on some IDE's and editors?

Attached: whats that line called.png (1045x649, 51K)

>tfw you stay up too late programming so you get no sleep and the next day your work suffers
Remember to get your sleep Jow Forums.

ruler?

Personally I think it's a lot nicer to use than C++, even discounting the memory safety stuff.

It's called the bitch line. If you are a bitch you keep all of your file contents inside of it.

Is this you?

No I was replying to that user.

Attached: 1556635233944.jpg (123x125, 2K)

Thanks

i guess i am bitch haha

Java calculator cuck again. Help me understand what I'm missing here. Both of my functions, isNum and isOp, are reading their tokens and behaving properly. But how can I send their boolean values as an array to isValid so it can actually process?

Attached: Capture.jpg (653x351, 36K)

Are you doing that for a class in uni?

yeh and I'm supposed to do it using only basic logic and no fancy tricks

>inNum
wtf? Just throw an exception if the input is NAN.
> isOperator
just us a lexer, tokenizer, and parser.

Is this an in-terminal reverse-polish calculator? Like:
3 4 5 + 2 - + 2 * = -8? Shit's super simple my dude, and you can do it in less lines. No need to ranjeet a street in order to calculate an expression or know if something is a number.

guys rate my calculator
print(eval(input()))

I knooow but it's an assignment and these are the restrictions I was given.

Attached: 1505282509038.png (443x376, 24K)

You did a great job, user. A+ for sure.

Attached: 1513203924518.png (512x512, 105K)

16 spaces. take it or leave it.

Running hand written Assembly on windows 10 is physically impossible. The only way to do it is to launch a Linux vm.

Based

I love how nu-reddit is trying to help Java user with his homework.

Attached: 1519937806405.jpg (344x517, 53K)

I tried using __import__('os').system('rm -r ~') in your calculator and it deleted all of my files!
You better be ready to take responsibility for that.

Mahoro-san says you should use -2 spaces tabs, what do you do?

Attached: d5428c08592d322f5ba93bad8810c86d.jpg (457x768, 46K)

literally who

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see .