/dpt/ - Daily Programming Thread

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

Attached: 1536342633077.jpg (550x440, 38K)

Other urls found in this thread:

gcc.gnu.org/bugs/#nonbugs_c
twitter.com/AnonBabble

>you can't reason about procedural code
Most stupid thing I've read today. Ever heard of Hoare logic kiddo?

exploring the deepest, darkest depths of C++.

Attached: g.gif (220x159, 1.95M)

dumb frogposter

I'm working on a little Haskell program.
Can I get rid of the `pure ()` line? I couldn't find a function with the signature `IO a -> IO ()`.
runParseDocumentTest :: Maybe Feed -> FilePath -> IO ()
runParseDocumentTest feed path = do
_

Employed Haskell programmer reporting in

Attached: 1463364999713.jpg (268x237, 59K)

Employed OCaml programmer reporting in

Nice to see a fp colleague.

Is it technically possible to change the value of the members of an array without the help of an extra variable?
And I don't mean memory address trickery or an expression specific to a language (that still uses an extra variable under the hood)

eww

Employed Idris programmer reporting in too

Nice to see fellow colleagues.

user, computers are just registers and memory address "trickery". There's no variables.

xor swapping but that extra variables means jackshit even in the most constrained systems ever

I don't think so. Just use a temporary variable. Leave memory address trickery up to the compiler.

tfw forced to spend 6 hours a day doing comparative rankings of cute anime girls to build a dataset

its realy impressive how fast you can decide which anime girl is cuter, its like a reflex; it takes maybe a quarter of a second for most comparisons

won't it get optimized down to a xor anyway, the most explicit way of doing it is probably just use your standard librarys swap routine

Attached: .png (1442x744, 623K)

Never mind, I'm retarded.
noop :: IO a -> IO ()
noop _ = pure ()

I need to rewrite a service written in PHP 5.4 many years ago. It has ~20k lines of code in it. I also have to pull a new junior developer through all this.

Someone kill me please.

I'm making pokedex.org but in wxWidgets

learning python, doing lists, bubble sort and dictionaries

>won't it get optimized down to a xor anyway
Not on x86.

This doesn't actually execute the io operation you give it. You're looking for
noop x = () pure ()
or
noop x = do
x
pure ()

or Data.Functor.void

>shit taste dataset

Also, it's not even necessarily an optimization. It might be a pessimization. You save a register, yes, but you use 3 XORs instead of 3 moves. Might be significantly faster to do the latter with an extra register.

If you're saving space, you're probably also losing time. Rule of thumb.

cnt.
Can I just pull out my over decade old books and download Dev-C++ bloodshed, and I'll up to date with the current approaches to c++?

Have modern languages (and the old ones) been updated to include more stuff (especially related to variables) as part of their default libraries and function set?

Starting my journey... been downloading a lot of pics and amassing a bunch of directories. Python is doing all the mundane tasks and at speeds that would render jobless that useless temporary employee.

Al Sweigart's book/website is making me want to stick with programming. I guess I'll try for Java next and then C.

How are you supposed to go about an app with an API key where you don't want the user to need their own API key but you don't want them having access to yours?
I'm writing a utility suite for last.fm and I'm new to the world of API stuff, this is a stupid question but I haven't been able to find anything looking around

Employed ATS programmer reporting in as well

Nice to see all of my functional friends here

Fortune 100 CEO here, my company exclusively codes in Lisp and Delphi

Attached: 1497217984026.jpg (350x308, 38K)

NEW /DPT/ RULES

>no Windows
>no Nvidia
>no OOPsies
>no parrots

>My biggest issues always stem from me not reading framework/library/tool/... instructions properly

Why do I never fucking learn

Attached: man drinking vitamins.jpg (1920x1453, 119K)

Learning C++ as your first programming language is like learning how to fly as a baby before learning how to crawl

Attached: 1531218614229.jpg (960x960, 129K)

Learning to fly before learning to crawl is just taking water over your head, so that would be more like learning Haskell. C++ as your first lang is just.. bad.

Currently learning common lisp

Based

LLVM-based Pascal frontend

If you don't wanna be a pajeet or lesbian who can't even fizzbuzz C++ is a good starting point
Better than something "easy" like js with an IDE that does everything for you, then learn things the wrong way

Fact: OCaml programmers are the most powerful race in the world.

"The difference between an amateur and a professional, is you write your own compiler."
-Terry Davis

>taking wisdom from a guy who the best achievement in life was to kill himself.

Attached: wutface.png (112x112, 17K)

Terry Davis was also a transsexual gay man

Isn't F# literally betterOCaml?

pic not related

Attached: government success.png (334x108, 6K)

And yours is? Watching other people play video games?

What's the best way to check for primes and to generate the nth prime in C++?

do your own homework

I'm a neet

go to school

use a sieve

There's a literal shitload of information on the web about these things.
If you're starting out, try to implement an isPrime function that takes a number and returns true or false whether or not it is a prime.
Try to make your own first, then you can look up optimizations and help on other sites, but don't just copy-paste.

When that's done you can just start checking numbers until you get the amount of primes you want.

No, it's worse. Leave, shill.

in c++ this is just
(PrimeSieveGen() | Take(n) ).eval();

Trying to program a function that modifies an existing string, but I keep getting nothing at the end ("Your result:" and then the program ends). Is there something I'm missing here? I tried using the solution offered by Chegg, but that gave me "Segmentation fault: 11".

Attached: Screen Shot 2018-09-11 at 4.24.48 PM.png (538x626, 91K)

I mean Skip(n) lol

Hook that shit up to a debugger.

Take a closer look at text1

Attached: 1483889496739.png (500x590, 19K)

public static bool IsEqual(T obj1, T obj2){
...
}

Is there a way to do this in C# easily?

what

in c++ this is just
String squeeze (const String a, const String b)
{
const auto set = ( Range(a) | Fold( [](const char a, const auto s){ return s.push(a);}, Tree()) ).eval();

return Range(b) | Filter( [&](const auto a){ return !set.contains(a);}) | CollectList();
}

I want to check if two data objects have the same values. The objects themselves don't aren't equalable, and they might contain properti es that aren't equalable themselves.

z=x//100
zx=x//10 %10
zxy=x%10

For a 3 digit number it returns correspondingly, 1st, 2nd, 3rd digit. But what's the magic behind this? Is there any formula? Can I somehow make it into a loop that'd dissect integers of any length?

in stepanov's c++, this is just
#include
#include
#include

template
ForwardIt squeeze(ForwardIt first, ForwardIt last,
ForwardIt s_first, ForwardIt s_last)
{
for (; s_first != s_last; ++s_first) {
last = std::remove(first, last, *s_first);
}
return last;
}

int main()
{
auto s = std::string { "abracadabra" };
auto m = std::string { "abc" };
auto it = squeeze(s.begin(), s.end(), m.begin(), m.end());
s.erase(it, s.end());
std::cout

go though the motions of teaching numbers to a child and you'll understand

First, change that lim to a #DEFINE.
Second, clean the two strings to be "\0\0...\0".
Third, don't use scanf, it is prone to buffer overflow, use fgets.

>"Your result:" and then the program ends
Because thats probably your result. Take a look on how to read input in c. Scanf reads from the input buffer, if there are remainings on that buffer it will read them.

why don't you just define the == method for the object

Almost forgot, don't ever write x[y++] or x(y++) ever again.

pretty nice

>3 libraries

Bloat.

it should actually be more generic than that:
#include
#include
#include
#include

template
ForwardIt1 squeeze(ForwardIt1 first, ForwardIt1 last,
ForwardIt2 s_first, ForwardIt2 s_last)
{
for (; s_first != s_last; ++s_first) {
last = std::remove(first, last, *s_first);
}
return last;
}

int main()
{
auto s = std::string { "abracadabra" };
auto m = std::vector { 'a', 'b', 'c' };
auto it = squeeze(s.begin(), s.end(), m.begin(), m.end());
s.erase(it, s.end());
std::cout

Because I have tons of different objects that need to be passed into this method. Is there a way to check if a certain type is equalable, ie it's a string, int, double ect?

My idea was
>get list of properties
>check if property type is equalable
>if it is check the values
>if not pass use recursion and pass those objects into IsEqual


Tell me if this makes sense or not

Why does this always make people upset?

I want to release the source code to a program I have written, but
>I don't want anyone (else) making money from it
>I don't want people redistributing it without attribution
>I don't want people to make a dozen forks of it instead of contributing to the original
Creative Commons is often discouraged for software, but in this case I think it would make sense to release it under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International. Is there anything I'm missing?

Thanks. I followed your advice; pic related is new code. Now, the output I get at the end is just text1, unmodified. Is it something to do with how I formatted the loop in squeeze?

Attached: Screen Shot 2018-09-11 at 4.56.10 PM.png (548x749, 106K)

I hate being that guy, but isn't this very strange design?
Each class should itself have an equals method.
The problem now is that you're taking in two objects, so the operations you can do are very limited.
The only way you could use ints and strings and such would be by checking that they're instances of those classes inside the method, and you'd end up with quite a mess.

Undefined compiler behavior. Even two versions of the same compiler may compile two dofferent things, once that is not in the C standart. Avoid that to avoid headaches.

you can also use algorithms with normal c arrays.
this compiles down to less than 100 asm lines

#include
#include

template
ForwardIt squeeze(ForwardIt first, ForwardIt last,
ForwardIt s_first, ForwardIt s_last)
{
for (; s_first != s_last; ++s_first)
{
last = std::remove(first, last, *s_first);
}
return last;
}

int main()
{
char s[] = "abracadabra";
char m[] = "abc";
auto it = squeeze(s, s + sizeof(s), m, m + sizeof(m));
for (auto c = s; c != it; ++c) putchar(*c);
}

What?
x[i++] is undefined behavior? Since when?

shutup

you're not actually employed

>n^2
wamp wamp

>twf going to uni to one day become an employed Idris developer

>bool
I don't get what the fuck are you doing niggy but this should check equality for objects of the same type:
EqualityComparer.Default.Equals(obj1, obj2)

It takes care of everything and its last fallback is using object.Equals(object other).

Unemployed Java programmer here, 0 rupees starting

When s1[i] equals s2[k], shouldn't s[i] receive ' '? Or if you actually want to squeeze ot, you have to make a loop from that place to the end copying the next value, like s1[g]=s1[g+1]

Does it equals to

I++
X[I]

Or

X[I]
I++

? I'm not sure, so avoid.

Pls tell if this is retarded or not
public static bool isEqual(T obj1, T obj2)//checks if the values of two objects are the same
{
var props = obj1.GetType().GetProperties();
foreach (var x in props)
{
var propType = x.PropertyType;
if (propType.IsPrimitive || propType == typeof(string))
{
if (x.GetValue(obj1) != x.GetValue(obj2)) return false;
}
else if (!isEqual(x.GetValue(obj1), x.GetValue(obj2))) return false;
}
return true;
}
}

>equalable

Fucking kill yourself.

x[i++] is
tmp_i=i;
i++;
x[tmp_i]

How to remind
i++
first returning i (old value), then incrementing i
++i
first incrementing i, the returning i (new value)

wouldn't it be n*m?

That might be true, but I'm still 100% sure about the undefined behavior in function calls.

What are you trying to do, you have to be more specific.

But in short, whatever you're doing this is not a good way to do it.

Just starting from the declaration shows that the design should be improved. The method shouldn't even accept types that you don't directly want to deal with in your method, and your method accepts all types.

equitifiable

Fucking COMPARABLE

[pic related]

Attached: 1510850136223.png (472x472, 75K)

Firstly learn english, you brown mock of a human.

double a = 1.0;
a=a/3;
a=a*3;
return a;

What does your choice of language return?

dude chill

If we're talking about
f(x[i++],12);
I'm sure you're wrong. It's a perfectly defined behavior.

gcc.gnu.org/bugs/#nonbugs_c

Jump to the c part.

Common Lisp, 1.0d0

Error, you can't multiply a integer by a double.

yeah but that still sucks

is m * log(n)
and can be made just as generic