[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 24
File: 1444164399410.png (1 MB, 1702x2471) Image search: [Google]
1444164399410.png
1 MB, 1702x2471
Falsifying your employment history edition!
old: >>52033619
what are you working on, /g/?
>>
First-ish for Go.
>>
File: 1448453529488.jpg (101 KB, 884x903) Image search: [Google]
1448453529488.jpg
101 KB, 884x903
D
>>
>>52038440
C with GNOME libs is sweet
>>
Is it true that F# is the best programming language?
How do other languages even compete?
>>
java
>>
>>52038207
not a bad idea, ill give it a shot
>>
>>52038491
It's true, Senpai
>>
had some free time today, thought i'd look in to an esolang. this is cjam, program that returns the area of a circle

"Enter the radius of the circle:"oli2#P*p
>>
Daily reminder that if you can't pattern match or specialise, you don't have support for generics
>>
>>52038491
It's true
>How do other languages even compete?
They don't. The race is over. F# won.
>>
>>52038440
reminder:
https://www.youtube.com/watch?v=6G3kQyqMFpQ
>>
>>52038591
OCaml says hi. OCaml wonders how you like being 10x slower than it.
>>
Do I have to learn C# before F#?
>>
>>52038705
Start with C
>>
>>52038705
You should forgot about both.
>>
>>52038723
I already know C senpai
>>
>>52038705
No, it's better to start with F# outright too.
>>
>>52038362
>>52038600
no need to remind us that haskell in inferior :^)
>>
>>52038705
You have to learn to play D# first.
>>
>>52038705
>>52038723
Start with the Greeks
>>
>>52038704
It's not

F# is wonder why no multicore
>>
File: 2015-12-24_17-16-11.png (9 KB, 869x284) Image search: [Google]
2015-12-24_17-16-11.png
9 KB, 869x284
>>
>>52038504
good way to get banned from irc channels
>>
>>52038847
If your bot doesn't act like a bot, how would they ever know?
>>
File: 2015-12-24_17-19-04.png (12 KB, 869x292) Image search: [Google]
2015-12-24_17-19-04.png
12 KB, 869x292
My skills improve every day. Do yours?
>>
>>52038847
A fun challenge is to write markov bots and see how long they can remain undetected
>>
>>52038866
let () =
print_endline "why use a shitty language?";
print_endline "Greatness Awaits (tm)!"
>>
>>52038847
there are channels dedicated to people building bots

>>52038866
ur a hax0r m8
nice numbers, btw
>>
>>52038879
>markov bot
>2016 almost
At least graduate to LSTM bots already!
>>
File: 2015-12-24_17-23-07.png (16 KB, 871x359) Image search: [Google]
2015-12-24_17-23-07.png
16 KB, 871x359
>>
>>52038866
should be:
DateTime.Now.ToString("hh:mm tt")
|> printfn "I am a programming Master. It's %s"
>>
File: 2015-12-24_17-26-27.png (9 KB, 488x281) Image search: [Google]
2015-12-24_17-26-27.png
9 KB, 488x281
>>52038943
That's why I come to /g/, for the elite skills. What's the |> operator called, and can you stack them? Wait, I'll try.
>>
>>52038924
No, I'm right. There's no advantage to dynamic typing. It just makes it easier to write compilers for the language. That's all.

If you're sure I'm wrong, please explain why you think dynamic typing is useful for anything.
>>
>>52038973
I think it's called pipelining, and yes it can be continuously stacked with other operations.
>>
>>52038847
>he isn't an op in at least 30 channels on 5 networks
cumon step it up
>>
File: 2015-12-24_17-28-34.png (9 KB, 496x290) Image search: [Google]
2015-12-24_17-28-34.png
9 KB, 496x290
wowow you can stack whatever the fuck |> is called
>>
>>52038973
pipe forward operator. It takes the value of the expression before the operator, and makes it the last parameter of the function after the operator. Yes, you can stack them. They are beautiful.
>>
>>52038973
>That's why I come to /g/, for the elite skills
kek
>>
>>52038986
Dynamic typing makes it more difficult to write compilers for the language. Static typing makes it more easy to write compilers for the language.
>>
>>52039003
Try pattern matching next.
>>
>>52039021
I do the same actually. There's actually a small number of good programmers in /dpt/
>>
>>52038922
>using if statements
>not using pattern matching

why live?

let rec gcd x y = 
match y with
| 0 -> x
| y -> gcd y (x % y)
>>
>>52039026
and what exactly is that based on? Static language compilers do everything that a dynamic language compiler does, except they also verify types, field names and references etc during compilation. TypeScript is basically just a static compiler that does this to vanilla JS, and can find some compile time bugs by figuring out what types variables are meant to be at compile time. You can add type annotations though to help it out, but it will infer a lot by itself.
>>
>>52038986
>It just makes it easier to write compilers for the language.
Haha, that's completely incorrect. You need a compiler and a VM. Maybe for the same feature set, because dynamic types can do a lot more than static without extra functionality.

>If you're sure I'm wrong, please explain why you think dynamic typing is useful for anything.
Polymorphism, generics. "Oh let me just implement a bunch of box classes and write an interface for all the types that this function needs to accept". Or you can have a significantly more complex compiler to do this for you.
>>
>>52038973
Pipe operator
>>
>>52039079
A dynamically typed variable needs to be analyzing the type of the variable at all times. A statically typed language just needs to ensure that the operation is sensible for that type; this requires less code to achieve.
>>
>>52039054
>F# is better than Haskell
myGcd x 0 = x
myGcd x y = gcd y (x `mod` y)
>>
File: 2015-12-24_17-37-40.png (12 KB, 509x377) Image search: [Google]
2015-12-24_17-37-40.png
12 KB, 509x377
>>52039029
>>
>>52039082
>You need a compiler and a VM.
I'm talking about the compiler. And you don't need a VM, you can compile directly to native code if you want to. Or you can use an interpreter, which are also much easier to write.

>because dynamic types can do a lot more than static without extra functionality.
They can't do anything static languages can do. dynamic languages are the same as static languages, except without compile time type checking. That's the only difference.

>Polymorphism, generics.
What about them?

>"Oh let me just implement a bunch of box classes and write an interface for all the types that this function needs to accept"
Not really sure what you mean. What's a good example of what you're talking about? If a dynamic method accepts multiple parameter types, it still needs to check what they are at run time. Nothing is easier here, just more bug prone.
>>
>>52039129
>'mod'
HAHAHA
>>
IGNORE TRANNY THREADS

REPORT TRANNY POSTERS
>>
>>52039079
>Static language compilers do everything that a dynamic language compiler does, except they also verify types, field names and references etc during compilation
Dynamic languages do type-checking too, just during runtime. And how is 'doing more' and argument for better?
>>
>>52039125
>A dynamically typed variable needs to be analyzing the type of the variable at all times.
at run time yes. It doesn't have to, but most dynamic languages will.

>A statically typed language just needs to ensure that the operation is sensible for that type; this requires less code to achieve.
Static languages like C# and Java will still do run time checks on types, because it can't always be sure if a type will be what it's meant to be. This is done at run time, just like in languages like python and JS, but has nothing to do with the compiler.
>>
>>52039167
>And how is 'doing more' and argument for better?
They can catch bugs at compile time that a dynamic compiler will not find.
>>
what other languages support static duck typing like go?
>>
>>52039308
ocaml.

F# kinda with records..

both better languages than go btw
>>
IGNORE TRANNY THREADS

REPORT TRANNY POSTERS
>>
>>52039331
so go is the only imperative language?
>>
>>52039346
no, ocaml and F# are multiparadigm. They support imperative just fine.
>>
Can C# really be included in the same group of languages as C/++?
>>
>>52039343
>>52039166
this. the dubs know.
someone make a new one...
also, ignore and report anime threads.
>>
>>52039308
"static duck typing" is called structural typing
https://en.wikipedia.org/wiki/Structural_type_system
>>
>>52039343
I don't like trannies, but you have to admit, in anime, it is cute.

If they were 3D tranny posters I'd agree, 3D transsexuals are an abomination.
>>
File: ew.png (272 KB, 470x624) Image search: [Google]
ew.png
272 KB, 470x624
How do I learn JS, /dpt/?
>>
>>52039427
> I don't like trannies, only pretend trannies
>>
>>52039156
What I'm saying is that the onus of implementing type generic functions, polymorphism, etc. is on the programmer with a statically-typed compiler. I'm sure this can be avoided with a sufficiently complex compiler, but that's the argument against it. You either end up with a compiler that isn't good enough to allow you to write transparently polymorphic code or a compiler that is so complex it has to write a good chunk of the application for you just to get around the artificial constraint of type safety, which is a massive effort. The dynamic compiler leaves type checking to the runtime or programmer if they need to specifically handle different types. This reduces the development cost for the compiler and the application code for most applications. Static type checking can be important for certain applications where code paths might not be touched for a long time, but not all applications are like that and so don't benefit from the extra checks a static compiler offers, but do from the easier to implement type parametrized code. It's all about costs.
>>
>>52039462
Fuck around with canvas.
>>
>>52039469
Can you explain an example?

generic functions and polymorphism is just as hard in dynamic languages as it is static ones. The only difference is a static compiler will verify certain bugs won't occur at compile time, while a dynamic language will wait until run time.

I'm not sure what makes you think this is not the case.

>It's all about costs.
I agree. This is why I hope dynamic languages are phased out of production environments completely.
>>
>>52039465
Anime trannies are cute though.

I don't like real life rape either, but in anime it is cute.

We can enjoy fictional things that we hate IRL.
>>
>>52039427
>anime trannies
these are actually really rare
most anime traps are simply crossdressers and not trans at all
>>
>>52039462
Read Eloquent Javascript. Should take about half a day to a day or so.
>>
>>52039683
what about https://github.com/getify/You-Dont-Know-JS
>>
>>52039469
>Static type checking can be important for certain applications where code paths might not be touched for a long time, but not all applications are like that and so don't benefit from the extra checks a static compiler offers, but do from the easier to implement type parametrized code. It's all about costs.
To add. This is why I would like a language like Typescript (but not JS, a real systems language) where types are optional to best take advantage of both cases.

>>52039542
>generic functions and polymorphism is just as hard in dynamic languages as it is static ones.
No it isn't.
function iterate(t)
local s = type(t)
if s == "table" then return pairs(t)
elseif s == "list" then return ipairs(t)
elseif s == "set" then return coroutine.wrap(function()
for k, v in pairs(t) do
if type(v) == "boolean" and v then
coroutine.yield(k)
end
end
else
error("unsupported type for iteration")
end
end

for i in iterate(list{1, 2, 3, 4}) do end
for k, v in iterate({a = 1, 5, 6, 4, 3, cpp="sucks"}) do end
for i in iterate(set{'a', 'b', 'c'}) do end

I'm not even going to get into how this would be implemented in C++... You would have to have to write a virtual base function that implemented an "iterate" method and then override it in every class you want to iterate. That's overhead because the dynamic code above divorces types and methods. Yeah you can do this in some languages via reflection, but it's just implementing the characteristics of a dynamic language at that point. Just ask people who have had to use dynamic types in C#, Go, or Java. The miniature embedded dynamic language needed reflection implements is a pain in the ass. you could blame the compiler not being advanced enough, but there is my point. The compiler has to be very advanced to get around the type safety system. But in a dynamic language with optional type checking you get the best of both. The compiler ends up being a big linter
>>
>>52039747
Sorry for the fuck-ups. I'm bad at writing.
>>
>>52038440
FAAAAAAAAAAAAAGGGGGGGGGGGGGGGGGGGGOOOOOOOOOOOOOOOT
>>
>>52039382
Yes.
>>
Hey /dpt/ what do you think of my code
>>
>>52039722
Never read it. All you really need to know about javascript beyond EJ is that it's single threaded so you can depend on the document not changing while inside a block of code.
>>
>tfw you only know C
>all the fun projects are done in javascript
Can I do back-end web development in C and learn just enough JS to make a front-end?
>>
>>52039542
there is no point in enforcing things like type arguments at runtime, which is why dynamically typed languages do not care about them at all
compound types are often just hashtables. if you have a list of some object, then no type checking is done at runtime. if a["foo"], where "foo" is some member and a the compound type, doesn't exist, then the runtime will just throw an exception
checking if a map contains a key is a lot simpler than type verification
this is what duck typing is about: if something exists at runtime, fine, if it doesn't, crash
if you want a list of some types that share a common feature then in a dynamically typed language you define the structure for each and that's it, in a statically you define the structure and also something that describes what these types have in common so the compiler knows what's up
the entire worry about correctness is moved to the programmers brain from the compiler, which obviously isn't that good for big projects
for small projects and scripts however it's completly fine and easier to write because you do not have to describe what things have in common
>>
I wish in JavaScript

"string" * 3 = "stringstringstring"

And

"3" * 5 = "33333"

Why doesn't it, /dpt/?
>>
>>52039831
learn JS and use it for backend AND frontend...
or, do something useful with C instead.
>>
>>52039831
JavaScript is piss easy senpai.

Just read this:

https://developer.mozilla.org/en-US/docs/Web/JavaScript
>>
>>52039853
because it's not python
>>
>>52039865
Is it possible to do neat things with JS without having to load 50MB of js frameworks upon loading the page?
>>
>>52039886
yeah, use angular.js
>>
>>52039886
What the fuck is a "neat" thing?
>>
>>52039880
I know, but it just seems common sense, all dynamically typed programming languages should do this.
>>
>>52038472
but GNOME is shit
>>
>>52039933
For me
"3" * 5 == 15
is the expected behavior for an untyped language.
>>
>>52039747
>a language like Typescript (but not JS, a real systems language) where types are optional to best take advantage of both cases.
That's objective-c

>That's overhead because the dynamic code above divorces types and methods.
That doesn't make it overhead.. What kind of "overhead" do you think this is in C++? It would be a little bit more verbose for C++, but not necessarily in other languages.
member __.iterate(t : Table) = pairs(t)
member __.iterate(t : List) = ipairs(t)
member __.iterate(t : Set) =
t |> Seq.ofSet
|> Seq.map (fun (key, val) -> k)

Would be the equivalent in F#. But this is of course compile time type safe. Is this less good compared to your version somehow?

>The miniature embedded dynamic language needed reflection implements is a pain in the ass.
I'm not sure what you're saying but Java and C# both have reflection. You could write the kind of dynamic code you wrong in Java or C# without any issues if you felt there was a reason for it.

>The compiler has to be very advanced to get around the type safety system
In Java or C# you just cast everything as an object, and bam, the type system is "off" and your code is effectively dynamic. People prefer to use the type system when it's provided for them though.
>>
>>52039913
non-trivial things, like web apps
>>
>>52039908
>use flavor of the month hipster.js framework #8324832
>>
>>52039886
yes, learn the whole ecmascript and code it yourself without frameworks
>>
>>52039951
For that, I think it would make more sense to use the unary operator.

"3" * 5 = "33333"

+"3" * 5 = 15
>>
>>52040013
>Anon reliving the PHP and JavaScript design and development experience
>>
>>52040013
>Use extra syntax for 95% of use cases
>Use reduced syntax for 5% of use cases

For what purpose?
>>
>>52039844
>there is no point in enforcing things like type arguments at runtime
but there use a point to enforcing at compile time.

>if something exists at runtime, fine, if it doesn't, crash
What about if you never want it to crash. What if certain things *should* always exist, and if they don't it's because there's a mistake somewhere in the code. These are bugs static typing make impossible to happen.
>>
>>52040104
Because it makes more sense, and you just pulled those numbers out of your arse.
>>
>>52040128
>but there use a point to enforcing at compile time.
>What about if you never want it to crash. What if certain things *should* always exist, and if they don't it's because there's a mistake somewhere in the code. These are bugs static typing make impossible to happen.
where did i claim the opposite again?
>>
>>52039853
>>52039933
I just found out, there is String.repeat()
>>
>>52040181
You didn't, but that's what the entire point of the thread of posts is. Dynamic typing being useless. No one's discussing what should or shouldn't be checked at run time.
>>
>>52040179
How often do you need to repeat a string exactly compared to multiplying two numbers in code?
If anything, 95% was conservative.
>>
>>52040183
This is why people look at you funny when you claim that you "need" operator overloading.
>>
>>52040210
I'm not the same anon, I was just saying
still... I'd prefer the python syntax, desu senpai
>>
>>52040183
Yeah.

And it looks hideous.

"3".repeat(5)

"3" * 5

Which looks better?
>>
>>52040210
What's the reason? I've never heard anyone say you "need" it. It's just super handy sometimes. Of course shitty programmers can write garbage with it.
>>
>>52040242
"3" "* 5
>>
>>52040191
>Dynamic typing being useless
again, if the script you are writing is simple enough so that you do not need correctness enforcement through type safety then a dynamically typed language has less overhead
the other point was that in regards to the simplicity of the interpreter vs the simplicity of the compiler, the dynamically typed interpreter is simpler
the op of the post i replied to claimed:
>generic functions and polymorphism is just as hard in dynamic languages as it is static ones
which i replied to because i don't think that's correct, atleast regarding the compiler/interpreter
the effort of maintaining correctness for generic functions/polymorphism or whatever is moved from the compiler into the brain of the programmer
>>
>>52039984
but angular was released in 2009
>>
>>52039939
no
>>
dynamically typed language:
let sq x = x * x; /// not type safe

statically typed language:
let sq x = x * x; /// type safe

any questions
>>
>>52040195
You multiply two numbers more, but usually, when you do it, they are of the same type, so you're asking the wrong question, anon.
>>
>>52039908
>search angular.js
>angularjs.org
>click on video
>gay ass song about angular.js
nope
>>
>>52040306
>>js related
>>gay
>surprised
>>
>>52040254
Because most people who find it handy will do shitty things with it.
If you're not able to work around not having overloading, you certainly wont write any good code with it either.
>>
>>52040292
I'm not the one using a language with implicit type conversion.
>>
>>52040279
>dynamically typed language has less overhead
How so? This was claimed, but never explained.

>the dynamically typed interpreter is simpler
Agreed. That was my point too. But this is of no benefit to the programmer targeting it. It's just easier for the developers of the interpreter. This is the only benefit to dynamic typing I can see.

>the effort of maintaining correctness for generic functions/polymorphism or whatever is moved from the compiler into the brain of the programmer
how so? Static and dynamic languages require equal thought from the programmer for this stuff. A static language will just tell you at compile time if you made a mistake.

see >>52039964
>>
>>52040318
>Because most people who find it handy will do shitty things with it.
not good programmers. bad programmers will shit the bed no matter what they are doing.
>>
>>52040242
Why the everloving fuck would you ever use a repeat method on a string literal?
It doesn't look half as stupid when you uses actual fucking vars like a normal person.
>>
>>52040318
Operator overloading is just syntactic sugar. It just makes your code shorter.
>>
>>52040354
>he hasn't joined the UFCS cult

m8 it's all fuckin rainbows over here
5.sqr.add(5).sqrt.writeln;
>>
>>52040306
>walk into sex shop
>find dildo
>wontsomebodypleasethinkofthechildren.avi
>>
>>52040354
I use it for indents
require 'logger'
require 'facets'
require 'terminfo'

class String
def wrap
columns = TermInfo.screen_size[1]
lines = self.word_wrap(columns).split("\n");
indents = lines[1..-1].join(' ').word_wrap(columns - 26).split("\n").map{|line| "#{' '*26}#{line}"}
indents.unshift(lines[0])
"#{indents.join("\n")}\n"
end
end

class Logging
def self.log
if @logger.nil?
@logger = Logger.new STDOUT
@logger.level = Logger::INFO
@logger.formatter = proc do |severity, datetime, progname, msg|
"#{severity} #{datetime.strftime '%Y-%m-%d %H:%M:%S'}: #{msg}\n".wrap
end
end
@logger
end
end
>>
>>52040354
See my meme star function, anon.

var star = function(str) {
var val = "\n"

for(var i = 0; i < str.length - 1; i++){
val += (" ".repeat(i) + ( str[i] + " ".repeat(str.length - (2 + i)) ).repeat(2) + str[i] + "\n");
}

val += str + str.reverse(1) + "\n";

for(var i = 2; i <= str.length; i++){
val += (" ".repeat(str.length - i) + ( str[str.length - i] + " ".repeat(i - 2) ).repeat(2) + str[str.length - i] + "\n");
}

return val;
}
>>
>>52040371
So you're saying everyone should have to read your entire project to establish when the + operator is actually plus and not something obscure?

How else will they know? Are you gonna document it every time? If not, when do you document it?
What if someone is reading one part using overloads but doesn't come across the few times you did document it?

The ends do not justify the means.
>>
>>52040415

>you shouldn't be allowed to overload operators
>you should be allowed to name your own variables, functions etc
>>
What exactly is operator overloading?
>>
>>52040411
Yes, lets change a language syntax so that making memestars is easier.
>>
File: ss+(2015-12-24+at+08.14.03).jpg (139 KB, 863x699) Image search: [Google]
ss+(2015-12-24+at+08.14.03).jpg
139 KB, 863x699
>>52039853
found the code monkey
>>
>>52039964
>That doesn't make it overhead.. What kind of "overhead" do you think this is in C++? It would be a little bit more verbose for C++, but not necessarily in other languages.
Programmer time necessary to implement the type abstraction. Obviously it's compiled out...

>In Java or C# you just cast everything as an object, and bam, the type system is "off" and your code is effectively dynamic.
It does so through the same type abstractions I was talking about. Just because you don't have to implement it yourself doesn't mean it isn't there.
>>
>>52040447
When an operator can do multiple things, usually depending on the type of data applied to it.
For example, in VB.NET:
2 = 2 ' = True
"2" = "2" ' True
a = 2 ' either assigns 2 to a or checks if a equals 2, depending on context
>>
>>52040415
you should only override + when the use of it will be obvious. Like creating a vector type, or a special numeric type.
>>
>>52040447
vector2 
a = {1, 1},
b = {0, 0};

a = a.add(b); // add is defined by whoever wrote vector2
//vs
a += b; // += is defined by whoever wrote vector2
>>
>>52040333
to be fair, i hadn't looked at ocaml so far, only at haskell and f#, and ocaml infers all the information i called to be redundant in my post about statically typed languages requiring more effort
i guess for nominally typed languages it's true that sometimes more effort to build the same small thing is required, but for proper structurally typed languages like ocaml, it doesn't seem to be an issue
>>
>>52040481
People should also only write 100% bug-free code :^)
>>
>>52038440
this pic is fucked up
>>
>>52040474
>a = 2 ' either assigns 2 to a or checks if a equals 2, depending on context

That's so fucking confusing.
One = should always be assignment.
Two == should always mean comparison.
I don't even want to know what the fuck === means in javashit.
>>
>>52040474
>when an operator can do multiple things
>(builtin operator with builtin types example)
what the actual fuck are you talking about
>>
>>52040494
how so senpai
>>
>>52040461
>Programmer time necessary to implement the type abstraction.
Type abstractions are made in dynamic languages too, they are simply only checked at runtime. You're not making anything new in a statically typed language. You might just need to write it a little differently so the compiler can know what the types are at compile time, instead of run time.
>>
I'm not even happy about * being overloaded in C++, now you guys want to overload + as well? Christ...

>>52040495
=== in JS is the same as == pretty much everywhere else. VB just likes to be extra retarded.
It gets bonus points for having arrays, properties, and functions ALL use () to be referenced. So if you have an array property with a constructor, good luck figuring out what the fuck you're supposed to call it with.
>>
>>52040428
If I see a variable, finding out where it is declared is not a problem.
The same goes for functions.

How the fuck does anyone know when you've used overloading or not, without trailing through the entire class?
>>
>>52040491
of course. You think they should write code with bugs?
>>
>>52040495
ignore him he doesn't know what he's talking about

operator overloading means the programming language lets you define how an operator works for a class
often it's gotta have a certain function signature (e.g. == returning a bool)

if you wanted to make a reference class, you could overload == to check by reference
>>
>>52040537
for example, you could write +,-,/,* operators for a vector class
so that it's
(vector_a + vector_b) * constant;
and not
vector_a.add(vector_b).times(constant);
or
vector_times(vector_add(vector_a, vector_b), constant);

normally languages don't support arbitrary operators (e.g. you can't just make up a random token like £*%"* and call it an operator)
>>
>>52040537
You're retarded. Operator overloading, just like function overloading, just means that the operator in question does multiple different things without explicit differentiation. Whether or not those overloads are part of the standard or are programmer-defined is irrelevant.
>>
>>52040571
Holy shit.

http://en.cppreference.com/w/cpp/language/operators
https://msdn.microsoft.com/en-us/library/aa288467(v=vs.71).aspx
https://dlang.org/spec/operatoroverloading.html
https://msdn.microsoft.com/en-us/library/dd233204.aspx

http://stackoverflow.com/questions/77718/why-doesnt-java-offer-operator-overloading
>>
>>52040586
Wow, how much of a retard are you?
Half your links prove me right, the other are explicitly only talking about programmer-defined overloading.

https://en.wikipedia.org/w/index.php?title=Operator_overloading&oldid=678336489
>In programming, operator overloading—less commonly known as operator ad hoc polymorphism—is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is generally defined by the language, the programmer, or both.
>>
>>52040571
However you're using "operator overloading", it's not how most people do
>>
>>52040415
You should always formally document overloaded operators.
CarFactory first, second, third;
first = second + third;

It's not always straightforward to understand why CarFactory can be '+' together. If you're going to do operator overloading, it's important to document the semantics of what it means.
>>
>>52040632
This guy gets it.
>>
>>52040632
So what is operator overloading as most people do it?
>>
>>52040484
all that effort to make your code two characters shorter. the "a = " is either not needed in the first case or missing in the second case or you're comparing apples to bananas
>>
>>52040631
>half your links prove me right
>here, look at this link you didn't fucking give

That's because operator overloading, 99% of the time a programming language mentions it, means the user defining an operator.

>>52040650
The user defining how the operator works for relevant types.


The fact that the operator depends on the type (and might work differently depending) is a given in any static language.
>>
>>52040632
Most people being retards who don't understand programming concepts doesn't mean that those concepts are somehow false.
>>
Daily reminder that the act of writing code is not coding, it is programming.

You are a programmer not a coder
You write code and You develop programs
>>
>>52040637
Car Factory shouldn't override +. If it's not already obvious what it does, it shouldn't the overridden. Just add a method to the class.

If it wouldn't make sense to name the method
CarFactory.sum(cf1 : CarFactory, cf2 : CarFactory)

does, then don't override +.
>>
>>52040680
What is the meaning of CarFactory.sum()? You still need to look in the documentation to find the details.
>>
>>52040655
Yeah, it could be:
a.addAssign(b);
Or if you're allowed symbols in your function names
a.o+=(b);
(in C++ you can manually call user defined operators - a.operator+=(b) )


>>52040661
>most people are wrong about this phrase
ok
>>
>>52038865
This
somebody explaiin
>>
>>52040553
>you can't just make up a random token like £*%"* and call it an operator
>PEP 465, a new operator (@) for matrix multiplication

POTTERY
>>
>>52040686
>What is the meaning of CarFactory.sum()?
my point exactly. If it's not obvious, then don't write it. You would never "sum" a car factory.
>>
>>52040698
Why the fuck don't python just use *
Jesus

But anyway, to anyone who doesn't like operators, the problem is the same as someone choosing a shitty name for a function.

The real potential problems with operator overloading:
- compiler figuring out what the hell is going on
- operator precedence
>>
>>52040495
:=
=
i think you mean
>>
>>52039036
gtfo to india
>>
>>52040711
So if you have to look in the documentation either way, there is no more of a problem than using overloaded operators.

I'm not advocating that we start overloading operators with wild abandon, I'm just saying that operator overloading is simply syntactic sugar.
>>
>>52040731
You shouldn't overload any operators in any non logical ways anyway.
>>
could someone explain this?

>3rd function take as arguments the name of the target, source, pointer to the element following the last element of the source
>>
File: 1444254238605.jpg (48 KB, 670x496) Image search: [Google]
1444254238605.jpg
48 KB, 670x496
What programming language is the most wu tang?
>>
File: imgur-2015_12_25-03:46:55.png (8 KB, 677x92) Image search: [Google]
imgur-2015_12_25-03:46:55.png
8 KB, 677x92
>his favorite programming language doesnt do this
>>
>>52040768
>I'm just saying that operator overloading is simply syntactic sugar.
Me too, but it should only ever be used when what it will do is obvious. Only if you would be able to write a function that sums two objects together, and your object is at least one of them. Anything else, and you should have a regular function.

CarFactory.sum() is not something that would exist in a real code base.
>>
>>52040801
cobol
>>
>>52040794
function pointer?
>>
>>52040804
prints out [12] ?
>>
>>52040804
>his keyboard doesn't have lambda and identity symbols on it
>>
>>52040778
so you disagree with data streams as they are overloaded with bit shifting?
cout << object;
stringstream(myobj) >> foo;
>>
>>52040825
cmon man, how else would you have packed that many symbols into one line
>>
i want to learn c# and f# in the abstract, but drinking alcohol and listening to trance music seems more appealing right now
>>
>>52040837
to real
>>
>>52040804
main = print 12

i just lifehacked your program
>>
>>52040837
do both. It will make both things more fun.
>>
>>52040830
not him
could've been done better f.am
not opposed to using operators in random ways to create DSLs (or obviously if you're writing a new language) but at least make it look right
>>
File: hrm.jpg (22 KB, 223x261) Image search: [Google]
hrm.jpg
22 KB, 223x261
>>52040830
>using data streams as an example of good overloading

Not sure if bait
>>
>>52040801
ruby
>>
>>52040812
still dont have a clue
>>
What's worse, node.js or python?
>>
how do you make blender render volumes
>>
>>52040804
>>
>>52040885
need less contrast, it's too hard on the eyes
>>
>>52040880
python is a langugae. Node.js is a server side web framework.

better to use node for web shit than python imo. At least you can share your code with your client side code.
>>
File: 2015-12-24_19-55-23.png (12 KB, 463x384) Image search: [Google]
2015-12-24_19-55-23.png
12 KB, 463x384
ok, this is where i left off

what should i learn next

btw, for all you trance peeps, there's an online radio end of year countdown event going on http://jellysite.es/AH/EOYC15/EOYC2015.png
>>
>>52040885
>x FOR x IN
>RANGE(1, 100)
> >=
> LAMBDA Y :
> ==
PFHAHAHAHAHHAHAHAHA
>>
>>52040890
Not irl/on my screen/with the rest of my screen.
Or are you memeing about the contrast in the haskeller's term
>>
>>52040804

I'm not sure what's less readable, Perl or Haskell...
>>
>>52040912
i am memeing
>>
>>52040909
you could write something like

[120 .. 330]
|> List.iter describePost
>>
>>52040911
:_, )
Funny, I learned about list comprehensions when learning Haskell, then abandoned it because it's used far less in the industry and has far fewer libraries available compared to Python. (This was when I was searching for a quick-to-write language, as I'd only used C and C++ prior.)
Haha right back at you.
>>
>>52040928
hmm. that ran but it didn't print anything. is it just being lazy?
>>
>>52040933
it's also not a shit language, in contrast with python
>>
>>52040942
That's not what I'm worried about, friend.
>>
File: 2015-12-24_19-59-53.png (19 KB, 431x766) Image search: [Google]
2015-12-24_19-59-53.png
19 KB, 431x766
>>52040928
>>52040941
nevermind, i am retarded and typed [120 .. 33]

anyone know where my extra new lines are coming from? or maybe it's just linqpad.
>>
>>52040941
eh... should have worked. Add it to the end of your code and re-run the whole thing
>>
>>52040950
what libraries do you need when you have eternal enlightenment?
>>
>>52040965
Hope that enlightenment can help you write libs real fast. Just as fast as I can use them, actually.

But idk tbqf, haven't used Python for more much more than a week, Haskell only a few days.
>>
>>52040885

So... this?
(1..100).select { |x| x >= 7 && (lambda { |y| y * y }).(x) == 144 }.each(&:display)
>>
>>52040955

{120 .. 330}
|> Seq.filter isDubs
|> Seq.iter describePost

could be fun too.

>or maybe it's just linqpad.
I'm guessing that. Can't think of another reason.
>>
i cant do the 3rd function, don't know what it means

  9    copy_ptrs - 3rd function take as arguments the name of the target, source, pointer to the element following the last element of the source
10
11 */
12
13 #include <stdio.h>
14
15 double copy_arr(double * target, double * original, int amount);
16 double copy_ptr(double * target, double * original, int amount);
17 double copy_ptrs(double * target, double * original, int last_el);
18 void print_arrays(double * to_print, char * message);
19
20 int main(void)
21 {
22 double source[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
23 double target1[5], target2[5], target3[5];
24 copy_arr(target1, source, 5);
25 copy_ptr(target2, source, 5);
26 copy_ptrs(target3, source, source + 5);
27 print_arrays(source, "Source");
28 print_arrays(target1, "Target1");
29 print_arrays(target2, "Target2");
30 print_arrays(target3, "Target3");
31 return 0;
32 }
33
34 double copy_arr(double * target, double * original, int amount)
35 {
36 int itr;
37 for (itr = 0; itr < amount; itr++)
38 target[itr] = original[itr];
39 return *target;
40 }
41
42 double copy_ptr(double * target, double * original, int amount)
43 {
44 int itr;
45 for (itr = 0; itr < amount; itr++)
46 *(target + itr) = *(original + itr);
47 return *target;
48 }
49
50 double (*copy_ptrs)(double * target, double * original, int last_el)
51 {
52 int *ptr, itr;
53 ptr = target;
54
55
56 return *ptr;
57 }
58
59 void print_arrays(double * to_print, char * message)
60 {
61 int itr;
62 printf("\n %9s: ", message);
63 for (itr = 0; itr < 5; itr++)
64 printf("%.1lf ", (double)to_print[itr]);
65 putchar('\n');
66 }
>>
File: 2015-12-24_20-05-43.png (23 KB, 441x644) Image search: [Google]
2015-12-24_20-05-43.png
23 KB, 441x644
>>52040995
nice
>>
>>52040858
I like this style. It's easier than C polyvariadic printf style.
>>
>>52040990
ruby and python are so similar in my head
>>
>>52041015
>222
>dubs

fixit m8
>>
>>52040999
and?
>>
>>52041015
and a little intro to function composition would be
{120 .. 330}
|> Seq.filter (isDubs >> not)
|> Seq.iter describePost
>>
>>52040915
not the other anon, but, how is that unreadable? that looks like math notation
>>
>>52041018

Ruby was designed with a number of influences, one of which being Python.
>>
File: imgur-2015_12_25-04:07:33.png (29 KB, 712x195) Image search: [Google]
imgur-2015_12_25-04:07:33.png
29 KB, 712x195
Are you fags even trying?
>>
>>52041024
I managed to get the first 2 function (copy_arr and copy_ptr), but I don't know what they meant by the 3rd one
>>
>>52041044
is that in-place?
>>
>>52041051
ok and?
>>
>>52041063
and what?
>>
>>52041017
You'll never realise how much you love printf() until you use a language that either doesn't have it or doesn't implement it properly
>>
>>52041076
well you're too stupid to get the 3rd question but what of it? are we supposed to symphatize with your poor soul or what?
>>
>>52040999
do not make copy_ptrs a function pointer wtf
>>
>>52041024
>>52041063
>>52041085
I think he wants us to do his homework or something
>>
File: 2015-12-24_20-13-11.png (26 KB, 477x758) Image search: [Google]
2015-12-24_20-13-11.png
26 KB, 477x758
>>52041023
done.

i have a scaling problem now, it doesn't detect quads or quints and i don't want to use the same strategy for those.

i need some sort of lookup table like
2 => dubs
3 => trips
4 => quads
5 => quints

and to build my logic around that
>>
>>52041037
>
|> Seq.filter (isDubs >> not)

I see that that works, but the >> notation is not intuitive to me at all
>>
I wanted to explore the idea of a meme app, so I built a meme except I wanted to do it without thinking about the stuff that matters.

It uses meme as the meme plus meme, meme Gateway, and memeDB for the server-like stuff. It also uses meme and meme, two official meme libraries.

I plan to post it to the meme to ask for feedback on my use of meme -- what I could have implemented more simply. Waiting until I finish the setup guide before posting it.

In general, I've been loving meme. It's really simple and quick to get started, but as you get deeper you find that many subtle design decisions were well thought out.

EDIT: This is my first venture in meme frameworks, having previously been overwhelmed by the learning curve of meme, meme, and meme.
>>
>used c++ throughout college
>switched to c# afterwards, havent seen any c++ in years
>refreshing on c++ for a project im supposed to maintain
>mfw i remember how unnecessarily convoluted and complicated c++ is
>>
>>52041172
c++ is dogshit
>>
>>52041149
(isDubs >> not) X
or (isDubs >> not)(X)

is the same as

not(isDubs(X))
>>
>>52041149
>>52041204
intuitive way of thinking about it is that it puts the left function inside the right function
>>
>reading f# book
>"Because tab characters can indicate an unknown number of space characters, they are prohibited in F# code."

my niggas.

meanwhile, python 2 silently converts tabs to 8 spaces. python 3 is smart, but still.
>>
>>52041149
>> is the function compositor. It basically just glues two function together.

So imagine you have
let isNotDubs =
fun isNotDubs i ->
isDubs i //returns a boolean
|> not //flips the value a boolean

you can make this short with
let isNotDubs = isDubs >> not


Not something i use often, but is sometimes really nice.
>>
>>52041172
Literally never any use for C++. If you want low level, you use C, if you want higher level, you use C#
>>
>>52041250
>python silently converts
maybe your shit ide lmao
>>
File: 2015-12-24_20-29-07.png (37 KB, 1617x209) Image search: [Google]
2015-12-24_20-29-07.png
37 KB, 1617x209
>>52041267
ok, it's a little smarter but not very much.
>>
>>52041252
>C#
>higher level

oops
C is quite close to F on the keyboard
perhaps your finger slipped
>>
>ocaml first class modules
wtf am i reading?
And I thought monadic pipe endo-metafunctors were fly.
>>
>>52041282
Visual Studio (2015, not sure about earlier) when editing F# documents will automatically do spaces when you press tab
>>
>>52041250
If the person used tabs correctly, then it doesn't fucking matter how many spaces they represent.
That's the point your mongoloid, you get to fucking choose.

You're as bad as iOS users, too afraid to spend more than 5 seconds configuring an app.
>>
>>52041040

I actually find a lot of mathematical notation to be rather nonsensical compared to the kinds of notation used in most modern programming languages. Further, I should note that the use of the arrow operator in x | x ← [1..100] just feels off. Generally, a left arrow is either a reverse implication, or an assignment. If one wants to suggest that x is an element of [1..100], then the ∈ symbol should be used. Not that this is in any way more readable than the word "in".
>>
>>52041252
C++ is faster than C while also being higher-level.
>>
>>52041303
>C++ is faster than C
Yup, and santa is real, and the moon is made of cheese!
>>
>>52041303
java.bait.OutOfBoundsException
>>
>>52041250
Absofuckinglutely disgusting, I didn't know about that. That's it, F# belongs in the fucking trash and I'll legit never even try it.
>>
>>52041336
you still use tab characters? shaking my head to be honest family.
>>
>>52041331
>>52041333
Lmao butthurt cmen. Can't spell cuck without c!
>>
>>52041336

>>52041292


you can also switch to verbose F# where you have a whole bunch of "done" everywhere but indenting doesn't matter
>>
partial application is so cool

addTwoNumbers x y = x + y
adds2 = addTwoNumbers 2

Prelude> adds2 4

then you literally just copy paste what adds2 is equal to and you get
addTwoNumbers 2 4

genius
>>
>>52041250
meanwhile, gofmt does the formatting for you

>>52041298
I loved mathematical notation more than I love the mess that is programming languages, pseudo-code, etc. and I haven't learned anything about functional programming. perhaps I should try it...
>>
>>52041346
>I can shitpost all I want, nobody will ever call me out on my bullshit
>oh fuck, somebody noticed!

Go ahead and prove that C++ is faster, we'd all love to see evidence.
>>
>>52041353
Oh yeah? That's actually cool. I take back what I said, I might just try F#.
>>
>>52041298
I like reading <- in list comprehensions as ∈, or "is an element of."
>>
File: aes.png (31 KB, 250x156) Image search: [Google]
aes.png
31 KB, 250x156
I'm making a command line password manager using AES encryption. Is it acceptable to use the master password as the AES key, or should I be adding a salt or something to the key? If so, then if the master password is longer than the maximum AES key size (32 bytes), is it acceptable to truncate it?
Thread replies: 255
Thread images: 24

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

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.