/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

stackshare.io/python/in-stacks
plato.stanford.edu/entries/induction-problem/
twitter.com/NSFWRedditImage

One of my contacts set up an Excel spreadsheet with analytics for his business and now wants to turn it into a proper application. He told me the Excel sheet does things big companies buy SAP licenses for.

Does anyone know what he could be referring to? I'm familiar with some of Excel's financial functions but honestly I don't understand this domain very well. I don't want to get into something that's way over my head.

>dude trust me, my code compiled once that means it's correct

fuck javascript

This a million times. I hate when normalfags make all these pseudomemes about how "hard" it is to get code to compile.
That's exactly where the real fun starts

Hey, quick java q', does anyone know how to check if something entered (Through scanner) is an int?

Fort example, the system asks for a number and I want it to check if its an int or not so that if it is not an int it says something like "Sorry, you did not enter an int" rather then giving me an error.

Thanks.

This statement is true in Idris.

Yes, but Idris moves the issue from incorrect code that builds to correct code that doesn't finish building before you die of old age.

He probably means simple map and reduce statistics.

I made an RSS generator for the pirate bay in the last few days. It kept breaking because I didn't account for "Today" and "Y-day" as the dates, but now it's fully functional.

# Use this file to setup searches. The format is `xml_file category search`
# Blank lines or lines without a leading pound (#) are ignored
# You can find the category number on TPB by going on the website, doing a search, and looking at the last number in the URL

# Games
xmls/oxy.xml 401 Oxygen Not Included
xmls/rw.xml 401 RimWorld

the simplest thing would be to try Integer.parseInt and then catch NumberFormatException

right now trying to fap but before that I was reading up on elixir/otp

APL builds fast enough, but oh god...

i find it hard to follow /dpt/ unless i get in at the start of a thread

been searching for an hour
can't find a decent example of simple C# recursion that focuses on the logic and structure of the recursion method rather than the subject (factorials, etc...)

"basically" (not exactly) i want to add some numbers and get the sum, then take that sum and then use it in further additions.

lil help please?

Sure, my friendo. Check out Kleene's fixpoint theorem to understand how your language handles recursion.

>Kleene's fixpoint theorem
Given an input {\displaystyle y} y, first attempt to compute {\displaystyle \varphi _{x}(x)} \varphi _{x}(x). If that computation returns an output {\displaystyle e} e, then compute {\displaystyle \varphi _{e}(y)} \varphi _{e}(y) and return its value, if any.
Thus, for all indices {\displaystyle x} x of partial computable functions, if {\displaystyle \varphi _{x}(x)} \varphi _{x}(x) is defined, then {\displaystyle \varphi _{h(x)}\simeq \varphi _{\varphi _{x}(x)}} \varphi _{h(x)}\simeq \varphi _{\varphi _{x}(x)}. If {\displaystyle \varphi _{x}(x)} \varphi _{x}(x) is not defined, then {\displaystyle \varphi _{h(x)}} {\displaystyle \varphi _{h(x)}} is a function that is nowhere defined. The function {\displaystyle h} h can be constructed from the partial computable function {\displaystyle g(x,y)} g(x,y) described above and the s-m-n theorem: for each {\displaystyle x} x, {\displaystyle h(x)} h(x) is the index of a program which computes the function {\displaystyle y\mapsto g(x,y)} y\mapsto g(x,y).

these symbols make it so much easier to 'get'

I don't understand the question

rip symbol

better to be exact. it sounds like you want to sum a list of numbers by divide and conquer. it's easy to write the code for this—what's not clicking conceptually?

>thinks he's on /sci/
kekkest of top, you think Sup Forums-tards know into \LaTeX?

>LaTeX is somehow unique and also indicative of intelligence

this is pretty fun, thanks
i'm a mathematician and lament not knowing this stuff

regex match/pattern to check if it is all digits is more graceful, otherwise should work

>dude trust me, haskell/idris/memelang2017 compiled my code
>that means it's correct
>also, that means no correct code can be written without them

String dobSumString = dobSum.ToString();
char[] dss = dobSumString.ToCharArray();
int dssSum = 0;

for (int i = 0; i < dobSumString.Length; i++)
{
int idss = dss[i] - '0';
dssSum = dssSum + idss;
}

i want to calculate dssSum, then re-inject it into the top of the for loop with is value from the bottom.

>This statement is true in Idris.
Please show us your fully-verified Idris programs, user. No, fizzbuzz and Peano arithmetic doesn't count.

this is iterative, no?

yes but the iteration limit is based on the results

but this injection that you want is being done for you, right? this looks like it gives the right answer

the for loop doesn't let me redefine the variable
i want the variable at the end to be used at the top in the next loop

What the actual fuck am I even reading? What you're trying to accomplish?

it should. have you tested it? i just learned enough c# to write this and it was fine
int[] v = {1, 5, -2, 7, -3};
int sum = 0;
for (int i=0; i < v.Length; i++) {
sum += v[i];
}
Console.WriteLine(sum);

logm ← {⍺⍺((1-⊢)××)⍣⍺⍵}

ok... let me try to un-blah myself

let say i want to take an 8 digit date 12/23/2017
then i want to break down all the digits and add them up
1+2+2+3+2+0+1+7 = 20
that's the end of my code, but i want to take the 20 and run it through the same process.
2+0=2
keep this going until the final result is one digit (1-9)

what IDE/code editor are you guys using for your linux machines?

Alright, I've got two weeks off, for the first time in a year, and it's time for me to do all the projects I've been wanting to do.
SADLY, I haven't properly learned C yet. Other than The C Programming Language - 2nd Edition, what else is there for learning raw, 1975, functional C?
I wanna be doing low level micro controller stuff, along with time and resource critical user applications.
I'm tempted to ask about implementing OOP in C, but I imagine it'd be much better to learn proper strategies for functional programming.

Lack of LaTeX s indicative of the distribution of intelligence on Sup Forums.
Lattices are not really fun, so no wonder you don't know these. Overally i find the math used in CS pretty boring, though there are exceptions like homological algebra.

I think you're confusing procedural programming with functional programming.

That's much clearer. This isn't really a good example of recursion. You can accomplish it with a nested loop:
var str = "1234512345123451234512345";

while(str.length > 1) {
var sum = 0;
for(var i = 0; i < str.length; ++i)
sum += parseInt(str[i]);
str = sum.toString();
}

console.log(str);

basically, at the end, i need to redefine the charArray so that the new value is what the next loop starts with.

i've enjoyed working through the foundations of statistics for my ml hobby; otherwise, i agree

Oh measure theory was fun, i agree on that. Another kind-of fun area was model theory but i took that one on math department and didn't even mind that half of the course was about lattices. From the curriculum, CS version of it is really castrated, it's pretty much the bare minimum you need for standard formal verification course.

I mean it's basically like saying
>you don't know regex? ahaha plebian
There's nothing special about it.
LaTeX is not magic.

unsigned number = whatever;
unsigned result=0;

while(true){

unsigned digit = number - number/10;

if(digit){
result += digit;
number /= 10;
}
else{
number = result;
result = 0;
}

if(!digit && result < 10){
break
}
}

return result;

WTF seppels
class Shit{
private:
int status;
public:
Shit():status(0) {}
Shit(int i):status(i){}
};

int main()
{
Shit floating; //OK
Shit sinking(2); //OK
Shit swimming(); //Weird Shit happened
return 0;
}

You're declaring a function.
This is one reason to use uniform brace initialization.

Shit swimming{};
intuitive :^)

trying these out. thanks.
just so i know, are these both considered "recursion" though?

No.

I know that. But having parentheses as constructor caller, but if the parentheses is empty then it became a function is really retarded.
I know it's for "Backward compability" but that shit it so weird and a huge trap

You are right, if you don't know regex, you have nothing to do on programming forum. It means not only that you didn't even get through undergrad, you didn't even bother to learn a tool highly useful for programming.
Lack of LaTeX implies there's no need for it on Sup Forums, which means Sup Forums doesn't use mathematical language to formulate their ideas precisely. It means people here cover their arguments under ambiguity of natural language rather than expose it. If you can formulate your argument in precise language, why not do it? I never understood this, it's much easier to understand algorithms when they're formulated in mathematical language or pseudo-code, rather than natural language. The same applies to any argument.

I completely fucked this up btw and it will always return zero. But I think you get the idea anyway.

It gets even more retarded.
TimeKeeper time_keeper(Timer());
The C++ standard, for some retarded reason, requires that this be interpreted as
TimeKeeper time_keeper(Timer(*)());
and declare a function that takes a function pointer as a parameter rather than doing the obvious thing.
They call this "most vexing parse".

>regex is useful
Regex is backwards and disgusting.
Parser combinators beat regex in every single way, regex is simply an awful, stringly typed, textual encoding of a small number of them in an awkward way requiring no end of escaping

Similar to LaTeX then

Fight!! Fight! Fight! Fight!

>parser combinator for menial terminal tasks
Yeah sure, why not. I'm not saying regex is useful for parsing anything, I'm saying regex is useful tool for programmers that got beyond fizzbuzz.

>are these both considered "recursion" though?
No. As I said, your task isn't particularly recursive in nature. It lends itself to plain nested loops.

>it's much easier to understand algorithms when they're formulated in mathematical language or pseudo-code, rather than natural language. The same applies to any argument.
>the same applies to any argument
Looking forward to your mathematical formulation of an argument in favor of this retarded statement... You can use LaTeX if you want, and upload the output as a PNG. I'll wait.

parser combinators are trivial

Not him, but if Shit swimming(); is declare a function that return an object of Shit class, then how to define the function?
I tried similar way to that but gcc (g++) always reporting a function-definition is not allowed here before ‘{’ token

What are you doing with your life?

>muh parser combinators
crap.match(/[0-9a-f]*(-[0-9a-f]*)*/);

Show me your superior parser combination version.

I guess nothing... since I wasn't born female. Perhaps I should just choose to be one?

You are what you choose to be.

Wait then, how do you pass a temporary Timer object to a TimeKeeper constructor that accept a Timer class object before C++ and their curly braces initialization?

Define it in file scope, possibly in another translation unit.

You can define it inside the enclosing function with gcc (not g++), but that's a weird gcc extension that probably doesn't do what you think it does.

You could use another set of parens. Or user a named Timer rather than an rvalue.

>m-m-muh C++ renaissance
>muh sepples is NOT full of design flaws

B-but C++[x++] will be better!

have you haters even read the c++17 spec?

>sepples being backwards compatible with itself
>sepples not being shit
Pick one and only one.

Python didn't need to exist, and by existing it has set back programming by decades, but it was created anyway. Why do people do shit like that?

it's backward compatible in the worst way - only when it feels like it.

>Python didn't need to exist, and by existing it has set back programming by decades
Nobody writes real programs in Python. If you want to find the real culprits, look no further than C++ and Java.

Lots of companies use Python. It is a disaster.

>>dude trust me, my code compiled repeatedly until i could get it into a state where my unit testing script could verify expected behavior for all distinctly meaningful inputs on all in-scope platforms and it's very unlikely to exhibit undefined behavior considering it's fully standards conformant so one of the few possible remaining sources of undefined behavior is memory corruption which the script was also able to verify does not occur because it runs every test case in four runtimes, one in valgrind with debug info, one in valgrind with a stripped release executable, one outside of valgrind with debug info, and one outside of valgrind with a stripped release executable, and there was no abnormal termination reported by either and no non-terminal invalid memory accesses reported by valgrind in particular, that means it's correct for all intents and purposes
ftfy
don't criticize what you don't understand, prooflet
do you think a single theory in the world is scientifically """"""proven"""""?
scientists themselves deny this -- no, theoretical knowledge can be content with absolute proof given ideal premises, but all SCIENTIFIC knowledge, being that it operates in a world where ideal premises do not exist, must be founded upon REPEATABLE CIRCUMSTANTIAL OBSERVATION
your computer is pretty good, but it's not a perfect turing machine nor a perfect implementation of the lambda calculus, it is an imperfect machine, and to say ANYTHING about how it will process any given code, requires imperfect but strongly correlated scientific knowledge
theoretical proof that it works is secondary, and formal proof is nice, but as long as you have the scientific basis for declaring it correct (i.e. having tested it to hell and back under as many meaningfully distinct conditions as possible), you really don't strictly NEED any stronger theoretical basis for that declaration than just having your code be well designed, well documented, and standards adherent in the first place

>Lots of companies use Python.
They use it for various scripts, and I guess some webshits use it for server-side programming. What major products are written entirely in Python?

>It is a disaster.
It's not even that bad of a language for its intended purpose. Why are you so butthurt about it?

stackshare.io/python/in-stacks

It's impossible to know whether a given website uses Python on the server side, but the popularity of Django and Flask and the proliferation of Python jobs tells you enough.

>comparable to Perl, Ruby, Scheme, or Java.
dude... what

>Python
>It's not even that bad of a language
the absolute state of /dpt/

Not him but Python is a really shitty language.
>imperative
>interpreted
>poo
>no abstract types
>literally fucking cares about whitespace (haskell does this too and therefore it is also a shitlang even though it's great in every other way)
>
And here are the good things about it:
>very easy to understand
>has its own package manager for libraries
>unlike ruby, which touts these same features, python looks nice and its package manager doesn't require a few hours of setup
Believe it or not, people who aren't programmers don't care if the language they use is good. They don't have a very solid grasp on programming concepts, so if their language is bloated and slow, that's okay; whatever they're using it for, it STILL won't take as long as it would if they, *not being programmers*, had to code a solution in a more elegant and efficient but also more challenging language.
To them, a programming language is not a tool for *making*, it's a tool for *tinkering*. The code and its hypothetical functionality to an end user are very much a secondary concern to just figuring out whatever they're trying to figure out about the data set they're working with. So, for purposes like that, shitlangs like Python are alright, and particularly easy and friendly ones are ideal in every way.

if you can prove your code wrong then you're fucked

>when the computing ecosystem is so out of wack that its enthusiasts compare figuring out the behavior of its layers upon layers of broken shit to the trial-and-error-based scientific process
And they think it's a good thing, too...

Images are too time-consuming. If you can't express it in logic, it isn't an argument, simple. $CFL \subset CSL$
>dude trust me, unit tests are verification, and of course my test cases cover every equivalence class on input domain i-i think, and i s-swear dynamic analysis is enough to prove absence of bugs

So basically, your arguments are:
>muh FP autism
>muh whitespace
Okay, then. At least you're honest about where you're coming from.

>any of his gripes
>tied to FP in any way at all

>If you can't express it in logic, it isn't an argument, simple
He says, while blatantly refusing to "express in logic" any sort of argument in favor of his assertions... The absolute state of proof-posers...

>m-m-muh imperative
>muh types
>muh oop is evil
>not smelling of FP autism

If you can prove your code wrong, but you have hard evidence that it always works, you're not fucked at all.
Sure, if by "out of wack," you mean that computers are imperfect physical implementations of an ideal that fundamentally cannot and will never be perfectly realized.

>hard evidence that it always works
What form would the evidence take? What's to stop it from breaking next time you run it?

ok, this is superior

do
let tok = digit oneOf ['a'..'f']
many tok
many (char '-' *> many tok)

inb4 "but it's longer"

also makes you think why you couldn't have ['a'..'f'] syntax also do a parser

>computers are imperfect physical implementations of an ideal that fundamentally cannot and will never be perfectly realized.
The problem isn't with the machines, though. It's with the shitty software retards like you write, and with the shitty practices they defend.

>What form would the evidence take?
Exhaustive and repeatable unit tests.
>What's to stop it from breaking next time you run it?
Nothing, but if that's the kind of attitude you're going to take toward anything in life, you're an anti-intellectual and also objectively wrong.
See: plato.stanford.edu/entries/induction-problem/

Huh... that actually is better.

My C is safer than your Haskell.
The problem is indeed with the computer. In the environment it supplies, scientific proof becomes superior to theoretical proof, thus rendering apparently inane statements such as "my C is safer than your Haskell" possibly true.

>Exhaustive and repeatable unit tests.
Impractical for all but the most trivial programs.

>Impractical
Hardly.
Remember we are talking about a computer here.

I can't guarantee a printer will perfectly reproduce my document so I'm not going to bother spellchecking it.