/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Old thread:

Attached: 2jge7urriikz.png (407x921, 274K)

Other urls found in this thread:

github.com/Constellation-Labs/constellation
axiomsofchoice.org/
twitter.com/SFWRedditVideos

My wife, Nene, is so cute

Idris is a good language

repostin:
>have a job interview
>I could be working in a Fortran/MATLAB + industrial testing envirnoment
>they have one major senior programmer
>guy interviewing me (not the senior dev) had the last class at his college to take Fortran
>he was graying
Good thing I'm lower level I guess

inb4 100 posts asking for help with C basics

This poster is Steve Klabnik. He shills Rust.

How does it feel to know you will never be on my level pic related

Attached: jelly.jpg (1024x576, 62K)

Pro tip: you can summon Steve Klabnik by criticizing Rust or communism.

IT is not your "wife".
IT is not "cute".
YOU are braindead.

Us programmers, huh?

I finally got to start my 4 week summer vacation from a full stack IoT memejob and have so many ideas piled up I don't even know where to start.
Should I just watch the anime related to OP's pic to seek inspiration?

>i++
UNTERMINATED STATEMENT REEEEEEEEEEEE

Attached: 1332291274492.png (487x600, 250K)

I'm not Steve Klabnik. I don't even use Rust.

She IS his wife
but I agree she isn't cute

Ok I fixed that and made it read like psuedocode, among a few other tweaks, but I'm still not sure how to fix my O(n) complexity, and am only vaguely sure what that is. I'm pretty sure it's something about the nested loops making it fucktouple in runtime with every digit but that's all and I don't see any way to avoid that.
Thank you for being very patient with me anons.

Attached: Untitled.png (720x480, 29K)

fun fact - I did this myself in college I don't remember it. Just woke up like that

I'm working through Automate the Boring Stuff with Python. It's so fun. Already up to Chapter 7.

Why is Robert C. Martin "Uncle Bob" so popular? He's a complete idiot.

There are two types of programming language: functional and dysfunctional.

>i++
not ++i
Do you also bring the first piece of used toilet paper to throw it in the kitchen after wiping your ass?

>4
normal programmers, who don't give a shit
>3
first group of drooling idiots who think recursion or anonymous function have anything to do with functional programming
>2
group of clowns who think lisp is functional and you should use immutable data structures and higher order functions just
because they are "functional programming"
>1
the real functional masturbators who only use languages with dependent types and that do not allow IO

he's not popular though

>normal programmers, who don't give a shit
Sounds about right, given the abysmal quality of most code.

My former and current coworkers see him as a God. Clean Code is their bible.

He's everywhere at once because his concurrency is F E A R L E S S.

Post yfw your manager demands that you add a unit test for a singly inhabited type

Sir I am just a cashier.

Attached: 1292005890960.png (289x189, 70K)

all_sites
.into_par_iter()
.for_each(|site| site.shill(Language::Rust))

It's not up to the manager to decide that. His/her/xer/zer only concern is that people do their job.

i want to nakadashi nenecchi

Can some nigga tell me what are unit tests and why should I care in a way a fucking retard would understand?

bonus points if you tell how to properly do tests in an application that creates and manipulates data write/read

id : forall a. a -> a
>needs a more descriptive name, what about "returnInput"?
>needs some unit tests
>too generic, its purpose is unclear

If only, user. If only.

Unit tests are a means of working around programming language deficiencies.

i++ is an expression not a statement
completely incomparable

that explains pretty much nothing

Learning React via Udemy.com
Maximilian Schwarzmüller's videos are pretty detailed and recommended (IMO)

Am learning it because of an internship I finished a few weeks ago where I created an Angular application and because people mentioned Redux and NgRx Store I thought I'd try learn it, so I know what the hell Redux is and what it does.

#include
#include

int main( int argc, char **argv ){
FILE *fp = fopen( argv[1], "r" );
int c;
int i = 0;
char buf[5];
int nums[80];
while( (c = fgetc( fp )) != EOF ){
ungetc( c, fp );
fgets( buf, 5, fp );
nums[i++] = atoi( buf );
}
fclose( fp );
printf( "%033[2J" );
for( int j = 0; j < i; j++ ){
printf( "%033[s" );
for( int k = 40; k > nums[j]; k-- ){
printf( "%033[B" );
}
printf( "*" );
printf( "%033[u" );
}
fflush( stdout );
return 0;
}


wrote this program to plot data points in the terminal, only to find that Cygwin doesn't support ANSI escape sequences.

Should I try installing Linux already? I dunno, I don't feel like backing up and repartitioning my hard drive right now, and probably won't any time soon.

>Can some nigga tell me what are unit tests and why should I care in a way a fucking retard would understand?
I guess you normally test code by printing its result to the terminal, right? Imagine automating that process.
>bonus points if you tell how to properly do tests in an application that creates and manipulates data write/read
You don't. You isolate the read and write operations and only test the actual logic.

(nice get)
I'm a bit of a brainlet, i tried your method and experimented a bit but nothing printed in console. even when print was explicitly stated in the python script. WTF is going on here?

Programming on Windows is generally a miserable endeavor in my experience.

which class is this a method of

not him but why unit test when u can just valgrind

Unit tests is code that checks that your code does what you think it does. Usually via a framework like xUnit. This framework is then used to create and run said unit tests.

If you have a function or method that (for example) calculates the square root of n, you may want to check what happens when you put in: 1, 0, -1, 0.1, really large numbers, etc.

Now such a function is already well understood in general, but what if you create a function that either does something or calculates something that's pretty much not well understood? You may want to create unit tests to basically prove that that function does what you claim/think it does.

>I guess you normally test code by printing its result to the terminal, right? Imagine automating that process.
So basically check if sections of code work?
let's say if I have a function that converts X from Y to integer, I'd test it like

convert('INVALID', Type::INT); //exception
convert('25', Type::INT) === 25


like that?

>You don't. You isolate the read and write operations and only test the actual logic.
I work with PHP and I'm writing a CMS, lots of the functionality depends on interactions between items already in the database, like categories, uploaded files, etc etc.
I'd like to test that as well, but is there a simple way to do it?

based Steve

okay, I get it, thanks kind user

>>not him but why unit test when u can just valgrind
Because of side effects? If you run your code only once to debug, the next time you run it, the values may be different and you DON'T want to debug several times. Just write unit tests and run those.

That's the gist of it.

>unit tests
>prove
Good luck doing that with most functions

Yeah, I'll admit that's just theory. In practice, unit testing can be bitch.

>sepples is too stupid to understand that 1f is the same as 1.0f
why?? who takes this garbage language serious?

Wait a minute, I know what I did wrong now. I used percents instead of backslashes. I haven't used ANSI escape sequences in so long, I forgot how.

Use a vm

Good luck proving that a function with an infinite input space is correct with unit tests.

It's not O(n) if n is fixed...

>brainlet has never heard of significant figures

Things you could do instead:
>download a command prompt replacement with full support for ANSI escape sequences
>turn on ENABLE_VIRTUAL_TERMINAL_PROCESSING and then you can just use the command prompt because it will have partial support for ANSI escape sequences after that
>virtualize Linux in Windows
>use WSL, in conjunction with one of the many X implementations available for Windows, to run the Linux terminal of your choice on Windows without virtualization
>use a live Linux USB to test your code
>use a live Linux USB to safely shrink your Windows partition, and then install Linux on the freed space

Then just pick the edge cases, show it generally works and put a documentation note in the code.

Exactly. You write a test for each path in the section. Take this code for instance:
public boolean isEven(int i) {
if (i % 2 == 0) {
return true;
}
return false;
}

There are two paths: the if statement and the last line in the method. So we should write two tests like so:
assertTrue(isEven(2));
assertFalse(isEven(1));

That's it basically. Unit testing sounds daunting, but it really isn't.

That's deeply unsatisfying.

The alternative is to not test at all, which is (IMO) worse.

There is no possible function with an infinite input space. All function input is fundamentally data, and the possibility space of data, in the most general sense, even accounting for in-function side effects that introduce data previously unavailable, is:
2^(bits of memory space available on any primary memory device + bits of drive space available on any drive + bits available across all registers, general purpose or otherwise, whose states are not predetermined by the fact that the function has been called, thus ruling out, for example, the program counter and frame pointer + bits available on the entire fucking internet + any bits that can be PERSISTENTLY, stored in peripherals)

or u, could youse a logic language, with sufficient deductive power that assertions are literally all you need, no code in between, and then the assertions will self-satisfy regardless of input and u will get working code
it's like fagskells always say, the program is its own proof of corrected

Oops, I forgot to address your last question.
What you want to do is mock your database. i.e. provide a dummy implementation of your database.
Again some Java code:
interface Database {

void addCategory(Category c);
List getCategories();
}

class ActualDatabase implements Database {

@Override
public void addCategory(Category c) {
// add category to the actual database
}

@Override
public List getCategories() {
// query the actual database
}
}

class MockDatabase implements Database {

private List categories = new ArrayList();

@Overide
public void addCategory(Category c) {
categories.add(c);
}

@Override
public List getCategories() {
return categories;
}
}

So now you can swap out the actual database with an in-memory database to test your business logic. Look up dependency injection for more details.

It's a nice ideal, but perhaps not a pragmatic approach to programming. What if I need some very performant code? Haskell will be out the door and so is any other FP language.

But one should pick a language on a need to build basis either way.

Okay, well that was kind of embarrassing, posting a defective program. This one actually works:
#include
#include

int main( int argc, char **argv ){
FILE *fp = fopen( argv[1], "r" );
int c;
int i = 0;
char buf[5];
int nums[80];
while( (c = fgetc( fp )) != EOF ){
ungetc( c, fp );
fgets( buf, 5, fp );
nums[i++] = atoi( buf );
}
fclose( fp );
printf( "\033[2J\033[H" );
fflush( stdout );
for( int j = 0; j < i; j++ ){
printf( "\033[s" );
for( int k = 40; k > nums[j]; k-- ){
printf( "\033[B" );
}
printf( "*" );
printf( "\033[u" );
printf( "\033[C" );
}
fflush( stdout );
return 0;
}

That is, of course, irrelevant.

I don't know what I'm doing wrong then. user said my O(n) complexity was bad.

Attached: 1170804_1029925410434653_2506453898260696633_n.png (600x600, 91K)

Any Scala hackers/programmers here?

I'm looking for someone who can do a kind of audit of an protocol code using Akka.

Attached: AlgeGeom1.gif (360x361, 728K)

>There is no possible function with an infinite input space.
Further evidence that most programmers are mathlets

>Akka
lol Any => Unit

I am so sorry you have to see this

He is dumb. I think it's because "uncle" makes him familiar.

First of all, you need to stop thinking of software as being inherently tied to implementation. There's absolutely no proven reason you couldn't build a genuine Turing machine, not by attaching infinite storage to a computer but rather by completely eschewing all known designs of a computer and inventing a device that implements the protocol of a computer while working absolutely nothing like one on the inside.
Secondly, peripheral data space is in fact infinite all by itself, due to its real time volatility and its ability to produce interrupts.
Finally, the quantity of data you're describing is, for all intents and purposes, infinite anyway. Especially if you're talking not just about the data, but of its possibility space.

In the spirit of this guy (), Scala is also not something I've worked with before. I actually did youtube videos on Idris and am now interested in consensus mechanisms (DAGs, blockchain shizzle) and it's in that realm.

If somebody know about the algebraic topology of distributed computing, that would also be of interest.

Attached: 9780124045781.jpg (198x245, 40K)

Find Ubuntu in Windows 10 Store. Install it. Linux is instantly virtualised on Windows 10. Thank me later.

We're obviously talking about the context of programming you brainless ape. Of course N is already infinite, but there is not a single possible COMPUTER function whose domain is N.

Who is this Unclue Blub you all keep mentioning?

I actually think there are far worse languages than Scala, I just find it amusing that people get excited about its type system and then one of its most popular frameworks throws all type information out the window

a literal boomer obsessed with small talk who talks about "correct programming" like a function should only ever have two args. And other bullshit like that.

>Fortran/MATLAB
This sounds terrible.

How to average two ints in C?

i have trouble solving tasks from leetcode/hackerrank
i always look into the solution, and if i dont, i struggle for hours

what to do Jow Forums?

Attached: 1486879551506.jpg (750x1121, 461K)

guise how do i take the int of two averages

>completely incomparable
it is since most of the time you don't need the postincremented value. and the time you need it's better to use the value in one line, and increment in the next.

you write code for people to read and maintain, compiler doesn't care and optimizes it its own way

>it is since most of the time you don't need the postincremented value.
sometimes you do
>and the time you need it's better to use the value in one line, and increment in the next.
better for what?
>you write code for people to read and maintain, compiler doesn't care and optimizes it its own way
again i ask: better for what? i know you don't mean better to read, because it's not

(int) ((long) a + (long) b)/2)

NOTE: sizeof(long) == sizeof(int) on msvc

Yes I was also surprised when I looked at it last week and found it's not extremely much on the functional side - not as much as I thought from advertisement of it anyway.

So in any case, here's the code base I want to review
github.com/Constellation-Labs/constellation
and here's my mail if someone's interested in taking it apart with me
axiomsofchoice.org/

Attached: of_sorts.gif (899x455, 219K)

The successor function on naturals is computable and has a domain of N. Ackermann's function is computable and has a domain of N x N.

>most of the time
>sometimes you do
yeah, pretty much what i said.
>better for what
exactly as described in the next citation. You do chose code that's more readable when there's no efficiency loss.

It's definitely an OO language first and the functional parts are second class.

Awesome animation, thanks for sharing that

So there are two algorithm class files I have to study and understand (we're remaking the program with our own tools). What's the best way to go about this? What tools can I use to understand the step by step process an algo goes through to produce a result.

Should I use break points? Should I change values in the code to see how end results are altered? I want to understand how these algorithms work so I can make them work better.

>struggle for hours
Finishing struggling. It's taken me weeks to debug work stuff, and that was to find the situation which caused a bug. To properly solve it might've taken another week or two, instead of a single int hack.

Pen and paper?

Well I went through and wrote out what everything does in the class but I'm having a hard time understanding the algorithm in complex. My notes are very literal (e.g. "An arraylist is created and then filled with verticalRulings....).

I'm missing the forest for the trees.

in the broad sense*

yeah, but it's job related, and codebase is probably huge as fuck
i'm talking about default algorithmic tasks which are usually given at the interviews

Have you tried running the algorithm on paper on a small input and looking at the variables at each iteration/recursive call?

Learn the right way to do them and move on.

You have two choices for doing, either learn it yourself or take what someone else has done and learn to adapt it. Preferably, both.

Those functions, INSOFAR AS they are computable, do NOT have a domain of N. Theoretically, they have a domain S such that |S| = 2^(number of bits available to the executing system that are not taken up by execution itself).