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

/dpt/ - Daily Programming Thread

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

Thread replies: 337
Thread images: 32

File: 1473415000257.png (407KB, 700x463px) Image search: [Google]
1473415000257.png
407KB, 700x463px
old thread: >>56508350

Today's 9/9! The strongest day of the year!
How are you celebrating Cirno Day?
>>
Learning Haskell, it's going pretty great
>>
File: STRENGTH THROUGH PURITY.png (36KB, 2000x1412px) Image search: [Google]
STRENGTH THROUGH PURITY.png
36KB, 2000x1412px
>>
First for the simplicity of Java.
>>
4rth for Go

>>56515366
>>56515781
>>
>>56515680
Weird. Last time I tried, I wanted to kill myself.
>>
How long does the password used in a xor algorithm need to be in comparison to the data used to encrypt? Does it matter if the password is random or not?

I think if the password is as long as the data it should basically be a one time pad. I'm not sure if the password needs to be random. If the password is one character less than the input does it become massively less secure, or just slowly less secure as you take length off?

>>56515815
I found it not too hard to learn, and really fun, though I get triggered when you get asked to solve a problem in a particular way rather than in the functional way and it's super ugly
>>
>>56515792
FUCKING ADD STRUCTS YOU FUCKING ORACLE RETARDS.
Also fucking at 100% code swapping in debug mode. For some inexplicable reason it's not possible to add/remove methods or fields while the application is running. It's fucking 2016. They've even hired the damn DCEVM dudes who implemented this shit in their free time and it's still not included in the JDK.
>>
>>56515798
>it's awsome
Why would you lie like that?
>>
>>56515846
java doesn't have structs....?
what the fuck
>>
>>56515874
It has "plain old data" classes, but they're called "beans" and are still reference types.
>>
>>56515846
>inb4 Pajeets asking "why would you need that?"
>>
>>56515846
>Java has no structs
>Java has no unsigned types
>Java has no pointers
>Java has no pointer arithmetic

What the fuck is it good for?
>>
>>56515891
OOP was a mistake
>>
Anyone know a good way to get an evenly distributed function f :: Integer -> (Bool, Bool) ?
i.e. the chances of (0,0),(0,1),( 1,0),(1,1) are the same
>>
>>56515846
>inb4 retards believe that java has no composite types
>>
>>56515925
In Haskell? First of all, you need to describe the effect of the RNG. That, or you could program it so that different outcomes are "superimposed" and "collapsed" by running an RNG at the end.
>>
How many bootloaders have you programmed?

None? That's what I thought, noobs. Stay out of a PROGRAMMING thread, okay?
>>
>>56515930
Not without unreasonable overhead, no.
>>
>>56515867
how is it a lie?
in any case, it's my opinion.

>>56515798
OTOH, if you want to make UIs and stuff, don't use golang
>>
>>56515925
https://hackage.haskell.org/package/MonadRandom
>>
>>56515874
This is the primary reason why java applications are so RAM hungry. Since everything is an object, everything needs an allocation and a reference pointing to the object instead of simply including the data directly. GC performance also depends on the number of pointers in live memory.

ArrayList<Integer> alone is enough to summarize everything that is wrong with Java.
>>
>>56515925
Generate two random numbers, divide both by 2, return remainders.
>>
>>56515909
Writing business shit GUIs to keep track of what you sold to who.

And also: literally nothing else
>>
>>56515909
>Java has no structs
What's the point if it has classes already? I saw people arguing classes =/= structs, but I don't see the difference. Rust programmer here.
>Java has no pointers
>Java has no pointer arithmetic
Isn't it possible with native interface?
>What the fuck is it good for?
It's quite powerful while being super simple.
>>
>>56515945
Sorry. The point is to make a list of random (Bool, Bool) (really Int but only 0 or 1, so bool for this discussion, because no dependent types.jpg)
Likes to:
random01Pairs :: Int -> Int -> [(Int, Int)]

>>> random01pairs 5 532
[(0,1), (1,1), (0,1), (0,0), (1,1)]

I.e., if I get a list of 5 of them, it doesn't have to be evenly distributed, but if I took a million, I would expect it to be nearly even
>>
>>56516003
Then you need to describe the effect of the RNG leading to non-determinism, for instance with >>56515977.
>>
>>56515909
>Java has no pointers
actually the big problem is that everything is a pointer especially on 64bit
>>
I have around 40000 XML files I need to extract info from. Specifically, I need specific attribute values and info I can get from the file name. This info needs to be stored in a MySQL table.

Right now, I'm using a multithreaded python script to read the XML file line by line and get the values. It was fast in the beginning but now after nearly 1 million rows it's slowed down to bursts of 5 or so lines at a time.

Is there a more efficient way to extract XML data like this?
>>
>>56515987
What separates a "class" from a "struct" can depend on the language, but I assume the issue is that Java classes will contain extra cruft that people don't need when they just want a struct like creating a VMT and not being able to pass them by-value
>>
>>56516017
Sorry I don't quite get what you're saying, still fresh to Haskell but I'll look at anon's link, no need to spoonfeed further
>>
>>56516082
monads
nuff said
>>
>>56516088
Yeah I don't understand them yet :^)
>>
>>56516096
gotta git gud, keep going and you'll reach satori in no time
>>
>>56516039
I see.
I guess it could be easily archive as syntactic sugar, but they wouldn't be first class citizens then.
For me lack of RAII is the most problematic in Java.
>>
>>56516034
You didn't tell us what the slow part is.

Is the database slow? (did you create indices?)
Is the HDD slow because thousands of small files are scattered around?
Are you using a library that wraps around a C XML parser?
Are you doing stream processing of the XML data?
Do you do a lot of arithmetic operations and thus the python interpreter slows you down?

I can't fucking read your mind.
>>
>>56516082
There's a package random, and another, MonadRandom
(the latter uses the former)

It gives the examples:
die :: (RandomGen g) => Rand g Int
die = getRandomR (1,6)

dice :: (RandomGen g) => Int -> Rand g [Int]
dice n = sequence (replicate n die)
--replicateM n die


You might need to provide an instance for (Bool, Bool), but you could always produce twice as many results and pair them up
>>
>>56516118
>For me lack of RAII is the most problematic in Java.
Wut? You have try-with-resources.
>>
File: 3be.jpg (30KB, 572x548px) Image search: [Google]
3be.jpg
30KB, 572x548px
>tfw functional "programmers" don't realise that monads are just objects
>tfw they shit up /dpt/ with OOP hate
You can't make this shit up.
>>
>>56516155
Great, thank you! I'll get to really understanding it soon but will use this for now; thanks!
>>
>>56516182
This is some really nice bait anon
>>
>>56516182
Comonads are objects and simply using objects isn't OOP.
>>
>>56516182
>You can't make this shit up.
Wrong, Trump can make any shit up.
>>
>>56516182
Actually they're monoids in the category of endofunctors
>>
>>56516191
>Comonads are objects
They aren't though, that was some random deluded man trying to force it
>>
>>56516182
>>56516191
And by that I mean that objects are comonads. Not the other way around.
>>
>>56516191
this. an object is simply something in memory.
from wikipedia:
>In computer science, an object can be a variable, a data structure, or a function or a method, and as such, is a location in memory having a value and possibly referenced by an identifier.
OOP means "Object-oriented programming", that doesn't mean other langs don't have objects. all of them do
>>
>>56516238
That's a classic misguided OOP defense. When people point out the shortcomings, they extend the definition of OOP to include all programming.

The other funny response to a lot of OOP criticism is "OOP is good when it's used right". Well, yes, but OOP is so seldom the right choice that it needs to be put in its place.
>>
>>56516163
Uh, I went full retard. I was reading about it today and misread it as not finished/planned feature.
Anyway, that's a nice thing. It doesn't look as clear as RAII based on deterministic destruction but it's fair enough.
>>
>>56515798
Go has a ton of problems.

Mostly, the lack of generics and the shitty built-in approach to package management will make you want to stab yourself in the dick.
>>
recommend me a book to begin learning programming /g/? I'm a complete beginner and don't know if python is truly a meme or if its just some elitism trying to ward me off.
>>
>>56516207
TLDR What we call typeclass is similar to an interface in e.g. Java except it's more a compile time thing. An instance of the Monad typeclass e.g. "Maybe" implements some functions called bind and return. Two instances of Monads like "List" and "Maybe" have nothing in common except the signature of the two functions. What map/return does depends on whether you have a List or a Maybe. The haskell people decided that it's better to have typeclasses than to prefix their methods C/lisp style like bindList or bindMaybe and returnList or returnMaybe.
>>
>>56516327
First you need to decide what kind of programmer you want to be.
Embedded systems, complex/web/mobile games, web back/front-end, mobile app, enterprise software, big data?
>>
>>56516256
>That's a classic misguided OOP defense. When people point out the shortcomings, they extend the definition of OOP to include all programming.

Not really. What they're really doing is confuse the OOP definition of "object" with the non-OOP definition.

From the ISO C (not C++) standard:

>3.15
>object
>region of data storage in the execution environment, the contents of which can represent
values

They also mistake any opaque datatype for OOP encapsulation. This way, they don't have to defend the mish-mash of half-assed features that OOP couples together, only to then teach first-years about the benefits of decoupling.
>>
>>56516386
Not him but what should I learn now if I want to participate in the upcoming robotics renaissance in which the robots will terk all of our jerbs?

Dumb answer would be ladder logic but that's for older, shittier robots, rather than modern robots which are supposed to react to external events.

What specialized knowledge do Google's self-driving car guys rely on right now?
>>
>>56516421
>They also mistake any opaque datatype for OOP encapsulation. This way, they don't have to defend the mish-mash of half-assed features that OOP couples together, only to then teach first-years about the benefits of decoupling.
Okay, yeah, that's more the kind of thing I'm thinking of. Anything polymorphic is OOP. Anything that hides implementation is OOP. And so on.
>>
>>56516149
The faggot >>56516034 didn't even reply.
>>
>>56516327
My university computer science course didn't start teaching programming until my Master's year. Until that point, it was all math and theory. And no, it wasn't just a weird, shitty university. I literally went to the best university in the USA for computer science. That being the case, do you really think a hobbyist programmer can produce anything of value?
>>
>>56516149
I think it's the database that is slow since it was fast at first and I woke up and got a "load warning" message from the MySQL server. The script has been running for over a week now.
>>
>>56516421
>>56516454
What is OOP?
>>
>>56516487
You have to be an autodidact in this industry just attending college is not enough. The hobbyist can gain experience during the time he doesn't attend college to close the gap in formal education.

>>56516532
You must be at least 18 years old to post here.
>>
>>56516427
I don't know about books, but I can say you should care more about algorithms, computer vision and artificial intelligence and other abstract matter than learning programming language and programming paradigms.
Python or C are good enough for proof of concept in this kind of research. Implementing algorithms these researches invented is a work for actual programmers.
Being able to do both of them is a plus of course.
>>
>>56516532
Fluff: http://c2.com/cgi/wiki?OopIsFluff
>>
>>56516532
trash
>>
>>56516555
>>56516582
>>56516585
So no one knows what OOP is?
>>
>>56516597
Who are you
>>
>>56516597
Object Oriented Programming
The most polarizing paradigm in programming.
>>
>>56516597
see >>56516585
>>
>>56516520
I don't really know a lot about database optimization but if you're inserting a lot of rows then you should batch your inserts.
See http://stackoverflow.com/a/19682518
>>
>>56516597
Pretty much, yeah. Some define it as encapsulation + polymorphism. Others say inheritance and dynamic dispatch is a must. For others, everything must be an object, including classes and code.
>>
File: current year.jpg (21KB, 240x255px) Image search: [Google]
current year.jpg
21KB, 240x255px
>>56515846
>It's fucking 2016.
>>
Guys, we're taking it to the next level.

I think we finally managed to average ints at one point.

Now we have to define OOP.

What is OOP, objectively speaking?
>>
>>56516682
int OOP(int, int);
>>
>>56515909
>>Java has no pointers
>implying

public class Pointer<T> {
T obj;
public Pointer<T>(T obj) { this.obj = obj; }
public T derefer() { return obj; }
public void setDerefer(T obj) { this.obj = obj; }
}
>>
>>56516707
Now add 5 to it and dereference
>>
File: serveimage-8.jpg (191KB, 550x712px) Image search: [Google]
serveimage-8.jpg
191KB, 550x712px
>>56516182
Go back to /pol/ Drumpftard.
>>
>>56516677
https://github.com/HotswapProjects/HotswapAgent/commit/ff02c7a63f2f0929378f29986491b3e91be780aa
>2013
They've started working on it years before the release of the code on github.
>>
File: 1439008579129.jpg (247KB, 928x1428px) Image search: [Google]
1439008579129.jpg
247KB, 928x1428px
>>56516182
You have a containment board for a reason.
>>/pol/
>>
Any book recommendation to learn C++? I have progammed C++ before (only a few excersices, including OOP) but now I want to expand my knowledge on it.
>>
>>56516719
Pointer arithmetic is a different matter desu.
>>
>>56515909
>>56516719
Pointer arithmetic is actually terrible because it's very easy to fuck up and introduce a security flaw. Things that compile to pointer arithmetic (array indexing) are fine, though. t. Rust
>>
>>56516769
Pointers without pointer arithmetic are called references. You point to memory. You take the reference of a value.
>>
>>56516737
>>56516754
>Dae le drumpf

go back to /tumblr/.
>>
>>56516682
Objectively speaking, OOP is Object Oriented Programming, ie. an archaic programming technique that is used to classify different objects, their relation between and help the reuse of them, while saving the programmer/company precious time and money.

However, no one have ever seen this in real life up to this day, you are often found to rewrite old code, using OOP technique that you HOPE someone, someday, maybe you, maybe not, will use to optimize the program or debug/maintain it.

On the other hand we have the more simple programming techniques where, there is libraries, and when you use them, you don't need to rewrite your code every time you need a string, or an array or something trivial.

Hence, we have functional programming.

But the codemonkeys at bootcamps downtown SF don't understand this, they follow what they tell them so, we are forced for another 10-15 years to use this shit
>>
>>56516769
>>56516776
>hey look at our pointers!
>w-what? just because they're not pointers doesn't mean they're not pointers
>who needs pointers anyway? dumb
>>
>>56516776
Pointer arithmetic can be proven correct in various ways, just not in Rust.
>>
Has anyone compiled a python program?
I've been messing around with cx_freeze..
How do I add something like,
from win32api import GetSystemMetrics
or
from struct import *
?
My current 'build' file is like this,
import sys
from cx_Freeze import setup, Executable

setup(
includes = ["os", "win32api", "time", "os", "subprocess", "PIL", "win32clipboard" ],
name = "Windows stuff",
version = "3.1",
description = "Windows stuff",
executables = [Executable("screenshot.py", base = "Win32GUI")])
>>
>>56516768
Effective C++, Effective Modern C++, in that order.
>>
>>56516803
breddy sure you can still do pointer arithmetic in unsafe { } blocks but it's not encouraged because, well, see above.

>>56516808
>Pointer arithmetic can be proven correct in various ways, just not in Rust.
Yo actually you should show those white papers to the Rust language team. If they knew about a form of static analysis that can check pointer arithmetic for safety, they'd probably add syntax for pointer arithmetic to safe Rust.

Or, is this the kind of "proven correct" that can only be done by a human at this time?
>>
>>56515662
Is there a better way of doing the...
n = 5
X X
X X
X
X X
X X

... puzzle? I figured it out, but I'm not sure if its the most efficient way. I've been trying to teach myself programming for a little over a month
def cross_gen(n):
k = (n-3)//2
buffer = 0
for i in range(-((n-k)-1),n-k):
if abs(i) == 1:
continue
if i == 0:
print(' '*buffer + 'X')
else:
print(' '*buffer + 'X' + ' '*(((abs(i)-1)*2)-1) + 'X')
if i < 0:
buffer += 1
elif i >= 0:
buffer -= 1
>>
>>56516876
>but it's not encouraged
It's not discouraged either, but it's meant primarily as a tool for writing low-level primitives to be used in safe code.
>>
>>56516797
>codemonkeys at bootcamps downtown SF
Nice meme. Add a drive-by racist comment against Indians and you reach full meme nirvana.
>>
File: kek.png (3KB, 399x87px) Image search: [Google]
kek.png
3KB, 399x87px
>>
>>56516950
context?
>>
>>56516876
You need dependent types for it so it's not going to happen.

You can use SMT to automate some proofs (Presburger arithmetic, theory of arrays) but not all. For example, integer arithmetic with multiplication by variables (multiplication by constants just turns into addition) is undecidable and requires human intervention.
>>
>>56516950
>eventually does the needful
>>
>>56516737
>>56516754
You think I can't see through your samefag, butthurt libtard?
>>
>>56517005

He posts the same pictures every time, too.
>>
File: distribuidora.png (212KB, 1347x640px) Image search: [Google]
distribuidora.png
212KB, 1347x640px
Cleaning Data
>>
File: 1473294961952.jpg (53KB, 574x721px) Image search: [Google]
1473294961952.jpg
53KB, 574x721px
>>56517058
>>
File: 1466660781773.jpg (8KB, 250x250px) Image search: [Google]
1466660781773.jpg
8KB, 250x250px
>>56516207
>what's the problem?
>>
>>56516034
Have your python script convert the file to CSV and use the mysql console to read in the values
https://stackoverflow.com/questions/3635166/how-to-import-csv-file-to-mysql-table
>>
>>56517101

1996 - James Gosling invents Java. Java is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Sun loudly heralds Java's novelty.

2001 - Anders Hejlsberg invents C#. C# is a relatively verbose, garbage collected, class based, statically typed, single dispatch, object oriented language with single implementation inheritance and multiple interface inheritance. Microsoft loudly heralds C#'s novelty.
>>
>>56516815
Alright, thank you anon.
>>
>>56516034
In every iteration your put the data on mysql ?.
>>
File: 1472668080070.png (141KB, 800x600px) Image search: [Google]
1472668080070.png
141KB, 800x600px
QUICK! Post your solution!
>>
Coloured type theory is neat. From what I understand, colours basically formalize proof irrelevance and allow you to use it in cool ways.

It's kind of dual to ornaments, where ornaments promote code reuse (which, of course is equivalent to proof reuse) by extending a data type while colouring lets you promote code reuse by simplifying a data type (e.g. turning lists into natural numbers by erasing the contents and leaving the "shape").

It also somehow lets you internalize parametricity to some degree but I'm not really sure how that works. It seems a hell of a lot simpler than the other approach I've seen, though, which is extending pure type systems with hypercubes or some crazy shit.
>>
>>56517156
1995 - Brendan Eich reads up on every mistake ever made in designing a programming language, invents a few more, and creates LiveScript. Later, in an effort to cash in on the popularity of Java the language is renamed JavaScript. Later still, in an effort to cash in on the popularity of skin diseases the language is renamed ECMAScript.

(The Smalltalk entry is also pretty good)
>>
>>56517058
Why wouldn't you make a function and a dictionary as input?
>>
vector mpos = vector(o.position.x / MINIMAP_SCALE + MINIMAP_SIZE / 2 - WINDOW_W / 2 / MINIMAP_SCALE, o.position.y / MINIMAP_SCALE + MINIMAP_SIZE / 2 - WINDOW_H / 2 / MINIMAP_SCALE); // Crikey!
>>
>>56515662
It's 10/9 you fucking baka
>>
File: image.jpg (44KB, 328x307px) Image search: [Google]
image.jpg
44KB, 328x307px
Cirno is not technology related.
>>
>>56517179
void xOutput(int r) {
int x, y;
for(x = 0; x < r; x++) {
for(y = 0; y < r; y++) {
if(x == y || (r - x) == y + 1) {
printf("X");
} else {
printf(" ");
}
}
printf("\n");
}
}
>>
>>56517311
>x represents vertical
>y represents horizontal
>>
>>56517179
use std::io;

fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();

let n: u32 = s.trim().parse().unwrap();

for x in 0 .. n {
let line: String = (0..n).map(|y| if x == y || x == n-y-1 {'X'} else {' '}).collect();
println!("{}", line);
}
}
>>
>>56517483
>He fell for the Rust meme
>>
float r = rand() % (14.4f * i);

Why doesn't this work? It says it doesn't like using an int and a float with the % operator. i is an int, but it also doesn't work even if I cast it as a float.
>>
I nearly know nothing. University makes us learn C++ first.

What should I expect?
>>
>>56517529
rand() returns an int
>>
>>56517525
>implying I don't know dozen or so other languages
>he doesn't know Rust will be used everywhere you would use C and C++ in few years
>>
>>56517525
>He fell for the anti-Rust meme
>>
>>56517529
% can't do floats, use fmod() for that
>>
>>56517554
So it does, thank you. I just had to cast the (14.4f * i) as an int.
>>
>>56517562
>>56517560
hi steve
>>
>>56517536
Pain. Pick up Python before you start the year, at least you'll learn to tell the difference between a condition and a loop.
>>
>>56517583
you might want to cast rand to float and use fmod instead of %
>>
>>56517560
>everywhere you would use C and C++ in few years
Not until Rust gets variadics and integrals as generic parameters.
>>
>>56517529
You need to do randomization before casting it to float.
r = (rand() % (max * magic)) as float / magic as float;
>>
>>56517255
This is jus a rapid data clean.
Usually i process this with a WashDatase, that contains all replacements that need to be done for a specify datasource, but i'm not in my machine now, and i need this quickly
>>
Ok guys please help, i've been stuck on this for entire day.

This is in C#

All I want to do is make a timer that will shut the program down when the user specifies (seconds).

how the fuck do I do this?

I've tried timer.FUCKINGEVERYTHING it just doesn't work mane
>>
>>56517656
Post code.
>>
>>56517624
>variadics
It's unsafe and not very practical. It's better to use slices or macros. Unless you just want syntactic sugar over tuples like Java have.
>integrals as generic parameters
They might add it soon. It sounds like valid feature.
>>
>>56517656
are you using win forms?
>>
>>56517179
ITS ONLY WEEK TWO U CUNT CALM IT DOWN WITH THE COMPLEX SHIT
>>
I'm actually starting to like the name 'Hasklel', I think it's grown on me. I'm even considering using it unironically on the haskell subreddit.
>>
File: Code1.png (26KB, 1179x677px) Image search: [Google]
Code1.png
26KB, 1179x677px
>>56517672
at this point I was just gonna leave it till tomorrow
>>
File: Code2.png (16KB, 1246x268px) Image search: [Google]
Code2.png
16KB, 1246x268px
>>56517716
nope just a console application I'm still learning this shit
>>56517737
>>
>>56517624
>implying Peano arithmetic is decidable
>>
File: 2016-09-09_14-42-17.webm (210KB, 610x426px) Image search: [Google]
2016-09-09_14-42-17.webm
210KB, 610x426px
>>56517656
>>56517737
>>56517751
See webm.

Code:
Task.Run(() =>
{
StartSelfDestructionTimer(15);
});


static void StartSelfDestructionTimer(int seconds)
{
Thread.Sleep(seconds * 1000);
Environment.Exit(0);
}


Obviously, there are more things you can do with this, but this should point you in the right direction.

t. Pajeetslayer
>>
>>56517751
you need to start the timer.
>>
>>56517839
thanks dude I guess I was just over complicating things.
>>
>>56517893
Keep in mind that
Task.Run(...)
isn't always best practice, but it's the easiest way to just fire and forget.

You're essentially just pointing at a method and saying "You. Go.", and moving on with the rest of your code.
>>
>>56517690
>It's unsafe and not very practical.
The fuck are you smoking? Any reason why you think these things?
>>
How would you code the NULL value for an SQL implementation? Right now I'm using one byte per entry to represent it, but that seems really wasteful. Is there a better way?
>>
>>56518074
Depends on if it's a fixed or variable-width field.
>>
File: projgen.png (2MB, 3840x2160px) Image search: [Google]
projgen.png
2MB, 3840x2160px
General programming question from a noob:

How do I know where to start a project without googling it first? I decided to do the port scanner challenge, and I had no idea what to do, so I just googled "port scanner on c#" and saw some solutions. It turns out there's a whole library, System.Net.Sockets, that deals with this, so all I have to do is set up a for loop to run through my selected ports, and the TcpClient method from that library does all the work.

The thing is, I never would have known about this library had I not googled the answer. So I guess there's no way to do most of these challenges unless you google the answer first, and then try to copy it. Is that how I'm supposed to do it?
>>
File: fhex.webm (678KB, 736x412px) Image search: [Google]
fhex.webm
678KB, 736x412px
Working on my ncurses hex editor.
Currently implementing goto function.
>>
>>56518301
there are a couple ways to solve a problem
you can break it into smaller problems, then solve those problems
that's probably my favorite way

>>56518329
neato
>>
>>56517945
Weed.
Since we are talking about Rust I assumed you mean Variadic functions like in C/C++.
You have to choose type of arguments on runtime and choosing wrong type causes undefined behavior, doesn't it? It makes the function unsafe.
Unless you want Variadic like in Java where arguments are converted silently into table or some other object. That would go against Rust's principles. It's better to force programmer to choose their own way of doing them than to surprise them with synthetic sugar that creates unexpected structures in a background.
>>
>>56518371
I think he meant variadic templates (i.e. type-level lists).
>>
>>56518377
Oh you are right.
Then I agree this would be nice.
However I'm also a little afraid that templates might turn into a clusterfuck like in C++14.
>>
how do I into kernel programming? just finished K&R
>>
>>56517839
>t. Pajeetslayer
I'm glad you've adopted the title. Now I know who to thank for getting me through this fire code thing because holy fuck it's almost done.

>>56518301
>Is that how I'm supposed to do it?
Yes. I was going to say break it into smaller problems after you do but >>56518348 beat me to it. Make sure those smaller problems interconnect in some way. Some things you need to ask about if you're stuck. I didn't even know how I was going to store the mass of data I had to use for my fire code project for work until I asked here (I'm a one-man show here and have no one else in the office to ask). Other things you learn by doing and realizing along the way either how great something worked or how poorly it worked. It's a doing process, much like math where you pick up a pencil, actively read the material, and start working on problems until it clicks.
>>
>>56516924
def plot(n, f):
half = (n-1)/2
for i in xrange(n):
for j in xrange(n):
print('*' if f(i-half, half-j) else ' ', end='')
print()
def cross(x, y): return abs(x) == abs(y)
plot(5, cross)
>>
>>56517278
Aussie RAUS
>>
>>56518547
I've never had a trip, and yet I've been called Pajeetslayer like 7 times while helping anons with C# stuff.

Makes me all warm and fuzzy for some reason.

>>56518301
The fun part is when you break something into 18 small problems and solve them all AND THEN you find a library that does it all in one line with a few method parameters 8x faster than your solution.

See:
SqlBulkCopy
>>
>>56518607
>The fun part is when you break something into 18 small problems and solve them all AND THEN you find a library that does it all in one line with a few method parameters 8x faster than your solution.

Every single time.
>>
>>56518607
I'm pretty sure I was at least 4 of those times. I still have the state/city/county class example you cooked up. You da best.
>>
I'm trying to understand how to store a heterogeneous collection of function pointers in c++.

Please kill me.
>>
>>56518724
void*
>>
>>56518724
Heterogeneous in what way? This is probably a bad idea.
>>
>>56518607
>>56518692
Maybe if you didn't use pajeet languages like C shart that coddle and baby you with libraries and instead choose a barebones meme language, you won't have that problem.
>>
>>56518744

I like my fat standard library. It makes it easy to get things done.
>>
>>56518726
You can't cast function pointers to void *.

>>56518724
Typed unions, converting function pointers to objects, etc.
>>
>>56515846
>>56516478
Ad hominems.
>>
>>56518726
But i won't be able to call the function then.

>>56518737
I want to map strings to overloaded functions that take different argument types.
>>
>>56518769
Cast it back
>>
>>56518769
>I want to map strings to overloaded functions that take different argument types.
For what purpose? You'll need some kind of RTTI, in any case.
>>
>>56518772
That defeats the whole purpose of the heterogenous collection.
>>
>>56518799
No it doesn't
>>
Quit attacking the person instead of the position they're maintaining. It's a logical fallacy.
>>
>>56518348
>>56518547

I'm familiar with the 'break it down' approach, and I do that. The thing is, some tasks are already built into libraries, like "Scan port" is built into the Systems.Net.Sockets library, and I would never know that unless I googled the answer to the problem. Because I would never be able to code a "Scan port" function/method myself, at least not as a beginner.
>>
>>56518817
You going to quote someone the next time you post that?
>>
Quit attacking the person instead of the position they're maintaining. It's a logical fallacy.
>>
>>56518840
See
>>56518766
>>
>>56518847
Nothing you say matters, faggot.
>>
>>56518817
>>56518847
You're an idiot.
>>
>>56518783
I want to make a simple config file parser.
I want to map a data type to a config parameter name. When i read the parameter name and value from a file the parser should be able to look up in the map what data type the parameter is.
>>
>>56518859
>>56518863
Quit attacking the person instead of the position they're maintaining. It's a logical fallacy.
>>
>>56518870
What does this have to do with a heterogenous collection of functions?
>>
>>56518796
>>56518817
Autism
>>
>>56515662
Second day with C, what am I doing wrong, first two lines are user input and second two lines should be the exact same as output from the program. Will fix the indentation later, build emacs yesterday and was to lazy to set tab on 4 spaces.
/* program to print out all lines bigger than 80 characters */
#include <stdio.h>

#define SWITCH 80 /* lines bigger than this will be printed out */
#define MAXLINE 1000 /* maximum length of lines stored in line and temp */

main(){

int c, i, len, nl; /* store length of line and beginning of new line */
char line[MAXLINE]; /* store lines bigger than 80 */
char temp[MAXLINE]; /* temporarily store input */

len = nl = 0;
while ((c = getchar()) != EOF) {
if (c != '\n') {
++len;
temp[len] = c;
}
else if (len > SWITCH && c == '\n'){
for (i = 0; i < len; ++i) {
line[i+nl] = temp[i];
temp[i] = '0';
}
++i;
line[i] = '\0';
nl += len+1;
len = 0;
}
else {
for (i = 0; i < len; ++i)
temp[i] = '0';
len = 0;
}
}
for (i = 0; i < nl; ++i)
if (line[i] != '\0' && line[i] != 0)
putchar(line[i]);
else if (line[i] == '\0') {
printf("\n");
++i;
}
else {
printf("\n");
break;
}
return 0;
}
>>
>>56518766
I do not think you know what ad hominem is.
>>
>>56518923
Ad hominem
>>
File: 1471809284603.jpg (262KB, 1280x981px) Image search: [Google]
1471809284603.jpg
262KB, 1280x981px
Does anyone have the /dpt/ starter kit image?
Or the /g/ starter kit image?
Pic related, one part of the starter kits.
>>
I'm trying to do a post with Okhttp 3.4.1

But when i fill the form (Request Body) it goes like this

.add("username", user)
.add("pass", pass)


and then use the Request and OkHttpClient to post it and it looks like nothing happens because the page is still the same, UNLESS i change the request body to this

.add("username ", user) <- add anything to the field, space period semicolon etc..
.add("pass", pass)


So if i change the field to anything else the page changes to "Invalid User/Pass"
What am i doing wrong?

I'm doing this to a website with no api and i have done this before with other libraries Jaunt and Jsoup
>>
>>56518952
hot
>>
>>56518952
fuck you for giving me a boner faggot
>>
>>56518467
First you make a MMORPG.
>>
>>56518902
I can't store data types in a collection, but i thought maybe i can store overloaded function pointers.

But it seems this is an equally retarded idea.
>>
>>56518936
(of an argument or reaction) directed against a person rather than the position they are maintaining
>>
Are there any uses for monads in the category of monads?


>>56518952
>>56518977
samefag

>>56518974
actual fag
>>
>>56519002
>actual fag
Thanks Captain obvious!
>>
>>56518990
You can't store types themselves, but you can store runtime representations of those types. In your case, an enum will probably suffice.
>>
>>56518998
Something that did not happen.
>>
>>56518998
>of an argument
When I called you an idiot, it was not an argument
>>
>>56518990
>>56519021
Also, why bother putting this stuff in a collection when it's going to be hardcoded?
>>
>>56519023
>Retard
>Faggot

Those are directed towards the people.
>>
>>56518936
that sounds like ad hominem to me
>>
>>56519021
>but you can store runtime representations of those types
How? You mean just manually define enums for all data types i an think of?

>when it's going to be hardcoded?
It's not.
>>
>>56519043
>Or reaction
>>
File: 7.png (184KB, 660x720px) Image search: [Google]
7.png
184KB, 660x720px
>>56518952
>>
>>56519089
There are insults, not arguments.
>>
>>5651911
Reread the definition and then see
>>56519113
>>
>>56519002
u wot m8?
>>
>>56519149
Took you a while to edit
>>
>>56518952
i wish i was cute
>>
>>56519100
Okay, different spin on things. This is a config parsing library? I'm assuming you want to give something like a map from string keys to values to the user. Why does the library need to know about actually interpreting the values into their desired types? The user already needs to take that map and interpret it into a real structure - just make them interpret the values themselves. You can obviously give functions for that, like turning a string into an integer and whatnot, but I would keep that responsibility out of the parser since it's a lot of trouble.
>>
>>56519157
not an edit m8
>>
>>56515662
Cirno is cuter than pretty code!
Happy Cirno Day!
>>
>>56517179
pajeet tier solution coming through

import Text.Printf

main :: IO ()
main = do
n <- readLn
star 1 n

star :: Int -> Int -> IO ()
star x y
| x == y = printf "%s*%s\n" (space x) (space x) >> star (succ x) (pred y)
| x < (x+y) = prettyprint (min x y) (pred (abs (x-y))) >> star (succ x) (pred y)
| otherwise = return ()

space :: Int -> String
space n = take n $ cycle " "

prettyprint :: Int -> Int -> IO ()
prettyprint n x = putStrLn $ concat [space n, "*", space x, "*", space n]
>>
>>56519220
this is really bad anon

>>56519149
>>56519206
are you even british
>>
>>56519234
I know
>>
>>56519118
They are insults. They are reactions. Reread the definition.
>>
>>56519177
How does one start a personal project? At work it's easy: pick up tickets and do them, have the occasional meeting where we break down, estimate etc...
At home, I can't start something noticeably-sized for the life of me. How do you guys do it? Do you just plan and plan?
>>
>>56519277
Similar to you, I would like to do a big project but everything big either seems boring as fuck or too hard, or already existing
>>
>>56519242
>They are reactions
good
>>
>>56519177
>Why does the library need to know about actually interpreting the values into their desired types? The user already needs to take that map and interpret it into a real structure
Eh, no? That's the whole idea. The user just registers a pointer to a variable, and a label, and the lib takes care of reading the value from the file and assigning the value to the variable.
>>
>>56519234
no not even from a country with english as the official language, I just like the word
>>
>>56519312
Then why do you need to store heterogeneous functions? The functions can be of type
void (*)(char const *, void *)
, and do the writing to the pointers themselves. The library ends up completely type-agnostic.
>>
>>56519277
Open visual studio, new project, write "hello world", compile, run, change "hello world" printout to short description of project idea. Boom, project started. Continue on from there.
>>
File: owl.jpg (428KB, 1024x683px) Image search: [Google]
owl.jpg
428KB, 1024x683px
>>56518763
>You can't cast function pointers to void *.
int f() {
return 3;
}

void *g() {
return reinterpret_cast<void*>(&f);
}


Assembly output

1 f(): # @f()
2 movl $3, %eax
3 retq
4
5 g(): # @g()
6 movl f(), %eax
7 retq
8
9
>>
>>56519220
>>56519239

cross r = unlines (map line range)
where range = [0 .. pred r]
line y = map (disp . cond y) range
cond y x = (x == y) || ((r - x) == succ y)
disp True = 'X'
disp False = '.'
>>
>>56519381
Then the lib doesn't know as what type to interpret the value string from the file as.
>>
>>56519302
That too, but my biggest issue right now is the design aspect of it. At work, there's always a task, and it's as straightforward as fitting a missing piece of a puzzle. At home, trying to come up with a design feels like an endless wave of distractions and "I have no idea how to do that yet" over and over.
>>56519391
Thanks, but before I know it, I end having several stub types and by the end of the session I already forgot the precise responsibility each should have.
>>
>>56519456
It doesn't have to. The user provides the functions to interpret from strings to values, the library just deals with the structure of the config file. You implied in >>56519100 that the types are arbitrary, so how is the library supposed to deal with them by itself?
>>
>>56519434
Ok I see how this works now, didn't really think of it like that at all
>>
>>56518301
>fuck you tier
Are bootloaders that hard to do?
>>
>>56519493
Don't try to invent the design all at once. Start with "hello world" and make very small changes. None of them should take more than 15 minutes at first. Each change should bring your program just a little closer to the functionality you want it to have.
>>
>>56519497
>The user provides the functions to interpret from strings to values,
But i don't want the user to have to deal with this. This is what the lib is for.

> You implied in >>56519100 (You) that the types are arbitrary, so how is the library supposed to deal with them by itself?
I was going to use templates for that.
>>
>>56519571
templates only exist at compile time
>>
>>56519548
Makes sense. I guess I didn't try that because I'm afraid that, 2 days in, I'll suddenly realize I'd been working on the wrong thing.
>>
>>56519571
In that case, yes, the library is going to have to anticipate every single type anyone will want to use.

Templates won't help you here.
>>
>>56519548
This.
>>
>>56519588
I know. This is fine because all the variables (or at least their declarations, if you want to be picky) to be filled also exist at compile time.
>>
>>56519596
>I guess I didn't try that because I'm afraid that, 2 days in, I'll suddenly realize I'd been working on the wrong thing.
That will happen sometimes anyway. It's one of the risks you take when inventing things. If it happens after only 2 days and not a year, then you're doing great.
>>
>>56518724
Use ...
>>
>>56518301
are there any more useful pics/infographics like pic related for beginning coders? Some of the discussions here are interesting but others are way too advanced. Infographic dump, please?
>>
>>56518769
How do you even plan on using them? If you intend to call them, you could create your own map-like implementation that takes the parameter types too, as template args. Otherwise, create a wrapper or a base class that you can use as the type.
>>
>>56519662
I guess I'm not making anything by not even trying either... Thanks for the encouragement!
>>
File: 8.png (302KB, 1920x1080px) Image search: [Google]
8.png
302KB, 1920x1080px
>>56519752
>>
>>56519434
>>56519523
Ok this is a lot nicer now I see the sensible way to solve it, thanks

main :: IO ()
main = do
n <- readLn
mapM_ putStrLn $ star (pred n)

star :: Int -> [String]
star n = map (row ys) ys
where row xs y = map (output n y) xs
ys = [0..n]

output :: Int -> Int -> Int -> Char
output len x y
| x == y || len - y == x = '*'
| otherwise = ' '
>>
>>56519776
>you could create your own map-like implementation that takes the parameter types too, as template args.
I don't see how.
>>
>>56519752
>Some of the discussions here are interesting but others are way too advanced
Google everything you don't understand and if you don't understand what you find, google that too. It's called recursion. Once you understand recursion, try tail call optimizing your learning process.
Also, try not to take sides the way many here do. Some discussions get quite passionate and biased here. No matter what some may say here. I didn't learn programming from infographics.
>>
File: ːthumbsupː.png (11KB, 120x120px) Image search: [Google]
ːthumbsupː.png
11KB, 120x120px
>>56519819
>>
>>56519914
My point is, come up with a concrete API for whatever you're trying to do and use that to inform your design. Come up with a hypothetical function that does what you want it to do. What would its signature look like?
>>
>>56515947
>reinventing the wheel
>>
>>56518870
Switch case and X macros?
>>
>>56520011
main(){
int varA;
float varB;

ConfigParser p;
p.RegisterVar("foo", &varA);
p.RegisterVar("bar", &varB);

p.ReadConfigFile();

cout << varA << " " << varB;

return 0;
}

and then the cfg file would like like this
foo: 5
bar: 3.7


You mean like this? This is what i had in mind.
>>
>>56515947
That's because I don't do bootloaders. I do websites. I make great websites, they're really great. I make the best websites. Mexico is paying for them.
>>
I need some advice/pointers/more on RDBMS and graph/network representations of data.

For my project, postgresql is used and works for everything except one feature I want to have, a must have. This involves graphs. Directional graphs, to be precise. (let's go with acyclic for simplicity)

There are some documentation on this:
http://www.slideshare.net/quipo/rdbms-in-the-social-networks-age

But not quite enough for me to develop with certainty. Does any of you know of any example implementations? I'm going ahead to try developing this on my own, but any pointers/help is appreciated.
>>
>>56520191
That will work for every type you can anticipate. Internally, you should still use the trick where you monomorphize by making the stored function write to a void pointer - the stored function just isn't supplied by the user. You could potentially overload RegisterVar to allow the user to supply a function when one isn't built-in.
>>
>>56515846
But you can just define a class that consists of attributes alone though if you REALLY needed a struct.
>>
is coding openCV projects in C a bad idea?
>>
>>56516597
Depends who you ask and when you asked them.
>>
>>56520286
Isn't it better to just to map the lables to data types by way of an enum, then?
If i can't have templates generate the overloading automatically.
>>
>>56516597
No one knows what any "oriented" design is.
>>
>>56520191
Yes, that makes what you're thinking way clearer. Would something like this do it for you?
class ConfigParser {
map<string, unique_ptr<TypeBase>> m;
public:
class TypeBase {}
class IntType : public TypeBase {
int& out;
public:
IntType(int& out) : out(out) {}
void read(string s) {...}
}

template <typename T>
void RegisterVar(std::string, T& out) { } // specialize this
};
>>
File: 1465760139985.jpg (43KB, 511x477px) Image search: [Google]
1465760139985.jpg
43KB, 511x477px
>>56518744
>Libraries are bad

Desu lad looks like someone has never had to deliver code on a tight schedule.
>>
>>56520467
Actually, you don't even need the void pointer in the function. Here's what I mean:
class ConfigParser {
public:
template<class A>
void RegisterVar(std::string key, A *ptr);

private:
std::map<std::string, std::function<void(std::string)>> vars;
};

template<>
ConfigParser::RegisterVar<int>(std::string key, int *ptr) {
vars.insert(key, [](std::string literal) {
// don't actually do it this way
*ptr = std::stoi(literal);
});
}

template<>
ConfigParser::RegisterVar<float>(std::string key, float *ptr) {
vars.insert(key, [](std::string literal) {
// don't actually do it this way
*ptr = std::stof(literal);
});
}
>>
>>56520504
what does unique_ptr do?
>>
>>56520576
Oh, I suppose the capture on those lambdas needs to be [=].
>>
>try to do something really simple
>get arcane compiler error
>google it
>literally nobody else has ever had this problem

I fucking hate F#.
>>
>>56520628
std::unique_ptr is a C++11 addition, a pointer that deallocates pointed-to memory on destruction (it "owns" the memory), so you don't have to. It's movable, but uncopyable, to prevent double-frees.
>>
>>56520681
Probably because you used quotation marks...
>>
>>56520681
>F#
why
>>
>>56520681
Haskell
>>
>>56520681
isn't F# a bit of a meme lad?
>>
>>56520694
So it doesn't HAVE to be a unique_pointer there?
But if i store a pointer to TypeBase then i've essentially cast away all the functionality of the derived type, haven't i? I don't see how that helps.

>>56520576
This looks promising.

I'm gonna see if i can do something with this tomorrow when i'm less tired.
>>
>>56520819
It's worth noting that >>56520576 does the exact same thing as >>56520504, just without the ridiculous boilerplate.
>>
>>56520681
Perfect example of why popularity of a language can increase its productivity, with the sheer amount of pajeets having the same exact issue and then blogging about it.
>>
>>56520819
>So it doesn't HAVE to be a unique_pointer there?
Not at all, but unique_ptr spares you from having to delete them all at the end. Either way, the other guy posted better code, go with >>56520576.
>But if i store a pointer to TypeBase then i've essentially cast away all the functionality of the derived type, haven't i? I don't see how that helps.
I intended read to be a virtual function, but forgot to add that to the code, I rushed the thing a bit.
>>
>>56520841
I don't see how.
In the one i'm storing a pointer to a function. Then i just have to figure out how to force the compiler to compile all relevant template instantiations, which may or may not be a problem.

In the other i have a pointer to a base class... oh wait, that means read() should be virtual for that to work, right?
>>
>>56520681
I do also, that's why if you want a proper functional language I'd recommend >>56520719
>>
>>56520981
They're equivalent, it's just that >>56520504 leaves out a ton of stuff compared to >>56520576. It's using the whole Java-esque "functional interface" thing without lambdas instead of first-class function types and lambdas.
>>
>>56520950
>>56520841
/dpt/ has actually been helpful to me, for once. I feel energized for tomorrow.

Thanks, guys!
>>
>>56520981
>In the other i have a pointer to a base class... oh wait, that means read() should be virtual for that to work, right?
That's just to provide what std::function is already doing for you in the other example.
>>
File: Example3.png (39KB, 863x737px) Image search: [Google]
Example3.png
39KB, 863x737px
>tfw when i just finished up my vector graphics animator.

This program was a bitch at every turn.
>>
File: screen.png (54KB, 1280x800px) Image search: [Google]
screen.png
54KB, 1280x800px
>>56515662
>How are you celebrating Cirno Day?
By writing dumb slow 6502 assembly translator in pure busybox sh.
>>
>>56521032
That GUI style is fucking classic though
>>
In C++, can lambda functions only be defined inside other functions? It doesn't seem to let me define them anywhere else.
>>
>>56521168
They're valid expressions, they can go anywhere.
>>
>>56520681
>try to do something really simple
>get arcane compiler error
>google it
>literally nobody else has ever had this problem
Go on then, what is this really simple thing that no one has ever done before.
>>
>>56521032
The shit. Why the fuck did you make this?
>>
>>56521032
>>56521233
Gotta say, it looks real impressive m8. But why?
>>
File: Reworked.png (275KB, 1920x1080px) Image search: [Google]
Reworked.png
275KB, 1920x1080px
Now this, THIS I am more proud of.
>>
>>56521272

Well, you said you were going to do it and you've done it. Congratulations.
>>
File: whos_that_pokemon.png (2MB, 1920x1080px) Image search: [Google]
whos_that_pokemon.png
2MB, 1920x1080px
>>56521272
What's the language?
>>
File: unknown.png (216KB, 1234x385px) Image search: [Google]
unknown.png
216KB, 1234x385px
>>56521032
That productive autism, though.
>>
File: disapproving lou dobbs.png (166KB, 249x337px) Image search: [Google]
disapproving lou dobbs.png
166KB, 249x337px
>>56521345
What do you think?
>>
>>56521272
>.each do |k,v|
>conf = config[k]
>field = case conf
>>when String then conf
>>...
>>else raise "malformatted #{k} field"
>>end
>instance_variable_set("@#{k}", field)

You've repeated yourself again
>>
>>56521345
Cubic Zirconia
>>
>>56521363
After thinking about it very deeply. Probably Ruby
>>
>>56521206
This is what I have:
class Foo {
private:
function<void(void*)> Bar;
};


And I have to declare the Bar function inside one of Foo's functions, like this:

Foo::Foo(){
Bar = [=](void* i){
cout << i << endl;
}
}

If I try to declare it any other way, it gives me all sorts of errors. I would like to declare it by itself, just because I think it looks cleaner that way.
>>
>>56521359
>he/she
>not ze
IT'S THE CURRENT YEEEAAAARRRR
>>
>>56521345
EREN!
>>
>>56521359
I'd like to see Raine Rupert Revere work overtime during a cruch period.
>>
File: shillary disapprove.jpg (76KB, 1275x646px) Image search: [Google]
shillary disapprove.jpg
76KB, 1275x646px
>>56521369
No kidding.
>>
>>56521381
You can't define a method as a lambda
>>
>>56521359
That's a wide glabella
>>
>>56521381
>>56521404
You could have it as a member though
const auto Bar = [=](void* i) { cout << i << endl; };
>>
>>56521381
You can't do that with any field, though.
>>
>>56521381
>>56521404
Bar is not a member function of Foo, it's a member variable. The constructor assigns it to a value.
>>
>>56521366

Read the goddamn comments and you'll see there is a clear difference between both. One case statement concerns fields that can either be a string, an array of strings, or nothing. The other concerns fields that can either be strings or nothing, but may NOT contain arrays.
>>
>>56521233
>>56521262
>>56521359

i took a visual computing course as an elective and the semester project was to make a scene graph editor. i'm going through my old projects and extending their functionality so they don't look as trivial in my portfolio.
>>
>>56521345
Sapphire
>>
>>56521450
pretty cool anon. Well done.
>>
>>56521431
This could never work. Different lambdas have different types, they aren't erased.

>>56521433
It's the same code, it doesn't matter what it does.
>>
>>56521494
Provided the right signature, they convert to std::functions (at a runtime cost), what are you even?
>>
>>56521551
Did you give it a std function signature?
Do they convert on assignment?
>>
>>56521494

>it's the same code
>it doesn't matter what it does
Err... no. Two sections of code are only identical iff they do the same thing, and those two blocks are similar, but not identical, because they vary in whether or not they will accept array types.
>>
>>56521381
you edx too bro?
>>
>>56521578
Doesn't matter, you repeated the same code
>>
>>56521604

Are you retarded?
>>
>>56521615
No, you could've avoided repeating that code.
Ruby even has eval.
>>
>>56521630

>eval
This is where we go into a case of can vs should.
>>
>>56521665
It's ruby, it already performs like and is unsafe as shit
>>
>>56521578
Then just vary the "when Array" condition, instead of writing the same whole iteration twice with a tiny tweak.
>>
>>56521698
>>
>>56521574
http://en.cppreference.com/w/cpp/utility/functional/function/function

Constructor #5. It works by wrapping it and assuming it has an operator().
>>
>>56521706
Regardless the cleaner way to do this would be to make it a member, set it in the constructor, and have the "member function" (lambda member value) reference the member
>>
>>56521630
I really hope people like you never get to work on any real code.
You are the academics equivalent of the java enterprise developer.
No, wait, you ARE the equivalent of the java enterprise developer, because you're willing to ignore any other aspect of good code in favor of not repeating yourself.
>>
>>56521879
>good code
>the same code twice

learn the difference
knowing is half the battle
>>
Okay, are we happy now?

# Resolve all flag, directory, and target information fields.
# The hash table below maps each field to an array of 2 elements.
# The first of these concerns whether the field may be an array.
# The second concerns the default element if the field is unspecified.
# All of these will be converted into an instance variable for fast access.
{ "sources" => [true, ["."]],
"headers" => [true, nil],
"libdirs" => [true, nil],
"platforms" => [true, nil],
"libraries" => [true, nil],
"objects" => [false, "."],
"outdir" => [false, "."],
"output" => [false, "main"],
"debug" => [false, "-g"],
"release" => [false, "-s"],
"cflags" => [false, "-std=c11"],
"cxxflags" => [false, "-std=c++14"],
"ldflags" => [false, nil]
}.each do |k,v|
conf = config[k]
field = case conf
when String then [conf]
when Array then
if v[0] && conf.all? { |f| f.is_a? String } then conf
else raise "malformatted #{k} field"
end
when nil then v[1]
else raise "malformatted #{k} field"
end
instance_variable_set "@#{k}", field
end
>>
>>56521879
>you're willing to ignore any other aspect of good code in favor of not repeating yourself.
Oh jesus christ, I worked with a guy like this before. He made the most horrific architecture decisions and defended with "DRY = Don't Repeat Yourself :^)" like he was hot shit for knowing that.
>>
>>56521950
>else raise "malformatted #{k} field"
>else raise "malformatted #{k} field"

Why don't you just use monads?
>>
>>56521950
>true x5
>false x8

7zip is a better programmer than you
>>
>>56522012

There are two cases that lead to an error, and as such, two error strings. I daresay at this point, if you are going to critique, you should make a suggestion that makes sense. For instance, which monad, and why?

>>56522075

Well I originally just did two case statements, but apparently we're going for more compact code now.
>>
>>56521950
>lib[dir]s
>[out][dir]
>[out]put
>c[flags]
>c[xx][flags]
>ls[flags]
>c[++]
i could point out more pointless repetition LMAO GIT GUD EMBRACE HASKLEL
>>
>>56521950
>c++
Can't you multiply that + symbol instead of typing it twice?

DRY, motherfucker.
>>
>>56522075
What's wrong with that?
>>
>>56522163
DRY autists would do something like
doubleplus() { ++ }
cdoubleplus()

I've literally seen retards write shit like that that's longer and less readable because "can't repeat yourself LEL" as if they have no idea why that principle exists.
>>
>>56522212
What if you change the definition of the meaning of "two plus signs" or C++ changes its name to "Cpenispenis"?

One would cause one method change.

The other is 30,000 lines of code.
>>
>>56522144
with monads, a lot of control flow stuff becomes first class

i don't know how rubyceptions work but you could have something like

ifWellFormed k b tru = if b then tru else raise "malformatted #{k} field"

ifWellFormed k (vv[0] && conf.all? { |f| f.is_a? String }) conf
>>
>>56522242
Are you seriously defending this shit?

If you want to chance the meaning of ++ then you replace ++ with your new definition, and make a separate function if you use it a few times if it's complex.

You don't complicate the codebase for the unlikely off chance that you might have needed that extra complexity in the future.
>>
>>56522147

Yeah, I'm not going to touch upon the field names. Point here is to convert fields from a JSON file to instance variables in the class so I don't have to regularly read from a hash table. I've already decided upon how most of the JSON file structure should be set though, so I can't really change that.

>>56522163

Doing so would require more characters than simply "++"

>>56522242

Yeah, it's not changing. At best, I'll end up changing the flag from something like -std=c++14 to -std=c++17 sometime along the line. That said, I do not intend to support languages other than C and C++, and I do not intend to support toolchains other than gcc or clang in the near future.
>>
>>56522242
one would cause one method change with a really misleading name
the other is 30000 lines of code, but at least won't be misleading

the issue with DRY is that people attempt to avoid the repetition of syntax, not some concept that can be assigned a proper and understandable name.
try to avoid semantic repetition, not syntactic repetition.
also, DRY results in stronger coupling, which is why instead of trying to push DRY to the max, you should find a sweet spot between the two aspects of good code (simplicity and other things are obviously affected too).
Thread posts: 337
Thread images: 32


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