[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]

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: 331
Thread images: 44

File: pair_programming2.jpg (298KB, 800x650px) Image search: [Google]
pair_programming2.jpg
298KB, 800x650px
This is /dpt/, the best subreddit of /g/

Pair programming edition.

In this thread:
r/programming
r/compsci
r/ReverseEngineering
r/softwaredevelopment

/!\ ** Read this before asking questions ** /!\

http://mattgemmell.com/what-have-you-tried/
http://www.catb.org/~esr/faqs/smart-questions.html


What are you working on?
>>
File: 1468472224634.jpg (61KB, 990x557px) Image search: [Google]
1468472224634.jpg
61KB, 990x557px
>muh lambdas
>muh monads
>muh higher kinded types
>muh generics
>>
>>60389392

>Hating on lambdas
>Hating on generics
>>
>>60389392
>Shitkell
into the trash it goes
>>
File: 1494332105752.jpg (733KB, 3702x2198px) Image search: [Google]
1494332105752.jpg
733KB, 3702x2198px
>>60389392
>muh generics
>>
Is Nock good for anything?
>>
>C++
https://www.youtube.com/watch?v=rWDNwN0h0LM

>python
https://www.youtube.com/watch?v=rkcXRBhYZHU


>C++
https://www.youtube.com/watch?v=MZIv6WtSF9I

>python
https://www.youtube.com/watch?v=qFl-Q21MzmQ


>C++
https://www.youtube.com/watch?v=1CpjRMICXNM

>python
https://www.youtube.com/watch?v=IIAWs3_Hgtc
>>
>>60389461
>C++ fag getting insecure over python
Times must be really hard
>>
> Using traits for the first time in rust be like holy shit inheritance never again
>>
>>60389562
>Literally just like Java interfaces and abstract C++ methods
>>
File: 1410792416378.jpg (266KB, 640x640px) Image search: [Google]
1410792416378.jpg
266KB, 640x640px
What is the language of the future?
Go
or
Rust
???
>>
>>60389633
C++
>>
>>60389633
Rust
>>
>>60389643
>C++ fags having to fly out of nowhere to stay relevant
Times must be hard. I mean it never even could compete with C with all those bells and whistles how can they compete now?
>>
>>60389657
No.
>>
>>60389633
But neither of those are functional languages.
>>
Normal thread:

>>60389695
>>60389695
>>60389695
>>
>>60389460
pls respond
>>
>>60389461
>comment is 90% youtube links
>>>/trash/
>>
>>60389721
kys
>>
>>60389681
>>60389477
kek
>>
>>60389633
i doubt we will have a language to rule them all like c or java were, especially now that the available tools allows anyone to build his own programming language without too much difficulties.
>>
What do you guys think of Scala? It seems pretty mature by now, being tied for 11th most used language in the Redmonk rankings and a large number of big libraries like Akka and Spark. It can compile to the JVM, to LLVM, or to JS. It's big enough that I see jobs in it pop up even in the backwater where I'm from.

It looks like something I should work on learning. It has a nice balance between monads and employabillity.
>>
File: hYMIItH.png (142KB, 511x564px) Image search: [Google]
hYMIItH.png
142KB, 511x564px
>>60389783
https://movio.co/en/blog/migrate-Scala-to-Go/
http://jimplush.com/talk/2015/12/19/moving-a-team-from-scala-to-golang/
>>
File: 1212237702.jpg (50KB, 629x821px) Image search: [Google]
1212237702.jpg
50KB, 629x821px
>>60389771
>available tools allows anyone to build his own programming language
retarded or just trolling?
>>
>>60389783
Scala is so 2010.
Use F# for that matter.
>>
>>60389771
>a language to rule them all like c or java
>A language
>Lists two languages that still exist and are widely used
>>
>>60389816
c ruled from the end of 70's to 95
java ruled from 95 to now (thanks to the android platform)

>>60389812
have you seen how many usable programming languages have flourished these last 10 years?
>>
File: 1327868411054.png (65KB, 210x251px) Image search: [Google]
1327868411054.png
65KB, 210x251px
>tfw you will never be one of the few people that created really ground breaking algorithms over 20 years ago
>>
Should I learn C++
>>
>>60389878
new technology need new algorithms. today hot waters are AI, Enhanced/Virtual reality, Computer vision
>>
>>60389930
Better question: can you?
>>
Write a function to determine the number of dimensions of a given array
dim(["lka", "chu"]) == 2 //char[][]
dim([]) == 0
dim(['s', 'q']) == 1 //char[]
dim([[21, 22], [387]]) == 2 //int[][]


How will C tards ever recover? Let's find out :^)
>>
Anyone here who did Bluetooth pairing with NFC before?
I am somewhat confused in how to set it up.
I have a TI CC2541 for the Bluetooth part and in the pairing I don't want to have to do traditional BLE handshaking.

I found this document describing the idea.
http://members.nfc-forum.org/apps/group_public/download.php/18688/NFCForum-AD-BTSSP_1_1.pdf

I'm confused as to how the NFC and Bluetooth part work together.
>>
>>60389681
>/dpt/ being a measure of what's relevant
enjoy your reddit-tier circlejerk
>>
>>60389964
>determine the number of dimensions of a given array
Why would you need such a function? Great example for a problem no on ehas ever encountered in the real world.
>>
>>60389734
who are you quoting?
>>
File: Screenshot_20170514-112454.png (58KB, 1080x482px) Image search: [Google]
Screenshot_20170514-112454.png
58KB, 1080x482px
>>60389964
Those empty square brackets look like the Unicode missing character symbol.
>>
>>60390062
>:^)
>>>/v/
>>
>chilling in javascript

typeof NaN

it's
'number'


not gonna lie, xded here for a bit
>>
>>60389813
I don't care much about how new something is. I care about whether it is good enough to build stuff with, and whether it can get me a job.
>>
Reminder that if you can use a language to implement (a -> a) more than one way then it's trash.
>>
>>60390535
NaN has a definition in IEEE 754

NaN has always been a float.

Since float is the only numerical type is JavaScript they just call it number.
>>
>>60389783
>big libraries like Akka and Spark
Both of those libraries are absolute garbage.

>a nice balance between monads and employabillity
It's a toy language. The moment you want to do anything non-trivial with monads you end up overflowing the stack, so you have to trampoline everything, resulting in a massive performance penalty.
>>
>>60389797
Yes, I imagine if your team is full of retards then they'll prefer to use a language designed for retards.
>>
>>60389332
Daily reminder that strictly typed languages are legacy garbage that does nothing but slow down development time and needlessly increase comlexity
>>
Is there ever a reason to have a static method with the same signature in a derived class?
>>
>>60389633
Ruby
>>
File: C9Kso0SWAAAsmb0.jpg:large.jpg (133KB, 1394x884px) Image search: [Google]
C9Kso0SWAAAsmb0.jpg:large.jpg
133KB, 1394x884px
Remember this whenever you're writing Go. It's a language designed for people who aren't good enough to use other languages.
>>
>>60390684
https://www.youtube.com/watch?v=3U3lV5VPmOU
>>
I learned that other languages do not allow you to recast things as different types, literally cucking you out of neat features like type punning and type generics.

How do people deal with this shit?
Why would you willing use a language that enforces it's "best practices" on you?
>>
File: 1463300878912.jpg (11KB, 255x191px) Image search: [Google]
1463300878912.jpg
11KB, 255x191px
>>60390709
>literally made for retarded codemonkeys
I like how gofags always ignore this
>>
>>60390733
Because that's the whole point of having types at all?
>>
>>60389633
Neither.

It's C++ and LISP
>>
>>60390751
types are just a compiler directive so it can know how to deal with pointer arithmetic and struct member names.
>>
>>60390733
If you can view an A as a B, then prove it by providing a function from A to B.
>>
Is c faster for algorithms and easier to learn than c++?
>>
>>60390769
Oh and, operator overloading for arithmetic between different types of numeric representations, such as int to float, or struct assignment, etc.
>>
>>60390769
No they aren't.
>>
>>60390779

>Is c faster for algorithms
Kinda

>easier to learn than c++?
Definitely.
>>
>>60389332
where can I get a loli like that that will watch over me?
>>
>>60389392
>""generics""
What is a "Generic"?
>Why would you willing use a language that enforces it's "best practices" on you?
How can my own language enforce its "best practices" on me? That doesn't make any sense.
>>
>>60390825
little sisters are a meme
>>
>>60390797
>>Is c faster for algorithms
>Kinda
Dangerously wrong. Go might be a better language for your skill level.
>>
>>60390754
>arithmetic between different types of numeric representations
Fuck off.
>>
>>60390797
t. underage retard
>>
>>60390841
>>60390859
C is faster on average especially compared to idiomatic modern C++
>>
>>60390772
∀ a b : Type, a -> b
>>
>>60390903

Wrong.
>>
>>60390903
You are dumber than the average anon especially if compared to smarter anons
>>
>>60390917
>>60390939
mmk

>http://benchmarksgame.alioth.debian.org/u64q/cpp.html
>>
>>60390903
Who said anything about using idiomatic modern C++?
>>
>>60390995

It's faster and safer than classic C++.
>>
>>60390915
Can you implement it?
>>
>>60391015
Who said anything about using classic C++?
>>
>>60390949
what if i told you those c programs are also c++ programs
>>
>>60390995
>he writes C with classes
>he thinks he writes C++
>>
>>60391055
what if i told you those C++ programs could also be printed and used as toilet paper?
>>
>>60390772
do you mean something like this?
B AtoB (A a)
{
return a;
}
>>
>>60391076
also, the c++ regex uses boost while the c one uses pcre. it's more a test about boost vs pcre than c++ vs c.
>>
>>60391022
f : ∀ a b : Type, a -> b
f = f
>>
>>60391124
Congrats on your inconsistent language.
>>
I'm derping around with quantum search algorithms.

Fun fact: a quantum computer can do binary search in log_3(N) operations instead of log_2(N) operations.
>>
>>60391144
Oh, and if you haden't heard about that already, quantum computers can search for a given element in an unordered array in O(sqrt(N)) operations instead of O(N).

I just found an algorithm to find the median of an array in O(sqrt(n) log(n)) operations.
>>
File: 1466169725690.jpg (214KB, 600x620px) Image search: [Google]
1466169725690.jpg
214KB, 600x620px
>>60391137
That's not written in my language though.
>>
I've started learning C++ recently, and made a space invaders.
But could someone explain something to me?

Why is it, that my program shows glitches and segfaults due to an (unrelated?) memory leak on Linux, but shows no such behaviour on Windows?
>>
>>60391281
Congrats on using an inconsistent language, then. I suggest you apologize to your mother, considering what day it is today.
>>
>>60391348
You're probably overwriting your null terminators or something and writing past the end of the array.

Are you initializing your arrays and variables?
Because C++ doesn't do it for you.
>>
>>60391348
linux is shit, more news at 11
>>
>>60391348
Because you wrote it in C++ and not Idris.

>>60391376
If you don't like anime, why are you here?
>>
>>60389633
Russian.
>>
>>60391348
run it with valgrind
>>
File: 1493976753469.png (372KB, 865x705px) Image search: [Google]
1493976753469.png
372KB, 865x705px
>>60391366
>Congrats on using an inconsistent language
I wouldn't use such a language. I'm not interested in something which can prove any proposition.
>>
>>60391348
POST CODE
post code
POST code
post CODE
>>
>>60391446
90210
>>
>>60391384
Every object that needed to be declared either gets created in a constructor or set as NULL there.
I don't initialize my vectors or base types.
Finding and fixing the memory leaks removes any trace of glitches.

>>60391387
It took me half an hour to set it up on Linux, took me half a day on Windows.
Not to forget the shit I had to undefine because some compiler shit fucked with a "createWindow" function I wrote.

>>60391418
Can't really get the hang of Valgrind, most things it finds are leaks in the SDL library I'm using.

>>60391446
Don't have any problems right now, and the leaks came from unrelated objects. It just made me wonder.
>>
>>60391521
>Can't really get the hang of Valgrind, most things it finds are leaks in the SDL library I'm using.
Yes. That's fucking annoying.
>>
>>60391537
there's no need to free when quitting the program it's just cargo cultism to argue otherwise
>>
>>60391521
post the damn source so we can analyze it you mong
>>
File: dpt.png (378KB, 1450x1080px) Image search: [Google]
dpt.png
378KB, 1450x1080px
rolling. LOL!

(((won't do it anyways, because I am a lazy fuck ;-) )))
>>
>>60391554
this but what about pthread objects, pipes, file descriptors, isn't it good practice to destroy/release them?
>>
>>60391569
Holy fucking shit I'm not gonna post the entire source on here because that's pointless since everything's fine now.
>>
>>60391554
When encouraging bad coding practice became mainstream?
>>
File: 1493812976016.jpg (131KB, 501x501px) Image search: [Google]
1493812976016.jpg
131KB, 501x501px
>>60391615
POST IT!!!!!!!!!!!!!!
>>
>>60391635
                                                                                                                                                         




no
[\code]
>>
>>60391705
fuck
>>
>>60389633
Crystal
>>
>>60391851
lel, never.
>>
>>60389771
>the available tools allows anyone to build his own programming language without too much difficulties
Then you have to define and program the programming language, support it over various platform types and different scenarios, document it, and prove that it has a significant advantage over anything else currently available
>>
>>60390709
"Oh. We made a hiring mistake and hired a retard. Let's put him in our Go team."
>>
>>60391858
Why not?
>>
>>60389633
Both are good for different use-cases.
>>
>>60391348
You probably have undefined behaviour somewhere. The thing Rustfags keep yappering on about.
>>
>>60391917
if ruby failed to become the language of the future, how crystal will ?
>>
>>60391215
>I just found an algorithm to find the median of an array in O(sqrt(n) log(n)) operations.
Impossible
>>
I just found out about this: https://itsfoss.com/nodeos-operating-system/

I don't want to live on this planet anymore.
>>
>>60391633
deallocating when you know the program is exiting is a cargo cult. you're just making the program slower.
>>
Every language but C and Lisp are memes.
>>
>>60392006
It's perfectly possible, if you have a quantum computer and can get the element at index n in O(1) time, where the index parameter is allowed to be a superposition of different inputs.
>>
>>60389392
>lambdas
Useful convenience
>monads
FP masturbatory cancer
>higher kinded types
100% useless
>generics
Very very useful
>>
>>60391988
Ruby largely failed because of its performance problems. The syntax itself is concise. Being able to run something like Kemal means that you can build a webserver without having to include something like Rails as well. There's way less overhead and significant performance gains that way
>>
File: camelia-logo.png (56KB, 261x243px) Image search: [Google]
camelia-logo.png
56KB, 261x243px
>>60389633
Perl 6
>>
This oop crap is pissing me the fuck off. Every other concept ive had no problem learning except oop.
Fuck.
>>
>>60392127
>meme
>>>/v/
>>
>>60392099
This is actually pretty neat if it supports webassembly.
>>
>>60392228
how can you struggle with OOP? it's just structs (objects) with functions (methods) and function prototypes (interfaces)
>>
>>60392228
what exactly is your problem?
OOP code monkey here
always hear people complaining, happy to help
>>
>>60392125
I totally agree. That's why I always exit my application with that code:
  kill (getpid (), SIGKILL);

That's faster.
>>
>>60392228
OOP is applicable to most of the problems you will likely face. What's the trouble with it?
>>
>>60392228
You might be retarded
>>
>>60389633
Go has a lot more traction than Rust does because it's basically fractionally-slower-C/++ without having to deal with memory management. It's main issues right now is how it handles dependencies and when it has to make calls to C bindings, which is slow as shit. Natively written Golang is fast as titties and in some instances uses even less memory than comparable C code
>>
>go
>haskell
pffffthahahahahaha
>>
>>60392163
Blub paradox
>>
>>60392250
>>60392248
>>60392259
Inheritance makes no sense to me and none of it is sticking and I've been watching videos and trying to understand it but i just can't understand it
>>
>>60392316
post the code from both
>>
>>60392319
Yep, definitely retarded
Sorry anon
>>
>>60392323
>print odd numbers from 1-99
>asks for code
i'm on /g/ alright lmao
>>
>>60392353
do it you faggot
>>
>>60392319
>Inheritance makes no sense to me
ok

Try to explain to us what you think you know about inheritance at this point. Or the part that doesn't make sense to you.
We will help from there.
>>
>>60392319
it's like function overloading
>>
>>60392319
learn inheritance and then strive to use it as little as possible.
>>
>>60392353
The C code could be a literal chain of print statements you fucking mong, no properly written program should take 8-10MB to loop over integers and mod2 them
>>
>>60392319
>Inheritance makes no sense
Class Animal has a method Talk() and property Legs.
Class Dog inherits from class Animal and thus has a Talk() method and Legs property available. It can stick with the default (i.e. what it inherited) or it can re-define what that method does and what the value of Legs is.
>>
>>60392316
300-700ms is a huge amount of time for the task for a non-VM based program, post code faggot
>>
>>60389633
python
>>
>>60392319
Imagine that you're making a video game, like Zelda. In this game, you want to make the player, enemies, NPCs, and items. All of these four things have a lot in common: they exist on the game's map, they can be interacted with, they may or may not move, they have sprites and/or animations, etc.

It would probably make sense to create a "Thing" class that can hold X/Y coordinates, statuses, sprite information, and so on. From this, you can create classes for "Player", "Enemy", "NPC', and "Item". Now you have these four different classes that can do things differently (items give healt and magic, enemies have attacks, NPCs say stuff, player is bound to user input). But for how they're represented in the game, there are common things between them that you can reference consistently
>>
>>60389633
Rust.
Go is dead by design.
>>
>>60392421
is this bait??
>>
>>60392541
is this bait??
>>
>>60392571
is this bait??
>>
>>60392541
>>60392571
>>60392586
no
>>
>>60392421
the code for c++/go was literally
for i = 1; i <= 99; i +=2
the code for haskell was contributed by some anon and was the simplest and easiest way to achieve this task in haskell
>>
>>60392631
this is bait
>>
>>60391884
>Then you have to define and program the programming language, support it over various platform types and different scenarios, document it, and prove that it has a significant advantage over anything else currently available

>Implying many programming languages do all these things.
>>
>>60389455
I think you missed print_sum_floats
>>
>>60392653
They're certainly lightyears ahead of someone building yet another meme language
>>
>>60389332
https://www.youtube.com/channel/UCfV36TX5AejfAGIbtwTc7Zw

>>60389633
>language of the future
does such a thing even exist, or is it predictable at all? who could have said "the language of the future is JS" some 10 years ago or so?

devs will just follow trendy shit imposed by big tech companies, just because these companies have the $$$, and devs want $$
>>
>>60392649
[1,3..99]
>>
Hrm... this actually looks kinda nice in Rust.

use std::mem::transmute;

pub fn fast_inv_sqrt(num: f32) -> f32 {
let half = num * 0.5f32;
let magic = 0x5F3759DFi32;

unsafe {
let i = transmute::<f32, i32>(num);
let f = transmute::<i32, f32>(magic - (i >> 1));
f * (1.5f32 - (half * f * f))
}
}
>>
>>60390709
>>60390735
>>60391912
brilliant there means Go itself. perhaps you are the retards after all
>>
>>60392785
Indeed. Explicit where it needs. Why does it have to be unsafe though ? f32 and i32 are obviously of the same size and they aren't pointers, so this isn't unsafe segmentation-wise is it?
>>
>>60391348
>>60391521
>hey, I was convinced by random "elite" programmers in /dpt/ that I should learn C++, and now my code is all fucked up. can you tell me, "elite coders" what to do pls?
>>
File: 124579312649.jpg (35KB, 503x595px) Image search: [Google]
124579312649.jpg
35KB, 503x595px
>>60392916 (You)
>>
>>60392996 (You)
>>
File: IMG_0271.png (61KB, 750x1334px) Image search: [Google]
IMG_0271.png
61KB, 750x1334px
>>60389332
Is the edx Harvard cs50 course any good? Is it worth it if I'm skipping the lectures? They're really long and slow paced, but the notes don't seem very thorough.
>>
>>60390754
Nope.
It's C and Common Lisp.
>>
>>60391554
I always free on exit, makes using valgrind a lot simpler.
>>
>>60391348
(Disclaimer: most of my experience is on libre software-based operating systems)

There's such a thing as "managed code" in Windows C++ I believe, where you can run C++ over the .NET runtime more-or-less, so maybe depending on how you've set up the program on Windows, said runtime softens the edges of those misplaced memory accesses you're committing?
>>
File: Screenshot-2016-02-17-07.52.50.png (172KB, 1236x572px) Image search: [Google]
Screenshot-2016-02-17-07.52.50.png
172KB, 1236x572px
s/scala/functional programming language/
>>
PCMSK2 |= (1<<PCINT18);


what did he mean by this?
>>
>>60393165
Set the PCINT18th bit in PCMSK2
>>
guys i need your help.

How do you implement the state pattern for each object, but the state are globally.

I have

Drawobject1 and drawobject2. Both implement event handling methods like clicking/rightclicking/dragging etc.. But it's depending on the global state. So there is no underlying differing states between object. If the state is currently in selection mode, all object will delegate their handling to the "selection state class".

So do you need a global state manager or something to set the state for each object in the scene, similar to the observer pattern? Then you can call currentState.Click() from within the objects;

What I now have is the state object that has a list of functions for each type of drawobject.

//global variable state


state = new State1;

class StateManager()
{
state1 = new State1;
state2 = new State2;
...
currentstate= state1;
}


class State1{
drawobject1Click() {}
drawobject1DoubleClick() {}
drawobject1RightClick() {}
drawobject1Hover() {}
drawobject1MouseLeave() {}

drawobject2Click() {}
drawobject2DoubleClick() {}
drawobject2RightClick() {}
drawobject2Hover() {}
drawobject2MouseLeave() {}

drawobject3.... etc.

}

//state2, 3, 4... etc implement the same list of functions as above

class Drawobject1 {
Click() { state.currentState.drawobject1.Click();
}

class Drawobject2 {
Click() { state.currentState.drawobject2.Click();
}

//etc. for each class it willl refer to their respective function in the state class

as you can see it gets bloated as fuck. Any tips?
>>
>>60393260
>pattern
don't
>>
>>60393267
what do i do then?
>>
just letting you know that Chapel is better than Go in every way.
>>
>>60392922

Any usage of the transmute function is unsafe according to the Rust compiler.
>>
Planning to create a webkit based linux framebuffer browser with tabs, decent UI controls and possible html5 playback / camera support

After that I should be done with X, I only need the browser and vim and the compiler / interpreter
>>
>>60393324
>Planning to create a webkit based linux framebuffer browser with tabs
not really sure, I don't have any examples, but I think this exists already...
I hope you care about security when doing this, webkit sucks in that respect. sadly, chromium is a good alternative...

I wish I could do what you'll do, btw. I also don't really need much more than that
>>
Why are side effects in Haskell so unpredictable?

foldr (\x _ -> print x) (return ()) [1,3..99]


prints this:
2


while this:
foldr (\x y -> print x >> y) (return ()) [1,3..99]


Prints this
1
3
...
99
>>
>>60393526
Ah sorry, the first one prints 1, not 2.
>>
>>60389392

dude, I just make cute webpages and people thrown money to my face. I am happy with that. I will never be a researcher, create my own compiler or new language or make intensive calculations that will need a server farm to process them.
>>
File: url.png (2KB, 267x189px) Image search: [Google]
url.png
2KB, 267x189px
>>60389392
>>60389431

no bully u fucklords
>>
>>60389964
>How will C tards ever recover? Let's find out :^)
>>60390027
>Why would you need such a function?
>>
>>60390785
one for trolling this meat thread
>>
>>60393526
my guess is that only the IO result that the function returns is calculated, i.e.
print 1
since all the other
print n
s are discarded by the folding function in the first fold, whereas they're all chained together in the second
>>
>>60393526
There aren't any side effects.
Haskell is pure.

You are constructing an IO action.
You make a function that takes a value, and an IO action as parameter, and you choose not to sequence that second action? It doesn't become a part of the result action
>>
>>60391079
it might have to be done with a primitive representation of the A and B types
>>
>>60393526
>>60393762
In fact, it's almost exactly the same as doing this in an imperative language:

void myFunction();
void myOtherFunction();

void main() {
myOtherFunction();
}
// why doesn't myFunction get executed?
>>
>>60391215
so its got tumblers like a locking mechanism built in. just use a hash with unique primes and say that instead of the prior.

the tech isnt the important part. its the time saved.
>>
>>60393526
Haskell is too lazy to do what needs to be done unless you explicitly tell it to.
>>
>>60390027
>Deflection
So this ... is the power of a C tard
>>
>>60393817
or a sieve iter at each iteration rather than a single value. all <unique value> at a cost of O(1), for all values and then use the product of log at that state of the iterative process.
>>
>>60393526
has absolutely to do nothing with side effects.
consider following:
foldr (\x y -> show x) [] [1,2,3,4]

prints just "1" as well.
your function takes two thigs, discards the right one and returns the left one, thus all the previous actions will be thrown away
>>
File: 1118full-ashley-benson.jpg (215KB, 1118x1118px) Image search: [Google]
1118full-ashley-benson.jpg
215KB, 1118x1118px
Should i learn java's awt and swing classes completely? I know the basics and i want to develop things for android and most of my knowledge going to be useless when i use android frameworks.

What should i do?
>>
>>60390709
>Go is shit

What do I learn next then? I got Java, C, and C++ rn

Python?
>>
>>60394087
Rust 2bqh
>>
>>60389633
Neither. Though if I had to pick one it would be go, at least it fills a niche. Rust is a shitty version of c++
>>
>>60394121
C++ is a shitty version of Rust*
>>
>>60394133
Rusts compiler performance will not come close to c++ in the forseeable future. And no one is doing anything creative with rust. No one important actually gives a shit about that language
>>
>>60394026
they are useless. I also know some of the basics of awt and swing, i even started learning Fx. But you dont need them for android programming (atleast so far). I also started learning android about at 2 weeks ago, so my advice isnt the best.
>>
linter
tokenizer
parser
interpreter
>>
>>60394026
if your trying to make a game or whatever, thats what im guessing your learning swing/awt for, there are already good gaming libraries for android like libGDX
>>
>>60389964
Depending on how the array is constructed in memory, this is logically impossible.
If we're talking about C or C++ style arrays, it is outright impossible, because the data is contiguous and linear without any headers, and the dimensions are implicit in the code being run.

If this is Java, then Java simply uses an array of pointers past the first dimension, then you can use a depth-first-search algorithm to count the number of pointers.
>>
>>60394257
What i need for android development?
Looks like all i need is get used to java syntax. Did android really use any libraries from java?
>>
>>60389455
tfw people do more advanced programming than summing all the primes below 7,000,000
>>
>>60394287
Yes i know i will use libgdx but i am not that part yet. I am just making simple games. Is LibGDX uses swing?
>>
>>60389332
/dpt/ is a mark of how no one here knows how to program more than a shitty fizzbuzz program or sum the primes below 7,000,000.

everyone here is just bitching on how C++ is bloated and how Rust will cure cancer.
>>
File: Wgt2Gcn.gif (2MB, 500x282px) Image search: [Google]
Wgt2Gcn.gif
2MB, 500x282px
>tfw you master C++ templates
>>
File: 1492898994584.png (44KB, 657x527px) Image search: [Google]
1492898994584.png
44KB, 657x527px
>>60392319
Ill explain this to you, pay attention retard:
-You are trying to model a Ford Mustang Gt, Toyota Corrola, and a Porshce.
-You know that every one of these classes has an engine, and 4 wheels
-Oh look, they all have something in common
-Instead of starting from scratch wrth an engine and wheels, you can just make a base class calls Car
-This base "Car Class" will have engine, and 4 wheels setup
-Now when you want to make a Ford Gt, you can inherit this basic "Car Class"
-You now have a superclass in which you can extend any car types.
The end.
>>
File: 1386290036806.png (263KB, 800x720px) Image search: [Google]
1386290036806.png
263KB, 800x720px
What's your favorite programming language and why is it C++?
>>
>>60394387
opengl
>>
File: koakuma_marisa.png (68KB, 268x292px) Image search: [Google]
koakuma_marisa.png
68KB, 268x292px
>>60389461
He's right though.
>>
>>60394402
also anyone who can drive a Car can drive a Ford etc
>>
File: IMG_0262.png (31KB, 874x436px) Image search: [Google]
IMG_0262.png
31KB, 874x436px
I just did a problem for a C tutorial. It takes an input of how much money, and returns the least amount of coins needed to make change.

I can't post my code, but it's just a loop that keeps subtracting by the greatest amount possible and increment a coin counter by 1 each time until the amount is 0.

I want to improve it so that instead of just returning the amount of coins, it returns the amount of quarters/dimes/nickels/pennies also.

I can easily just create a counter for each type of coin and increment those, but a function can only return 1 value. Obviously I can just maje the function print the results, but in the future how would I go about actually returning those four values elegantly? Making a seperate function for each seems overkill.
>>
>>60394454
This is very good.
>>
>>60394402
Explain to me why you can't just make a larger struct that contains various smaller structs within it?

Because that sounds exactly like "inheritance".
>>
>>60389964
>needing to compute tensor rank at runtime

Compile time master race reporting in.

#include <cstdio>
#include <type_traits>

template<typename value_t>
struct tensor_rank : std::integral_constant<size_t, 0>{};
template<typename value_t, size_t size_>
struct tensor_rank<value_t[size_]> : std::integral_constant<size_t, tensor_rank<value_t>::value + 1>{};

int main(int argc, char **argv)
{
int x[7][7][7];
const auto rx = tensor_rank<std::decay_t<decltype(x)>>::value;
printf("rank of x: %i\n", rx); // because fuck std::cout
return 0;
}
>>
>>60394350
you just need to know Java for android programming. There are however some android specific stuff, but its really easy to pick up on. Watch android tutorials on youtube, and if you alraedy know Java its easy.

>>60394387
you dont need to know java swing/awt for libGDX. It is its own thing.
>>
Eclipse or IntelliJ?
>>
>>60389964
int dim(void *ptr){
return 1;
}

the memory is just a huge array
you can perceive it as a matrix if you want to, but it will never change the fact that it also can be perceived as a huge array
>>
>>60394526
eclipse

there is nothing wrong with the latest version you can even use it for C++ and other languages not just java
>>
>>60394331
>>60394519
>>
>>60394507
https://en.wikipedia.org/wiki/Division_%28mathematics%29
https://en.wikipedia.org/wiki/Modulo_operation
>>
>>60394516

composition =/= inheritance

Your Ford is a Car, your Ford does not contain a Car. You don't take the Car out of the Ford to drive() it.
>>
File: chen_rape_face.png (54KB, 241x235px) Image search: [Google]
chen_rape_face.png
54KB, 241x235px
>>60392316
>Go is a great lang! It's faster than other GCs!
>O-only autistic FP sperglords like me with nothing better to do other than implement first order arithmetic on a computer can appreciate the brilliance of Trashkell!!
>>
>>60394516
>Explain to me why you can't just make a larger struct that contains various smaller structs within it?
thats seems to be composition

look up the term composition over inheritance. https://en.wikipedia.org/wiki/Composition_over_inheritance

Inheritance is the easiest concept to learn cmon m8, dont overthink it.
>>
>>60394526
im personally a fan of eclipse. I just find it much easier to use, and there are a lot more tutorials for Eclipse because its more popular than InteliJ
>>
File: yukari_lick.png (123KB, 471x577px) Image search: [Google]
yukari_lick.png
123KB, 471x577px
>>60394438
>it's fast
>it's robust
>it's easy to debug
>it's got great references and numerical libraries
>it's an idiot filter
>second only to Fortran
>>
>>60394709
>>it's an idiot filter
You've got that right
>>
>>60394717
hue
>>
>>60394519
This always returns 0 for me.
>>
>>60394561
What does this have to do with returning multiple values from a function? I already know how to calculate the coins used, but suppose I had another function that needs those four values calculated by the one function?
>>
>>60394809
either return a struct with two values or pass in two pointers and set them inside the function
>>
>>60394809
Your implementation was crap so I gave you links on how to improve it.

And there are two ways in C: Either return a struct, or pass multiple values by reference. You can also pass a struct by reference, which is the preferred method.

In higher level languages, like Python and C#, you can return an anonymous typed Tuple which pairs multiple values together behind a closure (which in memory is literally a struct)
>>
File: 1488707665022.png (304KB, 865x526px) Image search: [Google]
1488707665022.png
304KB, 865x526px
>>60394516
ok anon, your getting confused. Ill explain the difference between compostion and inheritance, and why WOULD NOT want to use composition when modelling cars.

Composition:
-is a has-A (has a) relationship
-Meaning that, when something has a another thing.
-A car has-A engine
-A bike has-A seat

Inheritance:
-uses a is-A (is a) relationship
-Meaning when something is another thing
-a Ford Gt is-A car
-4Chan is-A imageboard site.

Now in the case of our Cars, Ford, Toyota example, would you really use composition? That would make no sense.
-Does a Car have a Ford GT? Nope
-Does a Car have a Toyota? Nope

Using inhertiance:
-a Ford GT is a car. That makes sense
-a Toyota is a car. That makes sense too

Using composition to model cars would make no sense.
>>
FUCKING HELL I HATE REFACTORING

Will you ever get to a point where u finally git gud and dont need to refactor anymore?
>>
>>60389332
Why does the guy look like he's in deep pain when the girl is just touching him?
>>
>>60394854
this is literally not an argument. you are taking english phrases and translating them into programing but there is no direct correlation between colloquial english and programing

a car has-a engine.
a car has-a set of wheels
a car has-a dashboard
a car has-a manufacturer

there that makes more sense doesnt it?
>>
File: 1488330963674.jpg (15KB, 224x206px) Image search: [Google]
1488330963674.jpg
15KB, 224x206px
>>60394516
that is why you would not use larger structs, because it makes no sense in real life. When your writing OOP, your trying to make it as close to "real-life" as possible. Your trying to model after real relationships between objects in the world. A car does not have a Ford Gt, so you dont use composition. A Ford Gt however is a car (inheritance), so you can make a Ford Gt inherit from a car class
>>
I unironically like VSCode
I unironically like Win10
Deleting my arch partition famiru
>>
>>60394919
come on now you're being retarded on purpose you can choose to understand
>>
>>60394930
>>60394402
>>60392250

It really seems to me that fully embracing principles of object oriented programming (POOP) literally destroys your brain, because only adherents of POOP will attest to it's effectiveness.
>>
File: 1493018355609.jpg (85KB, 768x1024px) Image search: [Google]
1493018355609.jpg
85KB, 768x1024px
>>60394832
>>60394832
>>60394832


bump for help
anon pls
>>
File: OOPs.png (315KB, 1680x740px) Image search: [Google]
OOPs.png
315KB, 1680x740px
Reminder that OOPs was a well-intentioned mistake. After investing far too much time, money and brainspace to it, many people have difficulty simply letting go of it, and moving on.
>>
>>60394961
you're fucking retarded thanks for confirming yet again that POOP memers are just too stupid to understand OOP
>>
File: 1487614720518.jpg (130KB, 702x672px) Image search: [Google]
1487614720518.jpg
130KB, 702x672px
>>60394919
you just proved my point. Look at what you just did, you listed parts of a car.

a car has-a engine.
a car has-a set of wheels
a car has-a dashboard
a car has-a manufacturer

All of these are true, so you can build a car class using composition.

But now try to say:
a car has a ford gt.
a car has a porsche

That makes no sense, YOU CANT MODEL DIFFERENT CAR TYPES, using composition. You would need to use to inheritance. You can model parts that are inside of the car such as the engine, seats, etc...

The (has-A: composition) and (is-A inheritance) make perfect sense.

http://www.w3resource.com/java-tutorial/inheritance-composition-relationship.php
>>
>>60394953
no, I understand exactly why inheritance is shit and should be avoided at all costs. i used to be misled like you but then I spent a few years writing programs and actually learned something that wasn't straight from a Java 101 course
>>
@60394961
(You)
>>
>>60394832
>I Can't figure out how server would know about InfoPacket structure?
you code the InfoPacket in the server
they both must match

in a network protocol, the server must know what to expect, or you have to tell him (through the protocol what to expect)
as you are using strings, with variable size
or you code like
>i will send 3 null delimited strings in sequence
the string ends at the first null byte, 2nd string at 2nd null byte, and so on
or
>i will first say how big the string is (N bytes), then i'll send it, the second strings starts exactly after N bytes and so on
>>
File: 7297_7891.jpg (39KB, 640x480px) Image search: [Google]
7297_7891.jpg
39KB, 640x480px
Was Lisp robbed?

Was ML robbed?
>>
>>60394991
im telling you you're looking at the problem the wrong way. enjoy your unmaintainable taxonomic structure of cars, I guess.
>>
Why does sepples need a delete and a delete[] operator?
>>
File: miku poop.jpg (103KB, 500x500px) Image search: [Google]
miku poop.jpg
103KB, 500x500px
This mick walks up to you and splatters you with Principles of Object Oriented Programming!

What do?
>>
>>60395009
C was robbed
ML ate all the glue
Lisp was the phone
>>
>>60394992
i guess you are stupid then huh, cant even learn simple concepts from an Java 101 course. Calling something stupid when you cant even understand it, is the definition of stupid. I was only trying to help you
>>
>>60394992
now what if you have a Vehicle. not all vehicles have an engine or wheels etc. then it makes more sense to use inheritance for Car and Boat etc
>>
>>60395019
>This mick
She doesn't look Irish to me.
>>
>>60395014
no you are looking at it the wrong way. Sure you can model a base car class using composition, that makes perfect sense. But to make car contain other cars make no sense at all. Have fun
>>
>>60395009
robbed of what?
>>
>>60395005
on the pipe they will look like
for example
"Country\0OS\0\Name\0"
or
8"Country"2"OS"4"Name"
>>
>>60395005

Thank you.
>>
>>60395019
take 10 showers
>>
>>60395049
Prominence.
>>
>>60395077
lel, no.
>>
>>60395048
You are thinking that because a card "is a" Ford it must inherit from the Ford base class. That has no basis in programing or reality at all.

I specifically make all my classes final because of shitheads like you think think inheritance is the tool for everything.
>>
>>60395009
>>60395077
no they just fucking suck. they even had lisp machines so they were more than prominent enough and got a fair chance.
>>
>>60393447
it exists, but poorly implemented, no tabs, no video support etc. im planning to make it fully functional on the console.
>>
>>60390709
It's written "Why OCaml" in the top left corner.
Mind explaining this?
>>
>>60395139
It's the only decent statically typed and garbage collected language.
>>
why cant you just webdev in C++ or something instead of shitscript?
>>
>>60395110
No i dont think that dumbass,stop putting words in my mouth. If your only gonna have 1 ford class, then you dont need to use inheritance, its overkill. But if you were gonna have 200 car types, have fun making organized classes without using inheritance
>>
>>60395161

write a module for your favourite httpd in C++
>>
>>60390709
LOOOOOOOOOOOOOOOOOOOL

it's the obvious truth but it's hilarious that it's coming from the most official source the language creator himself that gophags are brainlets
>>
>>60395110
>make all classes final
Thx for confirming your retarded
>>
>>60395178

Making classes final by default is a good idea.

I prefer marking inheritables than marking non-inheritables.
>>
>>60394087
specialize in C++ and/or java
>>
>>60395161
web assembly
>>
>>60395187
why would you mistakenly inherit non inheritable classes.
>>
File: 1426217369168.jpg (17KB, 300x188px) Image search: [Google]
1426217369168.jpg
17KB, 300x188px
is this how you do encapsulation (i.e. returning more shit from a functino)?

class A
{
public:
A() :
a(0),
b(0)
{}
void set(const int a, const int b)
{
this->a = a;
this->b = b;
}
void print() const
{
printf("%d and %d\n", a, b);
}

private:
int a;
int b;
};

void myfunc(A& arg)
{
arg.print();
arg.set(1, 2);
arg.print();
}

int main()
{
A mya;
mya.print();
myfunc(mya);
mya.print();

return 0;
}
>>
>>60395204

I don't and I want to make sure nobody else does unless it's necessary.
It's nice to just be able to look at a class definitions and know that this is exactly what I'm working with.
>>
>>60395166
public final class Car {
public Car(Manufacturer m, Engine e) { ... }
}

Car pinto = new Car(new Ford(), new PintoEngine());
Car camry = new Car(new Toyota(), new MZEngine()); [/code]
wow so hard
>>
>>60395161
you can but the web hosts are gigantic faggots and keep the basic plan restricted to php/asp.net to get you to pay for the cloud meme
>>
>>60395214

does sepples allow returning adhoc structs or adhoc tuples?
>>
>>60395159
Yeah but the post was talking about Go.

There's no relation between the post and the picture.
>>
>>60395233
auto
>>
>>60395222
>Car pinto
>pinto
>Ford
that was supposed to be a Fiat Punto?
>>
>>60394853
>>60394842
Ty. Another question: given a number what would be the best way to create an array to hold each digit.

For example, user inputs the number 4588, so an array of size 3 would be created with the element at [0] being 4. Or if they enter 178779, an array of size 5 is created with [3] being 7.
>>
>>60395222
straight up garbage code.
I guess it is hard for you
>>
>>60395243
prolly because he didn't even get the screenshot from the original video, the rob pike talk, he instead took it from some random ocaml shit...

this is how the "elite" programmers in /dpt/ learn about other langs: from what someone else said about it. they aren't even able to learn a small lang like Go in a few hours...
>>
>>60395221
i have never seen this in practice. I guess the more you know....
>>
>>60395243
nvm, I just noticed that it was a Rob Pike quote. Makes sense now.
>>
>>60395214

>encapsulation (i.e. returning more shit from a functino)?
Those aren't remotely similar concepts.
>>
>>60395293
Size 4*
Size 6*
>>
>>60395233
>>60395248
why does this print "0 and 1"?
std::tuple<int, int> myfunc()
{
int a, b = 1;
return std::make_tuple(a, b);
}

int main ()
{
int a, b = 0;
std::tie(a, b) = myfunc();
printf("%d and %d\n", a, b);
return 0;
}
>>
File: chen_what.png (44KB, 388x256px) Image search: [Google]
chen_what.png
44KB, 388x256px
>>60395214
>encapsulation (i.e. returning more shit from a functino)
Lol what?
>>
>>60389332
is it just me or are anime girls getting thicc, they used to have long slender legs
>>
>>60395405

C declarator bullshit strikes again. Here's what you really wrote.
std::tuple<int, int> myfunc()
{
int a = 0, b = 1;
return std::make_tuple(a, b);
}

int main ()
{
int a = 0, b = 0;
std::tie(a, b) = myfunc();
printf("%d and %d\n", a, b);
return 0;
}
>>
File: the_devil.png (2MB, 579x1426px) Image search: [Google]
the_devil.png
2MB, 579x1426px
>>60395419
Thicc had been a thing for a while. Spaghetti legs is the more recent trend
>>
File: 162342148015.jpg (104KB, 1280x720px) Image search: [Google]
162342148015.jpg
104KB, 1280x720px
>>60395441
Fucking<jfhh4hkdhrgkse5hkghbsakdsgd

thanks anon
>>
so
>PHP, Go and Js are all garbage according to /dpt/

What should one use for web backends if that's the case?
>>
File: Programming-republic-of-perl.png (2KB, 97x97px) Image search: [Google]
Programming-republic-of-perl.png
2KB, 97x97px
>>60395483
P E R L (6)
>>
>>60395405
> Undeclared variable "a"
Enable compiler warnings and you will find issues like this next time automatically
>>
>>60395501

lol
>>
File: 1424666571507.png (127KB, 480x480px) Image search: [Google]
1424666571507.png
127KB, 480x480px
>>60395483
>web
that's your problem anon
>>
>>60395483
learn lisp, haskell, scala or ruby, obviously

those are the languages of expert /dpt/ coders
>>
>>60395295
you write something better then
>>
>>60395509
a has been declared anon wtf
it wasn't initialized tho
>>
NEW THREAD!

>>60395542
>>60395542
>>
>>60395509
>>60395525
using
g++ foo -std=c++11 -Wall -pedantic -Wextra
gives me no warnings though?
>>
>>60395307
people in general are such fucking retarded faggots about const correctness, very few people seem to do it
>>
>>60395483
this is the programming thread
>>>/g/wdg
>>
>>60395405
my dude

int a, b = 1;

you only set the value of "b" with that last equal sign.

a is "undefined" since you basically just did

int a;
int b = 1;
>>
>>60395222
>>60395524
and now what if you need to make 15 more cars. Are you really gonna remember all the details of what makes the car? What if someone puts together a car that doesn't make sense. What if they put a ford engine in a Porsche? The way you coded it, is horrible. Now go and improve your code retard
>>
>>60395405
Bump, come defend your shit code to this >>60395689
Im waiting anon
>>
>>60395722
misquote?
>>
>>60395722
>Bump
The thread is already at bump limit, faggot.
>>
Am I a pajeet if I use SHA for encryption?
>>
>>60395689
firstly, this is a client problem, not mine. but if you insist:
public final class CarFactory { 

public final Car makePinto() {
return new Car(ford, new PintoEngine());
}
...

There.
>>
>>60395851

>____Factory
Go back to the drawing board, anon.
>>
>>60395871
it models the real world, anon. car factories make cars
>>
>>60395892
this

quit forcing your shitty abstractfactorybean memes and try actually learning something for once
>>
>>60395910
>abstractfactorybean
>>
>>60395689
>>60395851
Alternatively, builder pattern if you want a more structured approach.

Please use composition and interfaces instead of inheritance unless inheritance is the only way to do something, which it rarely is desu.
>>
>>60396059

Interfaces are inheritance though, it's just inheritance of abstracts.
>>
>>60392316
>taking .3 to .7 seconds to print fifty numbers
Yeah, that's not suspicious at all.
>>
>>60396088
dont ever write the word 'extends' and we're good
>>
>>60392765
>who could have said "the language of the future is JS" some 10 years ago or so?
Steve Yegge loudly implied this in 2007, with his 'Next Big Language' blogpost.
>>
static const char *const arr[];
>>
>>60389455
Interesting idea, though not reall necessary, as you can just use the floats (or rather, doubles) function for both because of C's automatic type promotion.
>>
>>60389633
C. It's already 40 years old, but still widely used, this means something.
>>
>>60389633
Erlang
Thread posts: 331
Thread images: 44


[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.