/script>
[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: 314
Thread images: 38

File: dpt_flat.png (102KB, 1000x1071px) Image search: [Google]
dpt_flat.png
102KB, 1000x1071px
Old thread: >>60825429

What are you working on, /g/?
>>
First for C
>>
File: 1496616527752.jpg (52KB, 331x331px) Image search: [Google]
1496616527752.jpg
52KB, 331x331px
>>60832529
Is there a non-retard version of this thread?
>>
So I made a strategy for learning C++. First I will read this book:
http://www.cplusplus.com/files/tutorial.pdf
And then I will read "Effective C++"

Is this a decent approach?
>>
>>60832541
/fpt/
>>
>>60832529
Lisp
>>
>>60832547
Make one and please contain your autism there
>>
>>60832541
Come back when all of the americans have gone to bed.
>>
File: languages3.png (17KB, 522x384px) Image search: [Google]
languages3.png
17KB, 522x384px
Reminder that this is true no matter how much you deny it
>>
>>60832555
I think it's mostly gooks and eurocucks
>>
>>60832555
Europeans are even more subhuman though.
>>
>>60832561
You are not old enough to use this site
>>
>>60832529
Writing libc on ASM
Learning Haskell
Trying to prepare for interview as a c++ dev
>>
>>60832561
Rust says no.
>>
>>60832573
>>60832578
>responding to bait
>>
>>60832585
Is Isreal paying you for each replies?
>>
>>60832584
Before Rust that wouldn't be bait. All other productivity-oriented languages have to be extraordinarily micro-optimized or resort to FFI to compete with C, FORTRAN, C++ and so on.
>>
>>60832578
Rust could certainly have good performance (although it's not quite there yet), but its type system isn't powerful and flexible enough for it to offer fast development.
>>
give me more algorithm homework to solve. i need to brush up for code interviews. even though i hope i don't get a job coding because i want to get the full scholarship + pay for a network security masters degree at my university paid for by the DOD. that'd be so fucking amazing if i got that. but can't put all my eggs in one basket
>>
>>60832592
Who/what is Isreal?
>>
Programming socks just came in the mail, now i will put on then and a mini skirt and continue on my android app.
>>
>>60832616
Don't they enslave you for several years or else you have to pay it all back?
>>
>>60832608
>but its type system isn't powerful and flexible enough for it to offer fast development.

You have algebraic data types (deceptively called "enums"), typeclasses (traits) and recently gained support for higher kinded types (see https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md#encoding-higher-kinded-types ).

You definitely got all you need to be very productive. Dependent types would be nice, though. But then again, not even Haskell has them.
>>
>>60832639
you have to work there during the summers for no additional pay and also for X years after graduation (paid ofc). but it's a full scholarship for a MASTERS degree and ~$30k/y on top of that. going to pour my heart and soul into making the best resume possible for that and going to grammar check after my chinese professor if he gives me a letter of recommendation for it
>>
File: Python_function.png (60KB, 630x340px) Image search: [Google]
Python_function.png
60KB, 630x340px
>>60832540
So you say "systems work" is an application that's still to be filled out with such languages?
And is there maybe a recorded interview or so with the guy?

>>60832476
A programming paradigm in which mathematical functions are treated as first class citizens. By function we mean something which for a given input returns a particular output.
Pic related is an example of a Python "function".

>>60832467
>>
File: dlang_chan.jpg (70KB, 349x368px) Image search: [Google]
dlang_chan.jpg
70KB, 349x368px
Threadly reminder that dlang-chan has RAII; she's quite fast in execution and compilation; she's becoming fully memory-safe; and she's super duper cute! Say something nice about her, /dpt/!

>Tour
http://tour.dlang.org/
>Books
https://wiki.dlang.org/Books
>GC
https://dlang.org/blog/2017/04/28/automem-hands-free-raii-for-d/
https://wiki.dlang.org/Libraries_and_Frameworks#Alternative_standard_libraries_.2F_runtimes
>>
>>60832666
>not even Haskell
What is that supposed to mean? Are you implying that Haskell's type system is somehow not complete trash?
>>
>>60832585
Now just pose with your copy of K&R and post pics.
>>
>>60832693
i-i can do that
>>
>>60832666
Are those true HKTs? Or yet another version of pseudo-HKTs that are strictly less powerful than real HKTs?

Regardless, I'm not satisfied. Dependent types are so ridiculously powerful and productivity-boosting that there's not really a good reason not to have them.
>>
daily reminder that real programmers don't use typed languages
>>
Anyone used Qt here. How do you even write application logic with this shit. All I can do is use it's objects with its widgets. Thinking of just trying another GUI library
>>
>>60832618
Isreal is real.
>>
File: 2362514.png (283KB, 1816x2446px) Image search: [Google]
2362514.png
283KB, 1816x2446px
>>60832529
A video game I am fixing client to server communication at the moment lots of bug squashing but getting pretty close to having a test prototype of a full round.

https://www.youtube.com/watch?v=vF3lIg9cHJ8
>>
>>60832739
You're supposed to mix your business logic with your Qt stuff, it basically eats your entire project and makes you fully reliant on qt tools to even compile it.

Just use wxwidgets
>>
File: 318.gif (228KB, 400x250px) Image search: [Google]
318.gif
228KB, 400x250px
If I have a root folder that contains a folder called "src" that has my source code and a folder called "tests" that has a bunch of test code, what's the simplest way to write a makefile to compile build/test programs?
>>
>>60832779
It's really easy if you just want a binary.
If you want to compile to an obj/ it's slightly harder
>>
File: 99972327728055.jpg (37KB, 599x639px) Image search: [Google]
99972327728055.jpg
37KB, 599x639px
>>60832754
>your entire project and makes you fully reliant on qt tools to even compile it

Why do so many faggots talk about this garbage as it was godsend, fucking stackoverflow
Wasted so much time on it
>>
File: 6935824896.jpg (62KB, 634x438px) Image search: [Google]
6935824896.jpg
62KB, 634x438px
Anyways like the OP Asked I am programming a video game I am getting close to having an open public test.
>>
>>60832541
Come to /math/ in /sci/. We have dank memes.
>>>/sci/8962385/
>>
File: 528582.jpg (167KB, 1280x720px) Image search: [Google]
528582.jpg
167KB, 1280x720px
I hope I can make it to your goys satisfaction.
>>
>>60832669
>So you say "systems work" is an application that's still to be filled out with such languages?

Yes. There are domains such as embedded and hard-real time where even with a language such as Rust we need to drop down to unsafe and deal with the guts of a Von Neumann architecture.

>And is there maybe a recorded interview or so with the guy?

Google him, Ruby fags form huge cults of personality around their core members so you're bound all the info you'll ever want.

If you really want to know why it's worth it to target the Erlang stack, watch Erlang: The Movie. It's 11-12 minutes long and presents it clearly in a nerdy as fuck 80's fashion.

>>60832712
>Are those true HKTs?

Depends on where you draw the boundary. They mention its limitations: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md#limitations

As for dependent types, there are no non-research languages providing them yet. Idris is the only one that actually seems to intend at some point to reach for industry acceptance, so I'm keeping an eye on it.

It's funny really, they're so good for encoding business rules one would think srsfags with no hard real time guarantees like banks would jump at the chance to have them.
>>
>>60832779
Here is my skeleton makefile I use for my simple projects
CFLAGS += -Wall -Wextra -std=c11 -g -Og
LDLIBS =
CPPFLAGS =

SRC = $(shell find . -name '*.c)
DEP = .depend

all: progname

%.o: %.c
@mkdir -p $(DEP)/$(@D)
@$(CC) $(CFLAGS) $(CPPFLAGS) -MMD -MF $(DEP)/$*.d -c $< -o $@
@echo -e "CC\t$<"

progname: $(SRC:.c=.o)
@$(CC) $^ -o $@ $(LDLIBS)
@echo -e "LD\t$@"

clean:
$(RM) $(SRC:.c=.o) proname
$(RM) -r $(DEP)

.PHONY: all clean

.PRECIOUS: $(DEP)/%.d

-include $(addprefix $(DEP)/, $(SRC:.c=.d))

It handles rebuilding source files when headers change, but doesn't put shit into a build directory.
>>
>>60832854
But I'm not a kitsune anon

How do I become a kitsune?
>>
>>60832902
SRC = $(shell find . -name '*.c')
>>
>>60832902
how are actually you retarded for using pure makefile instead of at least cmake?
>>
>>60832934
>how are actually you retarded
What did he mean by this?
>>
File: 1494915863144.jpg (152KB, 1200x899px) Image search: [Google]
1494915863144.jpg
152KB, 1200x899px
>>60832905
Get Ran-somware on your computer.
>>
>>60832934
pure makefiles are simple to understand and don't require a goddamn configure script

>>60832754
wxwidgets is c++ only
If I'm writing a gui application, can I simply compile the C portion of the program into objects with gcc, compile the GUI C++ portions with g++ and then link the resultant objects together without issues?
>>
>>60832800
To a binary is fine, just have no idea how to write makefiles, especially telling them to compile files in different directories.
>>
>>60832529
Does anyone else experience semantic satiation when they're writing a program and you use a variable name too many times in a row? After writing the word "money" a few times, the word starts looking weird and I have to remind myself what it means.
>>
>>60833060
How the fuck do you even use the same word over and over within the same scope?
Sounds like a retard problem.
>>
>>60833060
my brain hurts

that image is like a duodecuple shot of absinthe
>>
>>60833100
well anon the answer is Java.
Money toddsMoney = new Money(3,50);
Money sarasMoney = new Money(2,50);
Money totalMoney = sarasMoney.add(toddsMoney);
System.out.println(totalMoney);
>>
I am a snake
>>
>>60833134
This is just shit code.
Also, I hope this is stored in ints and not floats.
>>
>>60832854
What kind of stuff do you discuss there?
>>
>>60833060
That's usually a hint that you might need to do write some abstraction.

>>60833134
In this case, you need to abstract over a shit language.

Everything in Java induces semantic satiation.

But in any case, your code could probably be better.
>>
>>60833160
ya it's ints, other than changing the variable names, what else could I do to make these 4 LOCS not shit?
>>
learning how to make mobile apps with Xamarin in C#, its fun xd
>>
>>60833164
Why don't you take a look?
>>>/sci/mg
>>
>>60833218
you could stop using the word money

do you also do int myInt = new Int?
>>
>>60833218
For that particular snippet?

System.out.println(new Money(6));


I'm too lazy to look at what Money's toString does, so you can even unroll that manually into a string.

If you want a more generalized version, you'll have to explain what your thing is supposed to do.
>>
>>60833271
based
>>
>>60833134
God Java is fucking ugly piece of fucking shit.

t. C++ lord
>>
>>60833303
Pot calling the kettle black if ever I've seen an example.
>>
>>60833007
help
>>
>>60833303
C++ is the second ugliest (mainstream) language ever. Perl, of course, being first.
>>
>>60833134
>new Money(3, 50)
>not new Money(new Dollars(3), new Cents(50)
kys sempai
>>
>>60832561
Ruby should be in the lower lefthand corner.

Also you need a third corner in the middle for Crystal. Good performance. Fast development. The kicker: empty as fuck standard library and no one else in the world uses it.

There are probably a few other languages that could go there too.
>>
>>60833457
>not new Money(Arrays.asList(new Dollar(), new Dollar(), new Dollar(), new Quarter(), new Quarter());
>>
>>60833505
>not just new()
tfw bitches think they know oop but they ain't know jack shit
>>
>>60833502
>Good performance. Fast development.
Impossible.
>>
>>60833521
crystal-lang.org
>>
>>60832561
I fucking hate this picture. The positive aspects should be the edges, not the corners.
>>
>>60833535
but senpai a corner is just the edge of a non-differentiable one dimensional manifold
>>
What's the best book on C#? C# Primer was disappointing.
>>
>>60833505
>not
new Money(Arrays.asList( 
BureauOfEngravingAndPrinting.create(Denominations.DOLLARS, 3),
BureauOfEngravingAndPrinting.create(Denominations.QUARTERS, 2)
));
>>
File: 15626158.jpg (29KB, 716x403px) Image search: [Google]
15626158.jpg
29KB, 716x403px
$wc
import std.algorithm, std.stdio, std.string[spoiler][/spoiler];
// Count words in a file
void main()
{
auto file = File(readln().strip(), "r"); // Open for reading
writeln(file.byLine().map!split.map!(a => a.length).sum());
}
>>
Showcase your language.
>>
>>60833614
main = length . words <$> (getLine >>= readFile)
>>
>>60833614
>not closing the file
>>
>>60833535
Corners are pretty edgy imo.
>>
>>60833614
>>60833653
@wc can also count characters and lines
>>
>>60833614
c#?
>>
>>60833696
Eww no
It's D
>>
>>60833669
You don't need to close files if you have RAII.
>>
>>60833662
How about your self respect?
>>
If I'm writing automated scripts that reads .csv files and stores the entries in a database, what "level" am I at? pls no bully
>>
>>60832561
How do you define "Fast development"? What specific use cases do your examples have that make development faster compared to other languages?
>>
>>60833711
This is elementary level.
>>
>>60833711
beginner
>>
>>60833711
CRUD SCUM (i.e. beginner)
>>
>>60833711
not-researching-existing-tools-that-do-that-for-you tier
>>
>>60833704
I feel pretty good about myself when I'm dressed for programming success!
>>
File: 8923415.png (154KB, 400x347px) Image search: [Google]
8923415.png
154KB, 400x347px
>>60833614
Love it, anon!
>>
Fast development means the time taken to produce a working, correct, non-trivial system. Things like a powerful static type system and property-based testing libraries help in this. Dynamic typing (usually), poor tool support, and having to write thousands of unit tests do not.

Sure, you can get some shit sort-of working in Python quickly, but I care about the whole development lifecycle, not how long it takes to get a basic prototype working. Big fixing and refactoring is hell in those sorts of languages.
>>
>>60833747

for what? the automation?
>>
What is
1. map
2. filter
3. zip
4. reduce
5. fold

In your language?
>>
>>60832934
>CMake
Let me guess, you use C++ too?
>>
>>60833761
>correct
>fast development
>non-trivial
Choose any two.
>>
>>60833809
Fast is relative, anon.
>>
>>60833770
>map f xs
xs.stream()
.map(f)
.collect(Collectors.toList());

>filter f xs
xs.stream()
.filter(f)
.collect(Collectors.toList());

>zip xs ys
IntStream.range(0, Math.min(xs.size(), ys.size()))
.steam()
.map(i -> new Pair(xs(i), ys.get(i))
.collect(Collectors.toList())

>reduce f xs
xs.stream()
.reduce(f)
.collect(Collectors.toList());

>fold f xs
isnt fold and recude the same thing?
:
>>
>>60833822
Fast is ALREADY relative. Software that is correct and non-trivial cannot be developed as quickly as software that is trivial or incorrect.
>>
>>60833855
>isnt fold and recude the same thing?
Not at all.
>>
>>60833859
Incorrect software is useless.
>>
>>60833770
Fold is enough to define most if not all of those.
>>
>>60833864
be more specific then
>>
What did Andrei mean by this? Feeling like a brainlet here
>>
>>60833895
fold has type
forall a b. b -> (b -> a -> b) -> [a] -> b


reduce is an abomination
>>
>>60833933
Oh I get it now
>>
>>60833878
Then speed of development can't be all that important.
>>
>>60834031
I charge $60/hour to program, you tell me.
>>
>>60834031
It's a lot faster to write correct software in Idris than it is in Python.
>>
>>60834088
That doesn't have anything to do with Idris being "faster to develop in" than Python though.
>>
What's a language that won't make me want ot kill myself.
>>
>>60834109
Memes
>>
>>60834109
Not rust, for sure
>>
>>60834109
Developing incorrect software isn't development at all.
>>
>>60834109
Go!
>>
>>60834136
>meme
>>>/v/
>>
>>60834109
language doesnt really matter. try maintaing a bad codebase. THAT makes you want to kill yourself
>>
>>60834153
Definitely a bot
>>
File: gotard.png (20KB, 300x441px) Image search: [Google]
gotard.png
20KB, 300x441px
>>60834152
>>
File: 1464315477104.jpg (41KB, 551x720px) Image search: [Google]
1464315477104.jpg
41KB, 551x720px
Should I start learning Rust?
>>
>>60834165
go is fine
>>
>>60834152
I think D is even more intuitive than Go, anon.
>>
>>60834169
Rust is a meme
>>
>>60834169
If you like wasting you time on the flavor of the month.
>>
>>60834152
Why won't Go make me die?
>>
File: 1488818361206.png (289KB, 700x740px) Image search: [Google]
1488818361206.png
289KB, 700x740px
>>60834186
>flavor of the month.
It's not a topic of this month, anon
>>
>>60834165
>>60834181
>>60834188
You misunderstand, anons, I want that anon to go; as in he should leave because he's asking a retarded question.
>>
>>60834200
Sure
>>
>>60834184
Can you elaborate?
>>
>>60834184
>meme
>>>/v/
>>
>>60834221
> >>>
>>>/trash/
>>
>>60834221
It's got a 7 minute refresh rate
>>
>>60834231
>implying it's a bot
>>
>>60834165
problem: my go code looks like this
a, err := doA()
if err != nil {
return nil, err
}
b, err := doB(a)
if err != nil {
return nil, err
}
c, err := doC(b)
if err != nil {
return nil, err
}
... and so on ...

Stack overflow answer: "its not so bad"
https://stackoverflow.com/questions/18771569/avoid-checking-if-error-is-nil-repetition

topkek in haskell this is just
sequence [doA, doB, doC, ... ]
>>
>>60834240
Anything else you be sad, tbqh
>>
>>60834243
>Not meeting preconditions, requiring errors
Wewlad
>>
just wrote a few quick programs to help my mom with grading. completely simple stuff and you could just use a calculator, but i'm a complete beginner and it's cool actually applying what i've learned to a real life problem. Also it's slightly faster than using a calculator.
>>
>>60834457
post your mom
>>
QUICK, MAKE A PROGRAM THAT GIVEN A STRING AND AN INTEGER WIDTH, WILL OUTPUT THE STRING WRAPPING AT WIDTH, HOWEVER, WORDS CANNOT BE LEFT SPLIT IN THE MARGIN.
I.E. NO
Test string is te
st.

IF WIDTH IS 17

KEEP IN MIND NEWLINES

PROTIP, BRAINLETS CAN'T DO THIS
>>
>>60834472
THE CORRECT OUTPUT FOR THAT IS
Test string is
test.
>>
>>60834243
in c this is just
void* doSequence(void*(**sequence)(void*), int n) {
void* param = 0;
int i; for (i = 0; i < n; i++) param = sequence[i](param);
}
int main() {
void*(*sequence[])(void*) = {
doA, doB, doC/*, ...*/
};
doSequence(sequence, sizeof(sequence)/sizeof(*sequence));
}
>>
>>60834494
kek
>>
>>60834494
fixed:
void* doSequence(void*(**sequence)(void*), int n) {
void* param = 0;
int i; for (i = 0; i < n; i++) param = sequence[i](param);
return param;
}
int main() {
void*(*sequence[])(void*) = {
doA, doB, doC/*, ...*/
};
doSequence(sequence, sizeof(sequence)/sizeof(*sequence));
}
>>
File: lang.rank_.617.wm_.png (155KB, 1250x1120px) Image search: [Google]
lang.rank_.617.wm_.png
155KB, 1250x1120px
They've updated the chart: http://redmonk.com/sogrady/2017/06/08/language-rankings-6-17/
>>
>>60834243
You fucking retard, the actions are dependent on the previous, and on errors too.
Should've used foldM and some Maybe there.
>>
>>60834606
>swift that high
wow
>>
>>60834606
>Doubt
>>
>>60834243
Can a gotard explain this code to me.
>>
>>60834606
>Common Lisp in the middle
Blub confirmed.
>>
>>60834648
I'm not a gotard but I can definitely explain that code. It's just chaining a bunch of function calls together but checking in between each call and only continuing if there hasn't been an error.
>>
>>60834610
>>60834494
(doA >=> doB >=> doC)
>>
>>60834472
import std.stdio;
import std.algorithm;
import std.range;
import std.conv;
import std.string;

void main(string[] args)
{
ulong limit = args[1].to!ulong;

string inputs, buffer;
while ((buffer = readln().strip()) !is null)
{
inputs ~= buffer;
}
each!writeln(inputs.chunks(limit));
}


 echo test string is test main test abc idk lmn abbbd | ./main 17
test string is te
st main test abc
idk lmn abbbd
>>
>>60834243
Lisp master race.
(loop :for action :in actions
:as (input err) := '(nil nil) :then (apply action input)
:unless (eq err nil)
:return err)
>>
>>60834734
Is that a complete program? I mean all you just did is write a function unlike me :^(
>>
>>60834243
It's just
doA()?;
doB()?;
doC()?;

in Rust.
>>
>>60834716
>test string is te
>st
You failed. Can you into comprehension, lol.
>>
>>60834750
disregard this, wrong anon
>>
>>60834754
Can you rephrase your question?
>>
>>60834765
Just make it such that words don't get split in the margin, like in >>60834490
>>
>>60834783
I think there is a hint of ambiguity in your question.

E.g. if after reading 17 chars if the character is not a ' ', I know I have to either go back to the previous word and start counting the next 17 chars from there OR I keep counting the next 17 characters
>>
>>60833662

So far you have none of the items you will need to program:

1. A computer with a respectable operating system and comfortable enough keyboard. This means no iOS devices.
2. A text editor that you are proficient with. If you are not proficient with any advanced text editors, just use Notepad++ or Gedit to start.
3. A terminal with Bash, zsh, or a similar shell.
4. A compiler or interpreter, depending on choice of language.
5. No external distractions.
6. A web browser with relevant documentation open.
>>
File: ....jpg (18KB, 480x270px) Image search: [Google]
....jpg
18KB, 480x270px
>>60833662
Don't forgot something to insert into your urethra. Otherwise your list is complete.
>>
>>60834841
The former.
>>
File: ran_delinquent.png (25KB, 120x234px) Image search: [Google]
ran_delinquent.png
25KB, 120x234px
>>60833662
>leotard
>tiara
T A C K Y
>>
>>60832542
You could then read about some C++11, C++14 and C++17 features. But yes focus on types, casting, class declaration-inheritance-implementation, headers and imports, cin and cout, fstream, pointers, passing by references and value, smart pointers, new and delete, function overloading, basic usage of templates, operator overriding...
>>
    file.byLine.each!writeln;

heh never touching the while loop again, too much writing
>>
>>60833770
1. undefined
2. undefined
3. undefined
4. undefined
5. undefined

What is fold for?
>>
>>60835010
https://dlang.org/library/std/algorithm/iteration/fold.html
>>
>>60835010
fold is reduce
>>
>>60833770
map
filter
fold/foldl/foldr/foldl'/scanl/scanr/foldM/foldMap/foldl1/foldr1/traverse/mapM
>>
>>60835032
oh and
zip zipWith mzip mzipWith

also ParallelListComp
>>
>>60833770
>map
mapcar, map
>filter
remove-if, remove-if-not
>zip
none, just use mapcar, since when it takes more than 1 list, it processes them in parallel until the shortest list ends
>reduce
reduce, more useful than haskell folds since it's not pure, also, it encompasses what foldl, foldr, foldl1, foldr1, and its strict variants do
you can use return-from and end evaluation
>fold
see reduce
>>
>>60829242
Yeah well he has a very good work ethic or loves what he does.
It's not for the casual employee. Its certainly abusive when they're not 100% in on it.

And there's even talk from experienced developers that it may not be productive. It certainly seems like it because it's the most important time to get shit done but there's no clear evidence of it being a good way to get shit done.

I think you can see how it's not for everyone though.
>>
File: ss-2017-06-10-07-35-36.png (14KB, 522x85px) Image search: [Google]
ss-2017-06-10-07-35-36.png
14KB, 522x85px
>>60834472
import java.io.IOException;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.util.Scanner;
import static java.util.stream.Collectors.toList;
import java.util.stream.Stream;
import java.util.List;
import java.util.ArrayList;

public class WordWrap {

public static void main(String[] args) {
if (args.length != 2) {
System.err.println("Invalid number of parameters.");
return;
}

String inFilename = args[0];
int width = Integer.parseInt(args[1]);

List<String> outLines = new ArrayList<>();
try {
outLines = Files.lines(Paths.get(inFilename))
.map((l) -> wordWrap(l, width))
.collect(toList());
} catch (IOException e) {
System.err.println("Cannot read input file.");
} catch (IllegalArgumentException e) {
System.err.println("Invalid input data: " + e.getMessage());
}

outLines.forEach(System.out::println);
}

private static String wordWrap(String s, int width) {
String[] words = s.split(" ");

StringBuilder out = new StringBuilder();
int charCount = 0;
boolean lineStart = true;

for (String word : words) {
if (word.length() > width) {
throw new IllegalArgumentException(String.format("Word '%s' longer than max width (%d).", word, width));
}

if (charCount + word.length() + 1 >= width) {
charCount = 0;
lineStart = true;
out.append('\n');
}

if (!lineStart) {
out.append(' ');
charCount++;
}
lineStart = false;
out.append(word);
charCount += word.length();
}

return out.toString();
}

}
>>
>>60834472
Too trivial to bother.
How is the single word>width case supposed to be handled though?
>>
>>60835053
>using java and not being pajeet
wtf
>>60835065
>trivial
read "I can't do it because I'm a brainlet."
>>
File: 1490896717840.png (114KB, 320x320px) Image search: [Google]
1490896717840.png
114KB, 320x320px
>>60835053
>>
>>60835053
;_;
beautiful.
>>
>>60835045
>more useful because it's not pure
ladies and gentlemen, an idiot
>>
>>60835106
>have a billion list element
>haskellfags have to use the entire list in their folds
lmao
>>
>>60835106
>>>/reddit/
>>
>>60835119
>Hasklets unironically have to implement their own slices
>>
>>60835092
It's literally just inserting a linebreak if you're standing on a whitespace character when the width is exceeded or tracing back to the previous whitespace character if you're not.
Except for >>60835065
Which is just figuring out the problem definition. Inserting '-\n' if the word covers the entire line or tracing back to see if you can isolate it on a line is my preference.

Trivial.
>>
>>60835119
https://wiki.haskell.org/Foldr_Foldl_Foldl%27

>>60835137
take + drop does this
>>
File: weird_goblin.png (35KB, 196x361px) Image search: [Google]
weird_goblin.png
35KB, 196x361px
>>60835053
>>
>>60835168
meanwhile in a good language.
immutable numarr = [1,2,3,4,5];
auto slice = numarr[0..2];
>>
File: fragzeichen2.png (194KB, 562x389px) Image search: [Google]
fragzeichen2.png
194KB, 562x389px
>>60832529
How are vectors represented as data in Scheme? I specifically want to know if it costs anything to run (vector-length) on them, or if it's accounted for internally, which I'm assuming it needs to be (as opposed to lists)
>>
>>60835166
Ok, negro, then have it such that you must return a list of strings, each being the corresponding lines in the would be ouput.
>>
>>60835191
c++?
>>
>>60835191
That's valid Haskell code, it just doesn't do what you think
>>
>>60835207
D
>>
>>60835193
I know in Common Lisp that if they have a fil pointer then its O(1).
Do Scheme arrays have an option to be adjustable or have a fill-pointer?
>>
>>60835207
The proper c++, yes.
>>60835208
then what does itdo?
>>
>>60835196
Doesn't cover the problematic case.
That does make it way easier to do in C though. It only makes it slightly harder in languages where the norm is to use excessive string concatenation.

Anon I don't see how this would ever be a particularly hard task unless we're supposed to do something like figure out the closest width that decreases the unclean line breaks by a percentage. Or best solution. That'd be non trivial. But I'm a bit lazy so I don't suggest that.
>>
>>60835222
defines a function "immutable" that ignores its parameter and returns [1..5]

defines a function "auto" that ignores its parameter and calls the function numarr with the list [0,1,2]


if you added the line
numarr = map (immutable () !!)

that would sort of do what you wanted (very inefficiently but flexibly)
>>
>>60835193
I dont know how if there is an object or anything that can be called in shceme (let alone a library or if shceme even is an object oriented programming language).
What i do know is that Vectors can be respresented as the sum of differing dimensional values.

A 2-D vector would be the trigonomentric product (or vecotr sum) of an x value and a y value. You can extend this logic to any number of dimensions.

If you mean drawing vecotrs like in Java 2-D then i have no fucking clue.
>>
>>60835234
>numarr = map (immutable () !!)
Haskell is pure tedium.
>>
>>60835236
Nigga, a vector as in a one-dimensional array.
>>
>>60835220
>bigO describing a practical component of a programming language
There's people that do this. I question how valid this approach is. Tons of inefficient stuff is O(1). Why you'd care about that over how man CPU instructions it costs you and how many cache lines you stomp all over is beyond me.
For general use of course. General use being less than about 100000 elements.
>>
>>60835211
>look up D programming language
>First thing i find is Google, the propogators of the jewish conspiracy to control the masses and stupify them.

What makes D any bettter than C, NewB, or A?
>>
>>60835268
D is not better than C, it's better than C++
>>
>>60835220
I don't think vectors are adjustable and this is the first I've ever heard of fill pointers. Resizing one means allocating an entirely new stretch of memory to the best of my knowledge.

But since they're not just naked arrays I'm guessing there has to be something keeping track of the length which means it can be referenced with zero cost. I just want to know the specifics.
>>
>>60835246
map (arr !!) [0..2]


is also a very inefficient slice of arr


1) they're lists
2) take and drop are already there
3) we don't want more fucking syntax
>>
>>60835268
>What makes D any bettter than C
no preprocceor.
modules
slices
UFCS
UDA
a proper c abi
etc
>>
>>60835274
but C++ is said to be better than C.
>>
>>60835261
I mean that is a constant one operation thing.
Like doing (1+ 1) in the REPL.
>>
>>60835281
"C++ is a better C" was supposed to be a joke.
>>
>>60835246
>>60835279
for splicing at least
you rarely even splice in Haskell, i can't remember having sliced anything more than 2 times in like 2 years of haskell
>>
>>60835268
FUCKING.MODULES
>>
>>60835279
>3) we don't want more fucking syntax
thats hard to believe given what it takes to do a simple thing like slicing a list
>>
>>60835278
This is why I'm considering switching to C.
In C, one knows exactly how things are.
>>
>>60835297
>a simple thing like slicing a list
1) you never fucking do it
2) it's fucking useless see 1)
3) you shouldn't slice a list anyway
4) Data.Vector has a slice function
slice i j arr
>>
Does anyone here work for a startup? If so, what is it like?
>>
new thread when?
>>
>>60835280
what are the U things.
>>
>>60835312
Over 100 posts.
But you're a bot I bet.
>>
>>60835303
>1) you never fucking do it
Because thats your rationale given the problems of doing it.
>3) you shouldn't slice a list anyway
Why?
Immutable slices are nice.

This is some weak DC.
>>
File: pointless operator.png (6KB, 421x111px) Image search: [Google]
pointless operator.png
6KB, 421x111px
>>60835297
>>60835324

wow this has improved haskell so much
amazing
the language is completely different now

>thats your rationale
what? you rarely ever slice a list in haskell, that's a fact
>why
because it's a list and not a vector or array
>>
>>60835320
Universal function calling system
User defined attributes
>>
>>60835301
Does one really "switch" to C from Lisp, or vice-versa? Like you're writing a project in Lisp and say "fuck it, I'm just gonna use C." They're kinda polar opposites that each have their own use cases.
>>
>>60835338
You're right, it's just that I don't want my shit to be too inefficient.
It bothers me that some things are O(6n) when they could be O(n)
>>
>>60835354
>>>>>>>>>>>>>>>>
>>
>>60835354
Scheme has FFIs that make it really elegant to write core operations in C and then Scheme on top of them.
>>
>>60835354
Just call out to Cee when you need to.
>>
Jesus christ I lack the patience of learning git
>>
File: ##squad.jpg (41KB, 599x548px) Image search: [Google]
##squad.jpg
41KB, 599x548px
someone explain this to me right now. I thought good languages only had one way to do something. why the FUCK? Are these all possible?
public static int sum(int[] array) {
int sum = 0;
for(int i=0;i<=array.length;i++)
sum+=i;
return sum;
}


public static int sum(int[] array) {
int sum = 0;
for(int number:array)
sum+=number;
return sum;
}


 public static int sum(int[] array) {
int sum = 0;
int i = array.length-1;
while(i>-1){
sum+=array[i];
i--;
}
return sum;
}


what the FUCK?
>>
>why are loops allowed to be flexible,ree
pajeet pls
>>
>didn't even give me a (You)
nice dubs tho, nerd
>>
>giving pajeets (You)s
absolutely not
>>
>didnt congratulate me on my dubs even though I complimented his
wow rude
>>
File: slices.png (9KB, 370x158px) Image search: [Google]
slices.png
9KB, 370x158px
wrote this for slice-anon

to   j = [ ..j]
from i = [i.. ]
i <> j = [i..j]

D (\l -> e)
-- slice dependent on length

M <list of slices>
-- gather multiple slices + concat
>>
>>60835376
>Java
>Good langauge
>>
>>60835477
nice double have a (You)
>>
File: 1481672953871.jpg (45KB, 312x395px) Image search: [Google]
1481672953871.jpg
45KB, 312x395px
>>60832529
How would you define the type of anime?
>>
>>60835556
gay
>>
>>60835556
With love, hugs, and semen
>>
>>60835556
anime :: Perfect
>>
>>60835469
fixed the i..j slice

turns out Data.Vector.slice takes an initial position and a length, not two positions
>>
>>60835376
return (nums).fold!((a, b) => a + b);
>>
>>60835688
>(a,b) => a + b
>not having operator sections
lmao @ ur life
>>
File: 1491005446148.png (276KB, 600x558px) Image search: [Google]
1491005446148.png
276KB, 600x558px
>>60835641
>::
>>
>>60834109
good 'ol C - it's too simple to be confusing
>>
>>60835798
C is better for simple-minded people.
>>
>>60835376
>good languages only [have] one way to do something
how could you possibly think that?

A good language would enable you to do something in any manner in which you could imagine it being done - the language should NEVER be a barrier limiting what you can do
>>
>>60835818
You've got that completely backwards.
Simple-minded people require their shitty languages to do everything for them, and hide all of the details.
>>
>>60835843
Indeed. And C is such a language.
>>
>>60832854
>>60833230
There are plenty of retards in that general.
>>
>>60832529
Are there any sentient beings in this thread?
>>
>>60835860
No.
>>
File: 1495786153676.jpg (52KB, 617x426px) Image search: [Google]
1495786153676.jpg
52KB, 617x426px
>>60835866
>>
>>60835788
having :: as cons is inconvenient desu
>>
how to make this less redundant?
public static void printRow(int number,int stop){
for(int i=1;i<=stop;i++)
System.out.printf("%4d",i*number);
System.out.println("");
}
public static void printTable(int number){
for(int i=1;i<=number;i++)
printRow(i,number);
}
}

please have mercy on my soul /dpt/, im a programming virgin
>>
>>60835934
oh and here's how it works.

input:printRow(12);

output:
1   2   3   4   5   6   7   8   9  10  11  12
2 4 6 8 10 12 14 16 18 20 22 24
3 6 9 12 15 18 21 24 27 30 33 36
4 8 12 16 20 24 28 32 36 40 44 48
5 10 15 20 25 30 35 40 45 50 55 60
6 12 18 24 30 36 42 48 54 60 66 72
7 14 21 28 35 42 49 56 63 70 77 84
8 16 24 32 40 48 56 64 72 80 88 96
9 18 27 36 45 54 63 72 81 90 99 108
10 20 30 40 50 60 70 80 90 100 110 120
11 22 33 44 55 66 77 88 99 110 121 132
12 24 36 48 60 72 84 96 108 120 132 144
>>
>>60835940
4chan fucked up the formatting a bit but you get the point
>>
>>60833770

1. map, collect
2. select
3. zip
4. reduce, inject
5. See 4.

>>60833942

What is the type of reduce? Because what you just gave for a type signature looks like the reduce method in Ruby...
>>
>>60836021
Rust?
>>
>>60836036
He's a Ruby shill, so ...
>>
>>60836036

Ruby. Rust called reduce fold and select filter. Rust also uses collect() to mean something completely different.
>>
>>60836036
Rust doesn't have reduce in the standard library, only fold. There's a foldl in the Itertools library, thoug: https://docs.rs/itertools/0.6.0/itertools/trait.Itertools.html#method.fold1
>>
>>60835942
Put the last for loop on top of the first one and get rid of the second procedure.
>>
https://haskell.godbolt.org/
>>
File: 1497077782859.png (79KB, 524x555px) Image search: [Google]
1497077782859.png
79KB, 524x555px
>>60836166
>>
>>60836193
dumb frogposter
>>
>>60836193
dumb frogposter
>>
File: zun (female).png (412KB, 850x638px) Image search: [Google]
zun (female).png
412KB, 850x638px
>>60836201
>>60836216
No anon. You are the frogposter now.
>>
>>60836230
dumb anime poster
>>
>>60836230
i haven't posted any frogs
>>
>>60836244
nice double, smart poster
>>
>>60832529
My god stackoverflow sucks. Fucking cunts sjw all over that place.
You question is this, you should have asked this, it should be like that. WTF................
Piece of shit site.
Deleting that cunt site's account.
>>
>>60836166
meanwhile
int testFunction(int* input, int length) {
int sum = 0;
for (int i = 0; i < length; ++i) {
sum += input[i];
}
return sum;
}



int example.testFunction(int*, int):
push rax
mov r9,rdi
mov r11,rsi
xor r8d,r8d
xor edx,edx
test r9d,r9d
jle 1f <int example.testFunction(int*, int)+0x1f>
movsxd rax,edx
add r8d,DWORD PTR [r11+rax*4]
inc edx
cmp edx,r9d
jl 11 <int example.testFunction(int*, int)+0x11>
mov eax,r8d
pop rcx
ret
>>
Is learning how to code worth the effort?

25, just got red pilled on linux(kali, tails, mint(testing). thinking javascript, c++, are the future. How did I do? Si or no.
>>
>>60835934
import std.stdio;

void main(string[] args)
{
import std.algorithm.iteration;
import std.algorithm.mutation;
import std.format, std.range;
each!writeln(iota(1,13)
.map!(i => iota(i,13*i, i))
.map!(j => format(" %s", j)));
}


$ rdmd main.d
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24]
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36]
[4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48]
[5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60]
[6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72]
[7, 14, 21, 28, 35, 42, 49, 56, 63, 70, 77, 84]
[8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 88, 96]
[9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99, 108]
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120]
[11, 22, 33, 44, 55, 66, 77, 88, 99, 110, 121, 132]
[12, 24, 36, 48, 60, 72, 84, 96, 108, 120, 132, 144]
>>
>>60836291
>kali, tails, mint(testing)
kek
>>
>>60836320
What's good then? Nothing that is free?
>>
>>60836339
Just get fedora and go to to this site
http://www.learncpp.com/

Or learn D instead if you don't want brain damage
>>
>>60836339
Debian
>>
>>60836306
why is the range function called "iota"
>>
>>60836365
"range" is a whole library
>>
>>60836365
because its part of the std.range module
>>
>>60836359
If she learns D first, she'll be too disgusted to start with sepples afterwards. D spoils the hell out of you.
>>
>>60836394
I know this fucking feels m8. I tried so hard to learn C++ but I feel so disgusted at header files
>>
>>60836365
because it's called that in C++
>>
File: chocolate-avocado-cake.jpg (39KB, 410x370px) Image search: [Google]
chocolate-avocado-cake.jpg
39KB, 410x370px
Anyone know where I can find all the interview cake problems and answers?
>>
File: 1477881300533.jpg (100KB, 392x409px) Image search: [Google]
1477881300533.jpg
100KB, 392x409px
What does zip do?
>>
>>60836437
Given n ranges, creates a range that successively returns a tuple of all the first elements, a tuple of all the second elements, etc.
>>
>>60836397
Don't worry, anon, it'll get modules soon™!
That aside, I can deal with C, but sepples makes me puke.
D a best!
>>
>>60836443
So if I pass [1,2,9] and "abc" will it return (1, a), (2, b), and (9,c)?
>>
>>60836454
yeah
  import std.range: zip;

int[] a = [ 1, 2, 3 ];
string[] b = [ "a", "c", "b" ];
zip(a, b);

writeln(zip(a, b));


[Tuple!(int, string)(1, "a"), Tuple!(int, string)(2, "c"), Tuple!(int, string)(3, "b")]
>>
>>60836483
oops, you dont need the redundant zip above wl
>>
File: 1477884178232.jpg (106KB, 363x435px) Image search: [Google]
1477884178232.jpg
106KB, 363x435px
>>60836437
>>
Kotlin makes my peepee hard
>>
my new reclusive weeb friend can manually create registry keys to make a standalone noinstall application associated with a filetype

what is his power level?
>>
>>60836825
>Winmemer
Very low.
>>
>>60836825
>registry keys
>wintoddler
Beginner
>>
>>60836833
>memer
>>>/v/
>>
>>60836384
>Range is a library
Oh wew
>>
>>60836833
>>60836865

he uses BDSM/loonix, he did that on my computer
>>
>>60832672
When you're this pathetic.
>>
Reason why Electron is a thing is because of the virtue of OSS
You hate electron right? Of course you do. It's just a web-browser rendering GUI as a desktop app.
While the idea of rendering UI with HTML+CSS(+JS) is a quite nice idea to create really complex UI designs very easily, having a web browser in the back-end really kills resources. But Electron is pretty fucking popular these days.

Enter Sciter (https://sciter.com/). It does not depend on electron to render UI. Looks like it's cross platform, embeddable, uses C API so can be used with any programming language. But how many of you people know about this?

Why did sciter fail to atom shell? I'll tell you why. The idiot that created sciter UI engine decided to close off the source and hijack the users for money.
Nobody cares about your fucking UI engine dude, people won't pay you money. The companies that use your UI engine is probably going to drop you soon as well.

Enjoy your project fading to obscurity once people does the same thing as you did, and then opening the fucking source. Consider your shitty UI engine *dead* then.

I don't understand what keeps these faggots from opening the source already. They know their fucking project is slowly dying and yet they won't release source.

Who the fuck pays sublime kek 60 bucks anyway? There are millions of people that don't pay jack shit. Faggots like you hold technological advancement back.

Thanks for reading my blog.
>>
>>60836889
Very high then
>>
>>60837038
>He is so pathetic he replies to this
>>
>>60837086
Just use VS Code, lad
>>
>>60837086
But sublime kek uses gtk?
>>
>>60837096
>When you got no comeback at all.
>>
>>60837099
Fuck you. I'd just use Co-edit. I use D almost exclusively. I'd rather not use macrowanker trash in my computer.

I am talking about UI renderers in general
>>
>>60837123
>I use D almost exclusively
AHAHAHAHAHAHHA.
Faggot.
>>
>>60837141
>>>/b/
>>
New thread:
>>60837216
>>60837216
>>60837216
>>
>>60837123
Co-edit is trash on windows, i use the runnable modules, strictly for quick dpt-projects. Its projects shit is trash.
And VS Code is FOSS though.
Thread posts: 314
Thread images: 38


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