[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 319
Thread images: 26

File: 1413574087478.png (265KB, 934x1000px) Image search: [Google]
1413574087478.png
265KB, 934x1000px
What are you working on, /g/?

Old thread: >>61957754
>>
First for OCaml
>>
File: 1386913464.png (321KB, 547x382px) Image search: [Google]
1386913464.png
321KB, 547x382px
debugging kubernetes calls

should have just stuck to servant-generated types, would have avoided these bugs but the haskell kubernetes lib is too heavy to pull in...
>>
First for OCaml sucks.
>>
I want to lick Lain's feets.
>>
>>61963889
First for JavaScript would never be programming
>>
File: 2017-08-18_21-20-29.png (6KB, 210x247px) Image search: [Google]
2017-08-18_21-20-29.png
6KB, 210x247px
Redpill me on macro usage in C++.

Which option would you choose?
>>
>>61963950
Definitely not first, that's C thing.
>>
>>61963950
enum seems to fit this case best.
>>
>>61963950
the one you forgot: (unless you need to do bitwise operations on it -- then its just a bit extra code to add that).
enum class TileType {
BLANK, NORMAL, WATER
}
>>
>>61963967
>enum class
wat
is this a thing?
>>
>>61963934
Lain is not for sexualising.
>>
>>61963950
use enum class, senpai
>>
>>61963984
Yes. It's a stronger type than "normal" enums, which are basically just integers with predefined values.
>>
>>61963950
>>61963958
Both the first and second are available in C.

I'd take the enum, personally. Fewer things you need to worry about yourself when extending with more types, though I guess if you're using C++ then >>61963967 looks like an equivalent solution.
>>
>>61963984
since C++11.
http://en.cppreference.com/w/cpp/language/enum#Scoped_enumerations
>>
>>61964002
>>61964012
every day I learn something new about sepples
fuck
>>
>>61964022
You're not alone, but thats the wonders of a language that is basically 4 languages bolted together.
>>
>>61964062
>4 languages
Who are they?
>>
>>61964125
C
Some object-oriented language
Some metaprogramming language
A bit of functional programming too
>>
I know some python, and I'm currently learning some C. Give me some not too big project to practice on, /g/.
>>
>>61964125
>>61964130
this, but to give it names:
CPP (read: preprocessor) +C
C++98-style OOP
TMP (template metaprogramming -- basically a whole dialect of C++)
C++11/14/17 FP
>>
>>61964158
Do people even use TMP any more?
>>
>>61964162
Template metaprogramming is one of the few things that actually make C++ bearable. If you limit yourself to writing "C with classes and RAII", you kind of miss out on what makes C++ a useful "low level" language.

I mean, STL containers alone is for me a reason to choose C++ over C for a new project. And it's not just about generics, I can declare semantically compile-time optimisations which simply isn't possible without templates.
>>
>>61964130
C
Java
Prolog
Haskell

Wow, how can other languages compete with ++C. I'm a /seppler/ now.
>>
>>61964190
>C++
>supporting Haskell
kek
>>
>>61964199
inb4 #include "HsFFI.h"
>>
>>61964162
Yes.. its how the 4th language is built to be fast. It lets you avoid the overhead of the '2nd language' by not having to deal with the OOP costs of double indirection, or bloating the vtable or forcing people to subclass or have to think about abstract / pure interfaces (or the headaches that MI can lead to.).

If you write libraries for other people, you generally either go full crazy with TMP (and drink the boost koolaid), or you just wrap the STL. Both but sit ontop of, or directly use TMP.
>>
>>61964189
>>61964212
>I can declare semantically compile-time optimisations which simply isn't possible without templates.
For example? Templates are certainly useful but I'm speaking specifically about metaprogramming. Using a template for plain old compiletime polymorphism isn't what I'd consider metaprogramming.
>>
Who thought operator overloading is a good idea?
>>
>>61964229
>not simply allowing custom operators in the first place
>>
>>61964229
anyone who doesn't want a separate addition operator for every single thing supporting addition (in any sense of the word)
>>
>>61964229
Stroustrup.
>>
>>61964229
Try doing BigNum arithmetic in Java and tell me it was a bad idea.
>>
>>61964190
Sepples combine their powers (and >>61964158 is right, it's more about C's preprocessor rather than just C the procedural language).

I mean, C is basically a portable assembly. You generally want to avoid writing that unless you absolutely have to.

Java is a neat 90's object-oriented language, but it seriously lacks a lot of modern features which they have to bootstrap on every new release. There's also the whole issue with an indeterministic garbage collector, making it unsuitable for most embedded environments.

Prolog is just a declarative language, it's not directly comparable to the compile-time programming you do with C++, but I'll give you that one. I know very little Prolog.

And for FP, Haskell is mostly limiting itself by being a strict FP language. In my opinion, it's more suitable for learning FP rather than actually use it in a productive environment, because you end up with abstract stuff like zygohistomorphic prepromorphisms.
>>
>>61964241
I'd separate concatenation and addition.
>>
>>61964241
hurrdurr add(a, b)
>>
>>61963183
>was Taught in universities
>hardly popular
>>
>>61964226
>For example?
Well, specialisation for example. Any generic that can be specialised into optimised versions for each type, for example std::sort.
>>
>people complain about D's parens dropping
lmao
echo x
>>
>>61964157
Base converter which writes decimal numbers instead of own digits.
Let's say, hex FEED.17 would look like 15,14,14,13;1,7 or 15'''14''14'13°1'17''
>>
>>61964226
Say you want to compute optimal slabs chunk sizes for a custom allocator based on the target platform, you can compute this at compile time and not have the runtime overhead of figuring out how many bytes you need here or there.

Say that same slab allocator determines which chunks to use based on how often a class of objects are allocated with it. Like, for instance it'll specialize Foo for small objects and pack them tightly. And for large objects it'll do something more cache friendly (like storing their addresses in a forward list -- or similar).

Why do it at runtime when the compiler can generate better code from your templates? Especially when the compiler can help you find tons of errors, instead of maybe catching an exception or an assert.

Another use case, look at how <chrono> is implemented. Compile-time errors for invalid casts (truncating durations, etc), and automatically conversions based on a computed algebra, so you can easily refactor later if you want to switch to a more fine-grained unit. This type of interface relies heavily on TMP.

>>61964263
But if operator overloading is bad, is method overloading bad too?
>>
>>61964311
>But if operator overloading is bad, is method overloading bad too?
It fucks the ABI by default, so I'll say it's bad. I'd rather have something like the C11 _Generic macro, except obviously not a macro.
>>
>>61964260
you still need an operator for every numeric type &c.

>>61964263
no different from operator overloading
>>
>>61964311
I suggest that you use int::add, float::add, or auto::add
>>
>>61964340
That's not opOverloading
>>
>>61964288
It's garbage, UFCS by itself is cool though.
>>
>>61964332
>It fucks the ABI by default
It just creates a larger ABI, the reason why it's fucked in sepples is because no one ever bothered standardising the ABI.
>>
>>61964368
Implement your custom::add
Not that hard
>>
>>61964356
oh, I just realised what you actually meant

yeah it's fucked and a bad idea
>>
>>61964267
It being taught is a decision of a small group of people. This does not indicate popularity. Popularity is indicated by how many actually use it for work. Barely any.
>>
>upload image of cat in popular blog platform
>click post
>nothing happens
>image is posted

>upload image of nude women
>notification about NSFW, sensitive material, etc
>delete image before posting

how do they do it? AI shit scan every uploaded image posted checking for nude content?
>>
>>61964410
Yes. I didn't find any publicly available neural networks for nudity detection, but there are some proprietary.
>>
>>61964406
You don't "use" SICP for work. You use the concepts in it for work. I agreed that Scheme was not popular (as in was not used a lot for projects), however the concepts that it had reached a lot of people as SICP was taught to them, and that's how closures got popularized.
>>
>>61964410
Machine learning.
>>
>>61964465
>language that popularized closures
>SICP

Anon, please.
>>
>>61964475
Clearly it was Javascript.
>>
>>61964679
That was my original claim, yes.
>>
Rate my shitcode, /dpt/
def to_new_base(a, base):
b = ""
mult = 1
pos = 0
anew = 0

while (mult < a):
pos += 1
mult *= base

pos -= 1
mult /= base

while (a != 0):
anew = a // mult
b += str(int(anew))
if (pos != 0):
for i in range(abs(pos)):
b += "'"
else:
b += "°"
a -= anew * mult
mult /= base
pos -= 1

return b


>inb4: >python
What's better to shitcode?
>>
>>61964869
Python is great for writing shit code, awful code, and many other bad forms of code
>>
>>61964871
Thanks, I am on the right way then.
>>
>>61963889
Diving back in to C# after having not touched anything related to .NET Framework since 2.0.
C++/C# interop is super comfy.
Unit and integration testing also super comfy.
I'm also really digging System.Diagnostics.Contracts
>>
>>61964945
Welcome back, rajesh
>>
>>61964945
you should look into pex and moles. its a shame other languages haven't picked up things like that.
>>
>>61964945
>C++/C# interop is super comfy.
explain
>>
>>61964945
>not touched anything related to .NET Framework since 2.0
Well, you're in for a ride.

Both the language and framework have come a long way; .NET 2.0 is basically unusable in comparison.
>>
>>61964973
Welcome black, Duqan.
>>
>>61965007
I think what he means is M$ C++/CLI thing, which helps using C# from C++ and vice versa. You write things in C#, write a helper function that converts C# values to C++ equevalent in /CLI and then call them from the normal C++
At least that's how i remember it
>>
File: 1390398252.png (1MB, 1919x1079px) Image search: [Google]
1390398252.png
1MB, 1919x1079px
>tfw find a screenshot from 2014

it was from adding image display to Yi buffers..
>>
>>61965007
C++ / C# interop is done via p/invoke. And when something is too complex for p/invoke (which is basically placing an attribute of which library the native function is om, plus a C# declaration (using types like IntPtr, etc).) You can use C++/CLI and write a simple wrapper over the native api and compile it to a .net assembly, which'll look exactly like it was written in C# (or F# or VB.net, etc).

example of p/invoke:
extern "C" { 
__declspec(dllexport)
void Foobar(int a) {
printf ("%d\n",a);
} }

// C#
[DllImport("Foobar.dll")]
public static extern void Foobar(int a);

// now you can do Foobar(42);
>>
File: compscigrad.png (19KB, 516x439px) Image search: [Google]
compscigrad.png
19KB, 516x439px
r8 the use of my degree
>>
File: graduate flipped.png (216KB, 1925x2013px) Image search: [Google]
graduate flipped.png
216KB, 1925x2013px
>>61965371
>>
>>61965234
or just copy paste c++ into an unsafe block
>>
https://gist.github.com/rgrig/b4cdaed3ed9a70dbdb6f158f14b57263
>>
>>61965234
Jesus christ that amount of gymnastics is worse than writing C89
>>
>>61965613
what the fuck?
>>
>>61965613
"enterprise"
>>
>>61965626
>that amount of gymnastics
A single line? Are you ok?
>>
File: Winniethepooh2011dvdrip.jpg (49KB, 720x400px) Image search: [Google]
Winniethepooh2011dvdrip.jpg
49KB, 720x400px
>Assume that there is about 1 toilet for every 3 persons, that existing toilets use an average of 15 liters per flush...
>>
>>61965626
>specify a method call
>specify the path to the dll that the method is in
>gymnastics
owo?
>>
>>61965234
>C++/C# interop is super comfy.
>explain
>here, look: C/C# interop

???
>>
>>61965639
>>61965631
turing-complete type systems are fun
>>
http://cc.bingj.com/cache.aspx?d=1462716999241&mkt=de-DE&setlang=en-US&w=xEsMxqoa0KJSwMsTh3p_8w2qryykfDvB

lmeow
>>
File: hivemind 2.png (232KB, 562x521px) Image search: [Google]
hivemind 2.png
232KB, 562x521px
>>
>>61965643
>>61965652
Try non fizzbuzz C/C++ libraries nest time
>>
>>61965646
so?
>>
>>61965517
so, you'll copy/paste all of, say, libwebp into an unsafe block?
or the windows api?
or directx?
>>
>>61965371
you fucking fucker, why did you not just copypaste the code

nonetheless:
>making a separate 3 and 5 condition
>>
C++ is such a mess, it makes me sad.
>>
File: ok.png (258KB, 1663x5063px) Image search: [Google]
ok.png
258KB, 1663x5063px
>>61965728
alright
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad);

picture related, its the documentation for this simple function.
its still two lines with p/invoke.
>>
>>61965884
if you want to use structs, you just make the structs with the right alignment (tons of attributes for doing all kinds of lifetime management, alignment, layouts, etc). There's also tools (for visual studio) that literally automatically generate all this for you. You just tell it which function from which lib you want and it'll create everything for you.

Say you want to pass in a pointer to a C struct:
[StructLayout(LayoutKind.Sequential)]
public struct ALTTABINFO
{
public const int SIZE = 40;
public int cbSize;
public int cItems;
public int cColumns;
public int cRows;
public int iColFocus;
public int iRowFocus;
public int cxItem;
public int cyItem;
public Point ptStart;
}

// variable names don't matter, literal copied from the API
[DllImport("user32.dll")]
static extern bool GetAltTabInfo(IntPtr hwnd, int iItem, out ALTTABINFO pati, StringBuilder pszItemText, uint cchItemText);


Its an okay way of doing it. As for C++, you have to write an extern "C" wrapper, or provide a .NET wrapper in C++/CLI. Most (useful) libraries, that want to be used from other languages already provide a C interface because only D can do FFI with C++.

I think Mono has x/invoke or something, but I don't do C# any more so..
>>
>>61963950

For similarly grouped objects, use an enum, preferably an enum class so things don't get put into global scope.

For regular old constants, use constexpr, as it is typed, and can be namespaced if need be.
>>
File: cb4.jpg (270KB, 1820x1365px) Image search: [Google]
cb4.jpg
270KB, 1820x1365px
int
*cracks knuckles*
main
*sips energy drink*
(void)
*puts on the hoodie*
{
*eurobeat intensifies*
>Enter
Let's CODE
>>
>>61966448
you're really defining everything in main?
>>
>>61966448
>(void)
well, at least you didn't write an empty param list
>>
I just discovered a minor step in the algorithm I'm developing for my thesis which I thought would be trivial is actually NP-hard.
>>
>>61966860
ha ha ha
>>
>>61966931
I-

I c-can get approximate solutions quickly
>>
>>61966860
You know what else is hard?
*unzips list of tuples*
>>
>>61966968
Sorry, I shouldn't have laugh, but it was funny.
>>
>>61966968
*scales problem size up by 5*
>>
what the fuck is a register

is it just a big set of 64 bits? what makes a register a int or unsigned int or a character or a float or a pointer or a struct?
>>
>>61967128
lol
>>
> 4 recruiters
> 3 pending applications
> 2 invites
ENTERPRISE MODE ENGAGE
>>
>>61967128
>is it just a big set of 64 bits?
Yes.
>what makes a register a int or unsigned int or a character or a float or a pointer or a struct?
It is what you want it to be. Zeroes and ones have a value depending on what they represent.
>>
>>61964679
Java popularized them by not having them.
>>
>>61963950
Macro constants are equivalent to magic numbers. I'd say always choose lvalues such as constants so that a pointer to it can be added to the program's symbol table. Believe me it is SUCH a pain integrating with lower level code that just #defines shit. None of those definitions are reachable from a FFI. But then again you're using C++, which mangles names
>>
>>61967182
Java had them all along, it just took until Java 8 for you to realize.
>>
>>61964288
Only if the function doesn't take arguments or has a single optional argument. Eg : assert("foo bar".split == ["foo", "bar"][])
>>
>>61967161
so it's the instructions that determine the "type" of the register? for example, if I make an int, it generates signed integer math instructions for the bits stored in register X but if I make an uint it generates unsigned integer math instructions for the same register X?
>>
>>61967303
Yes.
>>
>>61967303
The instructions do things with the zeroes and the ones and you get new zeroes and ones. They can be integers, or chars, or floating point numbers. If you add up a representation of an integer in two's complement with a representation of a floating point number you are getting a bullshit meaningless result. However, you can prove that adding up a two's complement with another two's complement by doing the binary sum will yield a two's complement representation that would match the actual operation in math terms.
>>
>>61963950
why do you have to tell the compiler that a literal constant is a constant expression?
>>
>>61967863
It's a compile time expression and can be used as such.
>>
>>61967886
Yes, but how could the compiler possibly not know that?
>>
>>61967863
Declaring it as const is enough.

>>61967886
Most of the time you don't have to say it.
>>
How do you master/become proficient at a language enough that you could apply to jobs for it?

I see lots of course that teach the essentials/the basics of a language, but surely that's not enough for getting hired for a job. For those of you who professionally work, how did you learn your language? What steps did you take to pursue a career as a programmer?
>>
can you got an IOS emulator on Visual studio 17?
I am using xamarin and trying to test it on IOS.
>>
>>61964162
TMP is popular in high-performance computing
It allows you to write abstract code for matrices, vectors, and complex formulas using them without sacrificing performance, yet retaining compact, high level code

Many scientific papers on the subject
https://www.google.com/search?source=hp&q=hpc+template+metaprogramming
>>
>>61968046
>compact
>>
>>61968044
Due to Apple copyright shenanigans, you have to have a Mac to debug iOS/macOS applications.
>>
>>61968079
I figured it was some shit like that. So I guess its pretty much I have to borrow my sisters iphone to see if it runs on IOS
>>
File: x.png (139KB, 1452x592px) Image search: [Google]
x.png
139KB, 1452x592px
>>61968077
Well, at least the code you write is compact :^)
>>
Haven't learned any C++ the whole day, I was in the job and work politics and now doing the same in /g/.

Here is a reverse factorial though
#include<iostream>

using namespace std;

int main(){

int n;
cin >> n;
int i = 2;
while ( n % i == 0){
n /= i;
i++;
}
if(n > 1)
cout << "NONE" << endl;
else
cout << i-1 << "!" << endl;

}
>>
>>61968112
Yeah, but keep in mind that you can only run it on your sister's phone; you can't actually debug with breakpoints. That still specifically requires a Mac.
>>
File: codebollocks.png (21KB, 1366x724px) Image search: [Google]
codebollocks.png
21KB, 1366x724px
Anyone here uses Code Blocks?
I can't open source file, when I press Run I get "Hello world" prompt and when I create new project CB blinks few times and nothing happens.
>>
could use some help with Perl if you don't mind...
Trying to make Perl read from a file, as in have something along the lines of 'user=name' in the file, and be able to have perl put this into hash, and whenever i ask it to print the part after the = sign, it would (in this case) print 'name'. I've gotten part way but don't quite know how to continue...
#!/usr/bin/env perl
use warnings;
use strict;

my $file = '/home/user/file.txt';
my (%param, $param, $value, $left, $right);
open(FILE, "<", $file) || die("no: $!\n");
while(my $line = <FILE>) {
chomp($line);
($param, $value) = split("=", $line);
#print("$line\n");
$param{$value} .= ($param, $value);
print("$param{$value}\n");
}
>>
>>61968150
#include <iostream>

int
factorial(int abc)
{
if (abc == 2)
return 2;
else if (abc == 1)
return 1;
else
return abc * factorial(abc - 1);
return -1;
}

int
main(void)
{
int input;
std::cin >> input;

int i = 1;
while ((factorial(i) < input) && factorial(i) != -1) {
++i;
}

if (factorial(i) == input)
std::cout << i << "!" << std::endl;
else if (factorial(i) == -1)
std::cout << "Error occurred." << std::endl;
else
std::cout << "None." << std::endl;

return 0;
}
>>
File: 1479773279139.jpg (705KB, 1536x1536px) Image search: [Google]
1479773279139.jpg
705KB, 1536x1536px
This code may be absolutely disgusting, but whatever.

What I'm trying to do is move an entity by whole increments. But even if the move speed is not a whole number, take the remainder and add it to the next step.

It has mostly worked, but a problem that I have faced is moving "backwards". The best way to explain it would be with jumping. Maybe an entity jumps with a starting velocity of -4 and falls as the number becomes positive. I might not be doing my math right, cause i'll reach zero, and randomly jump back and forth between -1 and 0 because of the remainder. Once I reach 0 I want to stay at 0 and continue the other direction.

    // x-axis: positive movement
if ( ent->mov[0] > 0 )
{
ent->rem[0] += ent->mov[0] - floor(ent->mov[0]);
ent->rem[0] = roundf(ent->rem[0] * 100) / 100;

valueX = floor(ent->mov[0]) + floor(ent->rem[0]);

if ( ent->rem[0] >= 1.0f )
ent->rem[0] -= 1.0;
} else
// x-axis: negative movement
if ( ent->mov[0] < 0 )
{
ent->rem[0] += ent->mov[0] - ceil(ent->mov[0]);
ent->rem[0] = roundf(ent->rem[0] * 100) / 100;

valueX = ceil(ent->mov[0]) + ceil(ent->rem[0]);

if ( ent->rem[0] <= -1.0f )
ent->rem[0] -= -1.0f;
} else
// x-axis: zero movement
if ( ent->mov[0] == 0 )
ent->rem[0] = 0;

// y-axis: positive movement
if ( ent->mov[1] > 0 )
{
ent->rem[1] += ent->mov[1] - floor(ent->mov[1]);
ent->rem[1] = roundf(ent->rem[1] * 100) / 100;

valueY = floor(ent->mov[1]) + floor(ent->rem[1]);

if ( ent->rem[1] >= 1.0f )
ent->rem[1] -= 1.0f;
} else
// y-axis: negative movement
if ( ent->mov[1] < 0 )
{
ent->rem[1] += ent->mov[1] - ceil(ent->mov[1]);
ent->rem[1] = roundf(ent->rem[1] * 100) / 100;

valueY = ceil(ent->mov[1]) + ceil(ent->rem[1]);

if ( ent->rem[1] <= -1.0f )
ent->rem[1] -= -1.0f;
} else
// y-axis: zero movement
if ( ent->mov[1] == 0 )
ent->rem[1] = 0;
>>
What are some cool uses of bitwise operators?
>>
>>61968276
Fast multiplication.
>>
>>61968276
https://graphics.stanford.edu/~seander/bithacks.html
>>
>>61968276
storing multiple numbers in one 32-bit integer type
>>
>>61968168
but its supposed to be a mobile app.
>>
>>61968382
Take it up with Apple.
>>
>>61963889
I know c.

Which programming language should i learn next?
>>
>>61968465
>I know c.
no you don't.
>>
>>61968465
in short you took intro to programming in c

>>61968393
yeah thats not even worth complaining about. fuck apple
>>
Doing quarterly backup of server's system drive so if it ever crashes I won't have to install a bunch of updates.
>>
>>61967863
constexpr lets you evaluate expressions at compile time. when doing a simple assignment like that, there's basically no difference.
but lets say you wanted to create (or use) that value at compile time.. (..don't do this though)
#include <cstdio>
#include <cstdint>

constexpr uint64_t factorial(uint64_t n) {
return (n > 1) ? n * factorial(n-1) : 1;
}

// compile with -DINPUT=42
int main(void){
constexpr auto result = factorial(INPUT); // will be replaced with 42! ..or 7538058755741581312
printf("%llu\n", result);
return 0;
}

# which is literally just
movabs rdx, 7538058755741581312
call _Z6printfPKcz
}


>>61968276
cool? well. practical would be bit masking and in general, flags
>>
Is there any way to check overflow in C++ without manually checking the limit of primitive types?
#include <iostream>
#include <string>
using namespace std;

int
get_int(string prompt = "Please enter the integer: ")
{
int result;
do {
cout << prompt << flush;
cin >> result;
if (cin.fail() || result < 0) {
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid input, please try again: " << flush;
} else {
cin.ignore(100, '\n');
return result;
}
} while (true);
}

int
fac(int x)
{
int result = 1;
for (int i = 2; i < x - 1; i++) {
result *= i;
}
return result;
}

/*
* Looks for factorial, starts from 1
* Returns -1 if the given int is not a factorial number
*/
int
probe_reverse(int x)
{
for (int i = 1; fac(i) <= x; i++) {
if (fac(i) == x)
return i;
}
return -1;
}

int
main(void)
{
int x = probe_reverse(get_int());

if (x != -1)
cout << x << endl;
else
cout << "Not a factorial number." << endl;

return 0;
}
>>
>>61968465
C++ obviously.
>>
>>61968725
Nope.
>>
>>61968725
You could probably come up with a template to do it. Check sizeof(T), allocate a container that's 1 byte longer, do bitwise addition into the new container and check the extra byte.
>>
>>61963908
Underrated.
>>
>>61968178
>Code Bollocks

Install VS
>>
>>61968889
>Visual Spyware
Install Qt Creator
>>
>>61968276
Packing 64 booleans in 1 variable
>>
>>61968878
>Underrated
what
>>
>>61968906
how?

store the bools in the bit fields of an int?
>>
>>61968725
>>61968864
well this, but a template specialization with numeric_limits<T>::max(), but thats what you're suggesting. just without the if.

>>61968906
std::vector<bool> :^)
>>
>>61968923
>std::vector<bool>
xD
>>
>>61968465
lern knitting and knit yourself some programming socks
>>
>>61968922
yes

>>61968923
>vector<bool>

That's autistic. Do it bitwise on uint64 like a real man you fag
>>
>>61968955
>yes
but an int is 4 bytes

1 byte = 8 bits
4*8 = 32 bits

32 bools ?
>>
>>61968955
vector of bool is generally just a bitfield. its a very special version of vector thats not really a vector because it stores individual bits not actual bools. so you can't actually get a bool out of it.
>>
>>61968923
Oh, it already exists as a standard template. I should have guessed.
>>
>>61968970
>but an int is 4 bytes
The fuck are you rambling?
int is at least 16 bytes.
>>
>>61968984
an int in C is 4 bytes
>>
>>61968980
template specialization was a mistake.
>>
>>61968970
btw, in C a CHAR_BIT (informally, a byte) is _atleast_ 8 bits

>>61968984
and an int is _atleast_ 16 bits.
>>
>>61968992
it might be but it's not quaranteed to be.
dumb faggot poster
>>
>>61968998
Everything is a mistake when it gets misused.
>>
>>61969038
C++ is more easily misused than most langs.
>>
>>61968998
reminder that C++ still doesn't have real generics, only the pseudo-macros known as templates
>>
>>61969032
you're a retard
>>
>>61969050
what are ``real generics"?
>>
I'm a beginner and i'm trying to solve this problem : "Can you find a combination of 5 forbidden letters
that excludes the smallest number of words?"
List of words : http://greenteapress.com/thinkpython2/code/words.txt
>>
>>61969054
t. somebody who has never used anything but 64bit operating system.
>>
>>61969082
Is that actually the full problem description?

I can make assumptions on what that means, but I don't like to make assumptions.
>>
>>61969064
data Maybe a = Just a | Nothing


Uniform representation - the parameter is just represented with a pointer, i.e.
Maybe Int ~ Maybe Bool ~ Maybe Double
In terms of representation
>>
>>61969064
>>61969128
e.g. in C++
template <typename T>
struct Ex {
T* ptr;
};


This should generate the same layout and code for any T, even Ex<Ex<Ex<Int>>>
(On most platforms)
>>
File: Capture.png (108KB, 1333x228px) Image search: [Google]
Capture.png
108KB, 1333x228px
>>61969107
Here is the full problem
>>
>>61969128
>>61969143
so a typechecked void*
>>
>>61969187
yes, it's more flexible
>>
Rate my non-compsci degree
for (int n = 0; i <= 100; ++n) {
if (n % 3) std::cout << "Fizz";
if (n % 5) std::cout << "Buzz";
else if (!(n % 3)) std::cout << n;
std::cout << std::endl;
}
>>
>>61969259
>Buzz5
>>
File: anal beads.png (34KB, 849x439px) Image search: [Google]
anal beads.png
34KB, 849x439px
>>61969082
>>61969174
Something like this.

Basically, you want to get word counts per letter and grab the five letters used in the least amount of words.

The answer would be
w, z, x, j, q
.
>>
>>61969272
He has it here like
else if
>>
>>61969282
What JavaScript is this?
>>
>>61969287
oh, must be blind
>>
>>61969309
>What JavaScript is this?
nani?
>>
>>61969282
But 2 forbidden letter can be in the same word anon, this make the answer more complex.
>>
>>61969232
Sounds fairly difficult. You'd have to have hidden function pointers or switch statements along with each type that you pass into the "generic" function. This sounds like a problem you can solve with C++'s existing OOP polymorphism.
>>
>>61969323
What is this language?
>>
>>61969338
its C# 6. the 2nd part is LINQ which has been in C# forever, but using the method call syntax instead of the relational/declarative syntax
>>
>>61969326
True. Reworking now to use the actual function it asks for, although it seems like it's going to have to run a full combination of 26:5 over the entire list.

>>61969338
It's C#.
>>
>>61969351
>C# 6
Has to be C# 7, considering the local function.
>>
>>61969360
I couldn't tell where the braces are because they are off screen. but, now I can make out that the main function is at the top. but yeah, its a modern C#.
>>
>>61969335
No you don't.
It isn't specialised.
Everything works completely generically.
If you want to do something monomorphic, then you do something like

vec<int> add(vec<int>, vec<int>);

as you say, you could have function pointers too.

you can't do this with C++'s polymorphism - it's subtype polymorphism and not parametric polymorphism.

>inb4 GADTs
>>
>>61969335
>>61969391
this then lets you have generic functions as first class citizens, since you know they operate on uniform data, then the code is uniform too
you can also have recursive types that if instantiated template-style would be infinite

plus, it doesn't inflate code like templates and it doesn't have any header/source problems
>>
I want to create a CLI subscription manager for YouTube. Should I use the API or use a web scraper?
>>
>>61969391
I'm a bit of a brainlet so please bear with me while I try to understand what you're suggesting.
What you want is a mechanism where you can write code like this.
template  <typename T>
void arr_add(T *ina, T *inb, T *out, size_t size)
{
for (size_t i = 0; i < size; i++)
{
out[i] = ina[i] + inb[i];
}
}


But no matter how many different instantiations of the template you use for whichever different types, it will compile to exactly one function emitted with a signature that looks something like this.
void arr_add(void *ina, void *inb, void *out, size_t size);

I don't see how you could do that without some kind of dynamic dispatch based on the types it is called with at runtime. The + would have to use a different opcode if it's given doubles rather than ints.
>>
>>61969565
Yes, + would because + is not generic.
You would need a
(T*)(*)(T*,T*)
parameter

And then your code is uniform and generic.

But for specific cases like (T = Int) you can obviously write the code
>>
>>61969050
You're not wrong, but templates are more performant than "real generic" anyway.
>>
>>61969596
Yes, but templates are also less flexible and less useful.
You could have both, and C++ is so awful it would probably do that.

>>61969565
>>61969590
Same as qsort that is, except that you have type checking
>>
Hi. I'm going through SICP, for those of you who have read it what kind of notes did you take? (if any) I'm unsure as to what I should be memorizing.
Also is Guile a good interpreter for testing your code?
>>
>>61969590
So the actual signature of the function to be emitted would be
void arr_add(void *ina, void *inb, void *out, size_t size, void *(*plus_operator_for_T)(void*, void*));

So you would have a hidden function pointer parameter like I thought.
I dunno, this seems like it'd get pretty bloated pretty fast. Your program would have a smaller footprint in memory but it feels like all the indirection and branching would add up fast.
>>
>>61969665
If you combine it with concepts it ends up much better

generic <Addable T>
T* arr_add(T *ina, T *inb, size_t size);

And you'd hope that it could be done with an optimisation pass that specialises and inlines for some cases.
>>
>implying poodris
>implying huskell
>implying scheme
>>
>>61969702
Unless you're developing for an environment where code size is a serious concern I don't see this as being something greatly useful.
But whatever, maybe I just don't have enough experience to see the advantage of this over regular templates.
>>
Learning Scala.
>>
>>61969794
The primary advantage is that the data and the functions that operate on them become uniform, meaning you can store generic functions, pass them around, operate on them, apply them, etc.
You can also do stuff like polymorphic recursion.
With type equality constraints (similar to a concept) you could do GADTs too.
>>
>>61969590
but + is generic in a template class, with accordance to SFINAE technically: std::plus literally just calls the operator+ on two Ts
// plus is basically defined as () which is called by std::invoke() 
// (basically apply, and depending on how old your STL is, it'll even be partially applied with std::bind)
// a naive impl:
constexpr T operator()(const T &lhs, const T &rhs) const {
return lhs + rhs;
}


>>61969794
regular templates hardly provide any bloat though. you only pay for what you use. an optimizing compiler won't even generate the methods in vector that you don't call, for instance. all templates slow down is compile (well, technically link) times.

its not like the days of c++03 where templates would blow up because of boost, a lot of the stuff added to c++11 allowed the STL (and your templates if you're paying attention to your traits..) to elide all kinds of things.

...unless you mean physical source code size, then yeah templates can get out of control, but actual executable code size (-Os really helps here too) shouldn't be that anywhere like it used to be.

>>61969835
you can do that too with ref wrappers / decltype(auto) / etc, using aforementioned std::invoke.

sorting a list?
vector<int> i { 5,3,1,7 };
vector<string> s { "s", "d", "a", "f" };

// reverse order
stable_sort(begin(i), end(i), greater<>());
stable_sort(begin(s), end(s), greater<>());
>>
what is the difference between currying and partial application?
>>
>>61969835
So you can do something like this?
generic <Addable T>
void arr_add(...);

auto fptr = &arr_add;
fptr(intarr1, intarr2, intarr3, n);
fptr(floatarr1, floatarr2, floatarr3, m); // Same fptr!

I suppose all of this would have been obvious to me if knew some FP language.
>>
>>61969794
>>61969835
Not to mention that its' cleaner from a conceptual standpoint.
One example:

Generics, unlike templates, have to work for every instance.
So a generic is itself typechecked, rather than typechecking a template instance.

>>61969890
You need to know the type at compile time in that case.
>>
>>61969918
No, the idea is that the
Addable T

Is a concept constraint, which basically means

a type T which is also Addable
The Addable bit can mean either "has a + operator" or "there exists a function pointer to add this T"
When you call it with int vs float, it'll choose that corresponding function.
>>
>>61969918
>>61969945
Oh wait, i'm confused by what you mean
>>
>>61969918
>>61969972
Yeah, I'm confused because you aliased the function and called it fptr
I assumed you meant the function pointer being passed in, sorry

Yes, it would be the same fptr.
Not different instances/overloads/specialisations, the exact same function.
>>
>>61969945
>>61969972
>>61969986
I'm talking about this idea here.
>The primary advantage is that the data and the functions that operate on them become uniform, meaning you can store generic functions, pass them around, operate on them, apply them, etc.
So in C++ you can't do something like this.
template <typename T>
void arr_add(...);

auto fptr = &arr_add;

This makes no sense, you must instantiate the template and then take the address of it before you can do anything. And the function you take the address of isn't generic, so it can only work for whatever instantiation you chose at the point of taking the address.

But with your proposed generics you can take one fptr and apply it to any of the types it is made generic over.
>>
>>61969352
The real problem is to optmize the program, it's for example useless to check 'abcde' and 'edcba' because it's the sames letters.
>>
>>61970017
Yes, that's the idea. I was just confused.

With the concept/constraint stuff (Addable), it's similar to OOP polymorphism (a vtable) except that it's an implicit parameter to the function, rather than packaged with the data.
You can imagine it as being the same as what we talked about before - simply passing the function pointer as an argument.


Basically, the core idea is that you know that it's the same code or the same representation for all instances (struct or function alike).
That's what I mean by generic, though I'm sure some people just mean any kind of parametric polymorphism (including templates).
>>
>>61970017
>>61970074
And as you say, it is an indirection, so it is slower code.
That's the main price you pay.
>>
imperative programming
>>
>>61970064
Yeah, trying to implement a fast and elegant non-repeating combination algorithm for this.

Basically 26 choose 5 on the alphabet.
>>
>>61970074
OK, I can see the advantages of what you're suggesting.
> it's similar to OOP polymorphism (a vtable) except that it's an implicit parameter to the function, rather than packaged with the data.
That reminds me of a thought I had a while ago. I was wondering what C++ would be like if it if bundled the vtable pointer alongside the struct pointer in a special, new type, instead than embedding the vtable pointer inside the struct. Something looking a little like this.
class Foo 
{
virtual void action() { printf("Called from a Foo"); };
};
class SubFoo : Foo
{
void action() override { printf("Called from a SubFoo"); };
};

Foo *foo; // may only point to an exact Foo
SubFoo *sub_foo;
virtual Foo *virtual_foo;

foo = new Foo;
sub_foo = new SubFoo;

foo->action(); // No vtable indirection necessary, since the exact type of Foo is known
sub_foo->action(); // Same

virtual_foo = foo; // A Foo* decays to a virtual Foo*. The vtable pointer is introduced with the decay.
virtual_foo->action(); // vtable indirection because exact type is not known.


>>61970099
You know how sepplesfags are with muh performance.
>>
I need to get back to what I'm doing but g++ is lol-worthy.
foo.cc:6:24: note: suggested alternative: 'abs'
f(std::forward<Args>(args)...);
^~~~
abs

yeah, I totally wanted std::abs() there.
>>
>>61970338
Here's another example of the advantage:
What if rather than a function that operates on a foo, you want a function that operates on a string to return a foo? (e.g. a parser)
You can't do that with OOP style polymorphism, but you can with concepts/type classes/traits/etc.

The idea is just that you'd define an "instance" (like a set of all of the virtual overrides for a particular type), and then based on the type the compiler picks one of these instances to use, e.g. if it needs an
int (*add) (int, int)
Then it'll pick the "int" specialisation.
>>
>>61970355
>not wanting abs
>>
>>61970399
sepples don't wanna make me lift, just to grow the neckbeard out and look at programmer socks on amazon.
>>
>>61970338
>>61970392
You could look at the Concepts proposal for C++.

Rust also has this and calls them traits.

Here's a lecture on Haskell type classes, I think this covers the idea:
https://www.youtube.com/watch?v=6COvD8oynmI
>>
File: stupidfucker.jpg (4KB, 146x138px) Image search: [Google]
stupidfucker.jpg
4KB, 146x138px
>>61968263
>spaces between parentheses
Anon, I...
>>
>>61970410
I'm gonna have to knuckle down and learn Haskell at some point. Real FP might as well be rocket science to me.
>>
>>61970410
The bit on typeclasses specifically starts at 8 minutes
>>
>>61970410
concepts + metaclasses will make C++2020 (it'll likely be 2023+ though..) so comfy.
>>
File: renge docker.png (328KB, 640x360px) Image search: [Google]
renge docker.png
328KB, 640x360px
I'm trying to figure out whether I should spend time on learning Docker.
When I deploy something once, I can do everything manually.
When I deploy something three times on the same machine, doing something manually becomes tedious so I write a shell script.
When I deploy something three times on three machines, changing the script for each environment becomes tedious, so I write an Ansible playbook.

In what scenario would I want to use Docker?
>>
please gib the "it's legit javascript" picture
>>
>>61970586
defined product/application bounds, aiding in isolation
reproducibility (having similar environment to production so you're not surprised by any weird configuration changes. also being able to have consistent environments if you're on a team that are easily copyable.).
setup boilerplate services for messing around, experimenting, etc

if you're just using it for deployment, chef, ansible, and the rest of those other deployment automation tools are superior, desu.

also the memes.
>>
>>61970586
isolation, kubernetes, composition, using existing images without having to fuck around
>>
File: cprogramming.jpg (26KB, 381x499px) Image search: [Google]
cprogramming.jpg
26KB, 381x499px
Now I can finally understand why people meme about this book so much. It is short, and precise. I don't know why it took me so long to read this book. Is there any programming/tech books that I should consider reading after finishing this one?
>>
>>61970794
continue the memes and read/work your way through SICP then HtDP.
>>
>>61963889
>What are you working on, /g/?
Shitty little evening project.
I take a lot of small notes, interesting urls etc.
Writing a program that will let me create small notes and encrypt them, thinks keepassx but for notes instead of usernames and passwords.
>>
>>61970794
LYAH
>>
>>61970808
>SICP, then HtDP
Shouldn't it be the otherway around? Or am I still getting memed on?
>>
File: index.png (205KB, 880x505px) Image search: [Google]
index.png
205KB, 880x505px
As requested by >>61959854
Presumably, since vaginas/dicks are usually red, the neural network considers red = genitals.
>>
>>61963932
what's your use case for kubernetes ?
>>
>>61970833
after SICP, HtDP will provide a lucid and elucidating review of the prior.
but you can just skip HtDP all together.
>>
>>61970833
Don't listen to the anon, xe's retarded. HtDP is a childrens book compared to SICP.
>>
File: --946.jpg (1MB, 2023x1200px) Image search: [Google]
--946.jpg
1MB, 2023x1200px
>>61970691
Here's a nice anime picture
>>
>>61970869
>>61970889
>>61970808
So If I finish SICP, do I achieve programming Zen status?
>>
>>61970863
trying to deploy this Haskell application as a service such that we can scale horizontally; you might even guess which one if you've been looking at Haskell opening in last 6 months or so

sadly it wasn't designed in way kubernetes wants it to (or anything where scaling is a thing) so it's really hacky right now
>>
>>61970828
Is this book any good? I think the cover looks cute.
>>
>>61970926
>>61970863
should say I solved most issues since I made original post but god damn it was a long day

the kubernetes API docs suck ass, figuring out what it wanted for patching of resources basically had me go look at kubectl source to see what the fuck they are doing there
>>
>>61970924
No, Haskell is Zen. SICP is wizard.
>>
Is there any difference in speed between these two?
int max1(int x, int y) {
return (x > y) ? x : y;
}

int max2(int x, int y) {
return (-(x>y) & (x^y)) ^ y;
}
>>
>>61970972
The first is probably faster, because the compiler is optimising a trivial expression, rather than some autist fucking around with bitwise instructions when they don't even have a processor in mind
>>
>>61970972
Compile both and inspect the disassembly.
>>
>>61970939
>>61970828
it's ok; it's where I started myself (not that poster) but it has been >5 years since so I guess it's pretty dated; depends what you're looking to get out of it I guess. I wouldn't really know what to recommend to a beginner these days though. What's your experience?

Speaking of Haskell books, I'm pleasantly surprised by High Performance Programming in Haskell; at least the part I read so far (~third of a way through I'd say). Few mistakes but nothing you shouldn't easily spot and it's a pretty good collection of stuff so far.
>>
>>61970990
I am pretty much a C newbie, but Haskell has always caught my attention as a "side programming language" for fun. I know it's a meme, but memes are sometimes fun.
>>
>>61969916

Let's consider regular addition on Ints.

(+) :: Int -> Int -> Int;


This function can be partially applied on a single number
x :: Int
to create a function that takes one
y :: Int
and returns x + y.

For example, this function

(+) 4 :: Int -> Int


takes a number and adds 4 to it. Here, partial application happens because (+) is a curried function.
I know you didn't ask about uncurrying, but let's now consider

(:+) :: (Int, Int) -> Int
(:+) = uncurry (+)


We can't partially apply this function like we could before, all we can do is pass a pair to it and get the sum of its components:

(:+) (1, 2) = 3


What happens if we curry this function?

let (+:) = curry (:+)
:t (+:)
Prelude> (+:) :: Int -> Int -> Int


Currying is turning a function that takes a tuple into one that receives each element of that tuple, on at a time, from left to right. To recap: first we had a curried function, (+), which we could partially apply to get a function with one less argument. Then, we uncurried it, and got a function that must receive a pair with both arguments in it, which we cannot partially apply. Finally, we curried this uncurried function to get yet another function, this time curried, which we can also partially apply.

With general types:

f :: a -> b -> c
g :: (a, b) -> c
curry :: ((a, b) -> c) -> a -> b -> c
uncurry :: (a -> b -> c) -> (a, b) -> c
uncurry f :: (a, b) -> c
curry g :: a -> b -> c


As an interesting aside, I'll leave it to you to "prove" whether or not
curry . uncurry f = id
, where id here is the identity on functions of type
x :: a -> b -> c
. You can also consider the opposite equality ;)
>>
>>61971028
> Let's consider regular addition on tits.
OK, what do I do?
>>
>>61970990
I never got the appeal of Haskell. Last time I tried it I spent more time trying to figure out how the fuck the language exactly works than about the software designs I wanted to implement.
>>
>>61970953
weew i thought scaling issues were a meme and only a real problem for big companies
>>
>>61971015
Then I guess LYAH may be OK. It doesn't really assume much previous programming knowledge so you're set. Unsure why you'd want it to be a side language though, it's really good. I'd hate having to write anything else these days.
>>
>>61971041
Boi.

Are you dyslexic? I didn't proofread my post with the precision I wanted (too tired), but I'm pretty sure it says Ints.
>>
>>61971043
Well, you could do both. https://www.microsoft.com/en-us/research/publication/the-implementation-of-functional-programming-languages/ is a pretty good book even if 30 years old by now. GHC commentary is always worth reading. Of course you don't need to read either to just use it to a pretty damn effective measure.
>>
>>61971043
You've got to go further into Haskell
Once you don't have a problem understanding regular Haskell code, then you can go in depth into stuff.
Once you learning the autistic type theory stuff, then you can get some really convenient designs and shit
>>
>>61971043
>I spent more time trying to figure out how the fuck the language exactly works
But that's the feature of Haskell. You must not think how the language works, only software design matters.
>>
>>61971015
Not him, but Haskell is a nice plaything. I'm not skilled enough to write anything practical with it and I don't see myself getting on that level anytime soon. So that's why I picked up Scala.
>>
>>61968909
OCaml is.
>>
>>61970972
max1(int, int):
cmp edi, esi
mov eax, esi
cmovge eax, edi
ret
max2(int, int):
xor eax, eax
cmp edi, esi
setg al
xor edi, esi
neg eax
and eax, edi
xor eax, esi
ret


No branches on O2.
>>
>>61971043
>>61971100
>>61971104
I want to get into functional programing paradigm, shoud i try haskell or clojure ?
>>
>>61971122
I'd say Haskell, since it's statically typed
>>
What is a good "statistics for programmers" type of textbook?
>>
>>61971119
But is it faster? It has more instructions. Is this after "muh optimizing compiler"?
>>
>>61971028
Thanks anon for the thorough explanation.
So: if you partially apply a curried function, you get another curried function and so on...
>>
>>61971148
any good "statistics" type of textbook
>>
>>61971132
Pardon my plebeianism but upsides of static typing are only better static code analysis tools and ide autocompletion right ? Am i missing something ?
>>
>>61971196
with ad hoc polymorphism you also get type based dispatch
>>
>>61971172
Why the quotes?
>>
>>61971028
 curry . uncurry = id
is less interesting "exercise" than
uncurry . curry
because latter requires fully lazy
uncurry
implementation which many beginners will completely skim over
>>
>>61968263
bumpin

>>61970415
easier to read
>>
>>61971122
Go for Clojure if you're a Lisp fetishist. There's no other reason to use that language.
If you don't want Haskell, there's always OCaml, F# and Scala.
>>
>>61971196
I mean "typechecker" could fall under "static code analysis tool" I guess but it's hardly an "only" sort of benefit...
>>
>>61971253
you won't get type classes with OCaml and F#
I don't know Scala and can't comment on it
>>
Can I learn the basics of C in just a few hours?
>>
>>61971264
http://danielwestheide.com/blog/2013/02/06/the-neophytes-guide-to-scala-part-12-type-classes.html
Is this comparable to Haskell type classes?
>>
>>61971290
Yes depending on previous experience and what we're considering the basics.
>>
>>61971168
No problem!

It depends on the number of arguments of the function. It's not very interesting to call a
f :: a -> b
function curried or uncurried, and I don't quite remember what the convention is on that, but on function with 3 or more arguments, yes.

If the function has
n > 2
arguments, when you partially apply it once, you get a function with n - 1 arguments, and if you partially apply _that_ function, assuming
 n - 1 > 2
, you get one with n - 2 arguments, and so on.
>>
>>61971306
I want to go through the R&K boom
>>
>>61971298
Skimmed it, looks like it does at least the basics
>>
>>61971298
Not him but AFAIU Scala classes can get you in a lot of trouble because orphans don't trigger any sort of warning so you can have different places in code give you completely different instances without any warnings: if you ever dealt with orphans in real code and decided to disable the compiler yelling, you can imagine how much trouble that may be.

But I also never wrote Scala so I may be talking out of my ass. Quick search brings up https://www.reddit.com/r/scala/comments/3bh5g8/what_makes_type_classes_better_than_traits/
>>
>>61971308
Exactly, it's stupid to debate if the `id` function is curried or not.
>>
>>61971355
I'm not an expert if Scala, but it has funky stuff like you just mentioned. I don't consider it a deal breaker though.
>>
>>61971154
why not benchmark it? (msvc with the standard release flags:)
Run on (6 X 2800 MHz CPU s)
08/18/17 17:03:59
Benchmark Time CPU Iterations
-------------------------------------------------
BM_max1 156 ns 151 ns 4977778
BM_max2 153 ns 136 ns 4480000
>>
>>61971104
I don't mean how it works under the hood, I mean the fucky little nuances of the language itself, especially the lazy evaluation. Trying to grok shit like the zipWith fibonacci sequence gives me a headache.
>>
>akaribbs down
what happen
>>
>>61971441
it only evaluates when it needs to, e.g. a primitive func or a case switch

fibs = 1 : 1 : zipWith (+) fibs (tail fibs)

because we've already got two elements, we can already get the head of fibs, and the head of (tail fibs), from which we can generate a 3rd element, then we can make a 4th, 5th, etc
>>
File: 1468013405521.jpg (48KB, 477x465px) Image search: [Google]
1468013405521.jpg
48KB, 477x465px
>>61971460
it's been down for a while
>>
>>61971383
>>61971308
Trying to determine whether anything is curried or uncurried or whatever is silly to begin with.

When you uncurry a function, you simply tuple up the first couple arguments (or more)
When you curry a function, you expand a tupled argument into separate ones.
When you apply a function to some arguments but don't fully saturate it then you're partially applying it.

Looking at some function f and trying to determine if it's partially applied/curried/uncurried is a fairly pointless exercise in semantics. For example:

f :: () -> Int -> Int
f _ x = x

g :: Int -> Int
g x = x


Now f () is isomorphic to g. So what can we say about partial application now?

Is f partially applied? No, f is f. Is f () a partially applied function? If yes then same would have to hold for g, they are isomorphic. But I think you would not say that for g. At best you can say that you're partially applying f and to get some function. This function is not partially applied or anything.

Same argument goes for currying/uncurrying. Is a function uncurried when it takes a tuple or only after you explicitly
uncurry
an existing function..?

tl;dr don't get caught up, these terms are just useful for describing what we're doing or a shape of a function rather than a strict analysis of what a function is.
>>
File: 69.png (21KB, 100x100px) Image search: [Google]
69.png
21KB, 100x100px
>>61971495
rip
>>
File: 1475432842909.jpg (76KB, 515x698px) Image search: [Google]
1475432842909.jpg
76KB, 515x698px
>>61971594
akari-sempai doesnt post very often either
>>
>>61971482
I might just be a brainlet but programming outside of the context of computer logic is unintuitive as hell.
>>
>>61971620
It's mainly because of composition with other stuff.
Most lazy stuff is more intuitive.
You need to actually think about how zipWith is implemented or what it does in lazy terms in order to get that sort of thing.

zipWith f (x:xs) (y:ys) = f x y : zipWith f xs ys

Forces the two list arguments into weak head normal form (basically until you get a constructor out of them, either [] or (x : xs), like 1 layer of pattern matching)

Then it calls f x y, but we don't actually force (f x y), so that can be returned as a lazy value
Then we have the rest, (zipWith f xs ys), which is also a lazy value
>>
Is golang worth learning? It's showing some pretty good growth and I wonder if it can replace other systems and network programming languages.
>>
>>61971680
>systems and network programming languages.
No because it's still GC'd at the end of the day. If it will ever be good at anything, it'll be microservices. Because that's what google wants to use it for.
>>
>>61971680
It seems basic enough that you can learn it quick and not waste much time.
>>
>>61971709
what's the problem in a language having a garbage collector?
>>
File: meirl.png (277KB, 704x480px) Image search: [Google]
meirl.png
277KB, 704x480px
>Got pigeon-holed into being a front-end developer using typescript
>Use typescript everyday for the past few months
>Realise I have no idea how to create anything in typescript from scratch only to add new features and build on existing site

Guess its time to actually learn typescript. No idea what I'm actually going to create. Any suggestions lads?
>>
>>61971755
It can't be used for real-time applications, like operating systems.
>>
>>61971769
what framework do you use at work (or want to learn)? use that framework+ts to consume some api and present it

twitch, flickr, 4chan, sports api
https://github.com/toddmotto/public-apis
>>
>>61971788
(most operating systems aren't real-time, though.)
>>
>>61971797

We have our own react/angular style framework so can't use that, will probably just jump on react again.
Its a pretty big company, >600 devs
>>
Planning a project. Is it possible to get access or to implement search engines from other sites to your app? Like facebook's friend list search/database for example?
>>
>>61971836
can you give me a quick rundown on React?

what's used for? can it be used for mobile? is it easy?
>>
>>61969282
>The answer would be
w, z, x, j, q

kek, that excludes both my first and last name
>>
Best way to learn Python?
>>
>>61971947
not to
>>
>>61971860
I'm not who you replied to, but if you're interested in learning react (free and bretty good): https://leanpub.com/the-road-to-learn-react

(I'm not the author)
>>
>>61971947
codeacademy to learn the language, then pick a framework for something to actually create something cool (django or flask for web, some machine learning framework for python, desktop app framework)

don't worry too much about how/what to do, and just actually do it
>>
>>61971955
have you read the book?

is it any good?
>>
>>61971992
yeah, it's definitely good. you'll actually build something with a good code base to pull from for your next project for structure/patterns
>>
>>61972022
thanks man
>>
New threads are created around bump limit, right?

>>61972090
>>61972090
>>61972090
>>
New thread:

>>61972099
>>61972099
>>61972099
>>
>>61971860

React is a UI framework from facebook. Standard web dev, i.e. html + css + javascript is a pretty slow and outdated way of doing web dev, with most sites wanting more functionality than a plain screen with a few links and stuff like that. Sure you can add functionality with js but in larger projects you will want a framework like react/angular/vue to ease web dev.

Its pretty essential now for becoming a web developer.

Mobile integration isn't a problem with it at all.

Like any language, the more experienced with programming you are (regardless of the language) the easier you'll find it to pick up and learn. I remember at uni having to learn F#, I've been programming since I was 13 but never picked up functional programming, most people there have only done the programming that was part of their course. I got the basics down in a day and got good marks, others spent weeks trying to understand it and their code was utter shite (imagine 15+ 'if' statements in a row checking the same variable for different outcomes). React itself is pretty easy though, nothing particularly unique to it that would take a lot of thought to get your head around.

With that being said, I've never used it in a professional environment (only became front-end in my new company that uses its own framework).

Below is the go-to tutorial for react, wrote by Facebook their self.

https://facebook.github.io/react/tutorial/tutorial.html
>>
>>61972096
>>61972110
why?
>>
>>61972116
thanks anon!
Thread posts: 319
Thread images: 26


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.