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

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

Thread replies: 255
Thread images: 29
File: smelly neet pussy.png (366 KB, 761x678) Image search: [Google]
smelly neet pussy.png
366 KB, 761x678
What are you working on senpai?

Old thread: >>52158558
>>
first for haskell
>>
YEAR OF THE LISP
YEAR OF THE LISP
YEAR OF THE LISP
>>
File: solution.png (14 KB, 851x330) Image search: [Google]
solution.png
14 KB, 851x330
How do I find the min and max of ten numbers?
>>
second for ocaml
>>
OCAML BEST LANGUAGE
>>
>>52161828
LOOPS MOTHERFUCKER

HAVE YOU HEARD OF THEM?
>>
>>52161828
sort
first element is min, last is max
>>
Why aren't functional languages faster than C? Surely someone should be able to write a compiled functional language that leverages the vasty more explicit code to optimize better?
>>
>>52161857
Go ahead.
>>
>>52161857
they are faster
>>
 happy new year's people. 
>>
>>52161828
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for(int i : numbers) {
if(i < min) {
min = i;
}

if(i > max) {
max = i;
}
}
>>
>>52161872
Don't meme me. Every benchmark shows C/C++ leading the pack. Always.
>>
>>52161872
no they aren't you delusional mutilated fucktard faggot
>>
>>52161884
>>52161892
show proof
>>
Threadly reminder that switches and if statements are deprecated
>>
File: 1359152352586s.jpg (7 KB, 249x218) Image search: [Google]
1359152352586s.jpg
7 KB, 249x218
>>52161828
Use sleepsort(). The value that is returned first is the minimum, and the value that is returned last (you have to count the number of times the variable was altered using semaphores) is the greatest.
>>
>>52161901
http://benchmarksgame.alioth.debian.org/u64q/which-programs-are-fastest.html
>>
>>52161846
That's gotta be just to troll people. Or maybe a gag-question on a quiz.

No one is that stupid. I'm telling myself this. I want to believe. I want to believe.
>>
>>52161771

/d[pc]t/ looks better senpai.

Daily Programing/Coding Thread.

We can even take it further:

/d[dcsa]t/

Daily Programming/Coding/Scripting/Anime Thread.
>>
Whats the point of loops when tail recursion exists?
>>
>>52161946
loops are faster and more readable in 99% of use cases
>>
>>52161946
kill yourself retard
>>
>>52161946
What's the point of tail recursion when you can just foldr?
>>
>>52161946
not all languages have tail call optimization
>>
>>52161946
Tail recursion compiles to loops
>>
>>52161924
NO
if you go there there next year it will be
daily Programming/Coding/Scripting/anime-deleted/FULL_ON_GAY/TRAPS/SJW/JEWS
>>
>>52161906
I love sleep sort
>>
>>52161874

It's only 5:22PM in the earliest timezone of the United States (the only country that matters). It is not yet the new year.
>>
>>52161901
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=ocaml&lang2=gcc
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=ghc&lang2=gcc
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=fsharp&lang2=gcc
>>
>>52161946
What's the point of loops when you can just copy past your code that is way more efficient than loops?
>>
>>52161971

Or latest, rather, because I'm a maroon.
>>
>>52161972
>>52161913
wow
>>
>>52161981
>fucking up your instruction cache
>>
File: wq.jpg (479 KB, 1280x720) Image search: [Google]
wq.jpg
479 KB, 1280x720
>>52161966
New drama for the new year.
>>
>>52161965
Do you mean language standard may not require the implementation to have tco or that some languages have no implementation that provides tco?

It's not current-year < 1980 anymore and if your compiler does not support tco you should not be using it.
>>
>>52161981
>What's the point of loops when you can just copy past your code that is way more efficient than loops?
Obviously trolling, but you do know that's literally what optimizing compilers do sometimes? It looks at the situation, and if appropriate, unrolls the loop. You leave those decisions up to the compiler, and your life is good.
>>
>>52162008
tco means compiling to loops

as in the compiler has to clean up your retarded shit
>>
How are match expressions so fucking based?
Why doesn't C++14 have them? What the fuck Bjarne?
>>
>>52162021
>as in the compiler has to clean up your retarded shit
It already does it on so many places so saying support for tco is not needed is retarded.
>>
>>52162036
You're on the wrong board buddy boy
>>
>>52162049

You're right, I am. I've also been drinking today. In fact, I started drinking last night and didn't stop.
>>
>>52162047
anon isn't saying tco isn't needed

>Tail recursion compiles to loops

it literally compiles to loops. recursive functions are fucking dumb as shit. you gain nothing except if you're a hipster reddit fag then it makes you feel smart because you're too retarded to realize how pointless recursive function calls are.
>>
>>52161924
/d[dcsa]t/ - ((Programm|Cod|Script)ing|Anime) Thread

Edit: There's probably a better way to do this.
>>
File: wheeeeee.gif (499 KB, 300x250) Image search: [Google]
wheeeeee.gif
499 KB, 300x250
How do I write C in the most autistic way possible?
I already cast the return value of malloc and cast pointers before freeing them.
I also use register and inline unironically.
>>
>>52162077
/dp+scat/
daily programming plus scripting, coding, and anime thread
>>
>>52162074
tail calls simplify code and make it neater
>>
File: 4459353701_826a3c120d.jpg (126 KB, 489x400) Image search: [Google]
4459353701_826a3c120d.jpg
126 KB, 489x400
>>52162084
sorry to break it to you but that's just straight up assburger
>>
IGNORE TRANNY THREADS

REPORT TRANNY POSTERS
>>
>>52162084
malloc error handling
>>
QUICK, POST HOW TO FIND THE MIN AND MAX NUMBERS OF AN ARBITRARY INPUT, IN YOUR LANGUAGE OF CHOICE
>>
>>52162114
no it doesn't.
>>
>>52162123
She's not a tranny.

Shame on you, anon.

Don't equate me to that tranny poster.
>>
>>52161828

Real or not that code gave me autism.
>>
Andrei Alexandrescu Three Cool Things about D
https://www.youtube.com/watch?v=FdpaBHyQNco
>>
>>52162148
i resent being called that, I only post hime from himegoto
>>
>>52162134
from stdin?
>>
>>52162084
>C89 only
>Check errno wherever possible
>-pedantic-errors
>Vim
>Use for every project and no exceptions
>Any libraries you use you must compile
>>
>>52162152
I really like Andrei, he's a good speaker.
Walter Bright on the other hand...
>>
File: Gatchaman Crowds.jpg (150 KB, 1920x1080) Image search: [Google]
Gatchaman Crowds.jpg
150 KB, 1920x1080
>>52162148
what a poorly draw anime then

and the character looks kinda like this guy
>>
>>52162084
>I already cast the return value of malloc and cast pointers before freeing them.
Wait, this isn't normal?
Holy shit what the fuck has Rob Pike been teaching me?
>>
>>52162084
Handle literally every possible error (even fclose), with errno switches and everything.
>>
>>52162166
kill yourself fag
>>
>>52162212
Don't be rude, anon.

He might have shit taste, but there's no need for this.
>>
File: Dlicious.jpg (840 KB, 1580x3422) Image search: [Google]
Dlicious.jpg
840 KB, 1580x3422
Daily reminder
>>
>>52162221
posting threads before the bump limit like he does is entirely unacceptable and has stirred up a lot of shitposting and image/thread wars

kill yourself
>>
>>52161852
> sort
Um, no. I mean, that will work, but it's completely unnecessary.

int result = userInput[0];
for (int i = 1; i < num_inputs; i++)
if (result < userInput[i])
result = userInput[i];
>>
>>52161852
>>52162259

>implying he wrote that in C++
obviously it's optimised C
>>
File: ooi.png (1 MB, 1920x1080) Image search: [Google]
ooi.png
1 MB, 1920x1080
>>52162247
Absolutely uncalled for, we're all white here. We can have a civil discussion without insults.
>>
>>52162195
>draw a girl
>call it a boy
people will defend this
>>
>>52161857
They are. See OCaml and ATS.
>>
>>52162197
casting return value of malloc is required if you want to maintain compatibility with c++
casting pointers before freeing is required if you're freeing const pointers.
>>
>>52162303

It is literally a cross dresser.
>>
I want to declare a character array and use a integer variable in it's name. So for instance [/code]char nameX [10][/code] where X is a variable i get from another part in the program, how would i do this ?

Language is C++.
>>
>>52162331
Type the same name, do not attempt to use the same name, or bring out the macro glue.
>>
>>52162331
Anon, what you've just said is one of the most insanely idiotic things I have ever heard. At no point in your rambling, incoherent response were you even close to anything that could be considered a rational thought. Everyone in this room is now dumber for having listened to it. I award you no points, and may God have mercy on your soul.
>>
>>52162331
Write a precompiler in python to compile your almost C++ code to actual C++ code.
>>
>>52162330
yeah sure, that's an easy excuse when all anime guys look like anime girls but taller and with shorter hair

is there even any reason for his character to be male, or was that thrown in as otaku fanservice?

>>52162356
>redditors still find this funny in 2016
holy shit
>>
>>52162300
>we're all white here
Uhm, I'm Indian.
>>
>>52162331
what the fuck
>>
>>52162366
Atomize yourself, currynigger!
>>
>>52162377
That makes a change, I thought someone would say "POO IN LOO".
>>
>>52162409
DEDICATED
>>
>>52162360
No, but Japanese men can be quite effeminate. In the actual show you clearly see that he's crossdressing.
>>
>>52162331
Fun fact: the compiler gets rid of your precious variable names.
>>
function countWords(str) {
return str.split(/\s{1,}./).length;
}


Find a flaw.
>>
>>52162461
hundreds of times slower and memory hungry than C because it's running in your comfy padded javascript interpreter
>>
>>52162456
And redundant whitespace and formatting, which is why you should do this >>52159457
>>
>>52162474
Just imagine it was psuedocode.

Find a flaw.
>>
>>52161857
Functional code _usually_ depends on a garbage collector. For instance, it's hard to statically reason about exactly which variables a referenced by a closure, and doing so often requires garbage collection to hold onto the references.
A solution could be to make everything immutable so that closures can just copy values instead of references, but then you get a performance hit due to no immutable state in other parts of the program.

Sure, some functional languages (Haskell, OCaml I think) will let you write very fast functions that just operate on integers (and you could write the same procedure trivially in C), but taking advantage of real functional features (lambdas, linked lists) often ends up slower than their less elegant imperative alternatives.
>>
>>52162495
if we're doing psuedocode then
word_count(str)

find a flaw
>>
>>52162197
Casting return values isn't autistic at all, it's good coding practice.
>>
>>52162509
why?
>>
>>52162506
your pseudo language is shit
>>
>>52159457
10/10 bait

>>52162084
Isn't register deprecated and completely ignored?
>>
>>52162519
str.count.words()

:^)
>>
>>52162506
>Completely missing the point of psuedocode
That doesn't explain the algorithm.
>>
>>52162533
ew
>>
>>52162535
your psuedocode doesn't explain what split does
>>
newfag here, simply trying to get the last 3 characters printed in upper case also how do you post code not like this shit

char x[] = "abcabc";
int i = 3;
while (x[i] != 0)
{
toupper(x[i]);
i++;
cout << x[i];
}
>>
>>52162543
It splits it into an array, obviously.
>>
>>52162437
but why does he wear the dress?
>>
>>52162528
yes, register is ignored completely by newer versions of GCC
>>
>>52162543
>>52162562
I don't think regex psuedocode is very reasonable
>>
>>52162562
that's so dumb
int count_wrds(char *str)
{
return do_thing(str);
}
>>
>>52162565
Nobody cares who he is until he becomes her
>>
>>52162579
The whole point of psuedocode not being a real language is that it leaves out unimportant implementation details in favor of details to clearly explain an algorithm so that you can implement it in your language of choice.

>>52162579
>>52162533
>>52162506
>>52162461
None of these are sensible "psuedocode"
>>
>>52162562
rate my pseudocode guys
writeKernel;

Linus can step aside, the real programmer has arrived.
>>
>>52162552
function meme(str) {
return str.substr(str.length - 3, str.length).toUpperCase()
}


Stop being a hipster and learn JavaScript and you use
 tags.
>>
>>52162605
> ;
it's shit
>>
>>52162598
rate my sudoku
>>
>>52162574
>he doesnt know regex
>>
File: 1451001555606.png (272 KB, 470x624) Image search: [Google]
1451001555606.png
272 KB, 470x624
How do I learn javascript, guys?
>>
>>52162616
[CODE] tags (lowercase)
>>
>>52162084
I feel like casting your malloc's to use a reference when debugging segfaults is less autistic than keeping track in your head
>>
>>52162618
python user please stop being harmful
>>
>>52162645
First you buy a black dildo.
>>
>>52162645
Let Brendan Eich fuck you in the ass.
>>
>>52162662
are you insinuating that all javascript developers are homosexual?
>>
File: Girls.png (490 KB, 449x401) Image search: [Google]
Girls.png
490 KB, 449x401
>>52162644
>he doesn't just google the regex he needs
>>
>>52162679
It's actually pretty easy senpai.

You shouldn't need to google the regex you need.
>>
char x[] = "abcabc";
int i = 3;
while (x[i] != 0)
{
toupper(x[i]);
i++;
cout << x[i];
}


thanks man, not being a hipster just an idiot
>>
>>52162658
ML
>>
>>52162461
>countWords("            ")
>2
>countWords("")
>1

smdh
>>
/sci/entist and Python pleb here.

I was wondering if anyone knew the most efficient way to do this.

Suppose I have an array (using numpy.array at the moment) of numbers like:

array([[ 0.        ,  0.        ],
[ 0.5 , 0.5 ],
[ 0.75 , 0.25 ],
...,
[ 0.90722656, 0.65917969],
[ 0.65722656, 0.40917969],
[ 0.15722656, 0.90917969]])


Each row corresponds to a coordinate/vector of arbitrarily large dimensions (n=2 in the example obviously).

I need to:
A) Find find the dot product (or the inner product/euclidean "distance") between each point), then
B) Rearrange new lists with the first entry being the coordinate in the original list and subsequent entries arranged from the "closest" to the "furthest" coordinate of all other rows in the original array.

I know for A) I can use numpy.inner to find the, but I don't know how to do this in an efficient array processing manner for all points.

Also there must be some bubble algorithm for B), but how do I keep track of the coordinate entry number in the original array (I need the original coordinates after the new lists have been sorted).

Would appreciate if someone could point me in the right direction. It needs to be as efficient as possible, we're talking about a lot of points here.
>>
File: Screenshot (13).png (134 KB, 1920x1080) Image search: [Google]
Screenshot (13).png
134 KB, 1920x1080
>>52162134
OK.
C++ WITH THREADING
#include <atomic>
#include <sstream>
#include <string>
#include <vector>
#include <thread>

#define ms std::chrono::milliseconds

int main(void) {
std::vector<int> numbers{ 5, 7, 8, 9, 1, 4, 2, 3, 6, 10, 15 };
std::vector<std::thread> threads;
std::atomic<int> max, min;
std::atomic<bool> first = { false };

//modified sleepsort()
auto func = [&](int time) {
std::this_thread::sleep_for(ms(time));
if (!first.exchange(true)) {
min.store(time);
}
max.store(time);
};

//meaty part
for (auto i : numbers) {
threads.emplace_back(func, i);
}
for (auto& t : threads) {
t.join();
}
printf("Min: %d, Max %d", min.load(),max.load());
}
>>
File: 1396508799625.jpg (50 KB, 500x211) Image search: [Google]
1396508799625.jpg
50 KB, 500x211
>>52162792
What's your favourite anime, anon?
>>
not gonna lie lads, python is pretty tight, tighter than my cousin's vag
>>
>>52162792
/dpt/ is not really the place to go asking how to use numpy. This thread is about general programming shit. Time to learn to use IRC.
>>
/cuck(old)?/ig

Gotta admit, regex is pretty fun ngl.
>>
>>52162823
I haven't watched anime in ages, don't have facourits and don't watch a lot to begin with, last one I was able to actually finish was NGE. Cowboy Bepop was the last one I watched, but it got too boring after the weird people joined the crew.
>>
>>52162938
I use IRC, which channel do you recommend? One of Rizon's?

I'd use stackexchange, but my adviser wouldn't like seeing elements of my project on the indexed web.
>>
>>52163003
try freenode, #python maybe
>>
>>52162792
> A) Find find the dot product (or the inner product/euclidean "distance") between each point),
d = np.tensordot(x,x,axes=(-1,-1))

If x is MxN, d will be an MxM array of dot products where d[i,j] = dot(x[i], x[j]).

> B) Rearrange new lists with the first entry being the coordinate in the original list and subsequent entries arranged from the "closest" to the "furthest" coordinate of all other rows in the original array.
Uh, what?
>>
>>52162819
>unironically using Edge
10/10
>>
>>52163030
Alright giving it a shot
>tfw all 3 my usernames is taken on FreeNode

w-what...people on IRC scare me...
>>
>>52162938
> /dpt/ is not really the place to go asking about programming
FTFY.
>>
>>52163077
fucking assblasted C-ucks and FP faggots think their retarded shitty meme languages are actually useful and not just a piece of shit to be wiped from some indian code monkeys ass that no one uses ina real business environment
>>
>>52163053
> B)
> Uh, what?
Yeah: uh, what?

But it probably involves np.argsort().
>>
>>52162823
Obviously the saviour of anime, OPM
>>
https://github.com/jonathanslenders/pyvim/blob/master/README.rst
>>
>>52163053
>d = np.tensordot(x,x,axes=(-1,-1))
NICE, exactly what I was looking for, thank you so much.

>Uh, what?
So for example now I have say d[1,:] which is 1xM vector of the dot products.

I want to sort this vector from smallest to the largest value. But after it's sorted I want to know it's index in the original d[1,:] vector, that information can be used to find the row entry in the original "x" array I think (I need it to feed to another function).
>>
>>52161828
That is not a solution it is a problem.
>>
>>52163164
map it to a tuple of its value and index (via mapi)
sort it by its value
>>
>* Now talking on #python-unregistered
>* Topic for #python-unregistered is: Welcome to #python-unregistered! You've been put here because #python requires you to register your nickname with Freenode. For more information about registering on Freenode, ask #freenode. For more information about #python,#python-* moderation, #python-ops.

The fuck is this? Are you telling me I can't spam nigger in the chat windows?
>>
>>52163167
If it 's simple and it works...
>>
>>52163092
>tfw you realize the average /dpt/ poster is this autistic

Explains a lot really.
>>
Any visual studio experts here? I'm writing a winforms project on the side for my office, but this is the first time I've used C# and visual studio, so I have no idea what the fuck I'm doing and I need some design advice.

Right now, all it does is generate documentation from a bunch of pdf and word templates, but I ultimately want to extend it to include database functionally to display different kinds of records we currently keep in a shittier format, and to generate e-mails, excel spreadsheets, etc. The problem I'm running into is that I want the program to run persistently with a low memory footprint, and whenever a new assembly is loaded, an assload of static variables are added to the stack.

It seems like my options are either to have the program dynamically load assemblies within separate appdomains so they can be unloaded without closing the program, or to have the program make system calls to execute separate command line programs externally. I feel like the second option would be less expensive and complicated, but I have no idea what the fuck I'm doing.
>>
>>52163092
Languages literally need to take lessons from C and FP

C:
Pointers, easy manual memory allocation, low level functionality & performance, function polymorphism, syntactic macros

FP:
Match expressions, algebraic type syntax, TCO, function composition syntax (inc. currying), type inference, a unit type, generics
>>
File: page1memoryBasic.png (65 KB, 640x640) Image search: [Google]
page1memoryBasic.png
65 KB, 640x640
Anyone want to give me feedback on the first page of my C tutorial/cheat sheet
>>
>>52163197
believe it or not, most people don't like you to act needlessly childish
>>
File: 1428353052866.jpg (282 KB, 1000x1000) Image search: [Google]
1428353052866.jpg
282 KB, 1000x1000
>>52163226
>Right now, all it does is generate documentation from a bunch of pdf and word templates

Please stop relying on shitty tools.
>>
>>52163181
Ok, thank you so much Anon. If was a girl I would kiss you on NYE and then some.
>>
/</?(.{0,})>/ig


It's alright to use regex to strip HTML, right senpai?

I only ask because whenever something feels good someone always jumps in and tells me I shouldn't do it.
>>
>>52163226
>visual studio
Off yourself
>>
>>52163233
*macros
(though syntactic macros would be appreciated)
>>
File: lel.png (59 KB, 662x395) Image search: [Google]
lel.png
59 KB, 662x395
>>52162792
>It needs to be as efficient as possible
>Python
>>
>>52163260
>{0,}
I seriously fucking hope
>>
>>52162792
I'm no data scientist, but here's how I'm interpreting what you want:
For each row in the original array, you want a list containing the dot product of the current row and another row.
This list is supposed to be ordered from least to greatest, with the initial row at the front.

Performing the dot product is an Omega(n^n) operation if done poorly. There's not really any getting around that, unless you perform caching, which should bring it down to O(n(n-1)/2)

If you use binary trees for each row, the sorting operation will take O(log(n)). Of course, you will have to write a comparison operation for the binary tree that finds the dot product of the two rows, with caching.

Does that sound good?
>>
>>52163250
It's not like I have a choice, or I wouldn't be doing this for windows in the first place
>>
>>52163235
something so basic is not what you should need on a cheat sheet
>>
>>52163260
You can't parse HTML with regex

But you can parse regex with HTML
>>
>>52163233
Pointers are absolute cancer and belong in the trash. FP in general gets fantastic performance when that is the goal of the language; the right language can be faster than C in real-world, non-toy tasks in many instances.
>>
>>52163282
I meant like array processing/optimized compiled functions instead of using for loops.

"As efficient as possible with minimum effort is how it's done in my field". I'm not a CS major.
>>
>>52163287
Rather, the total operation should be something like O(n(n-1)/2 + n*log(n)).
>>
>>52163164
ix = np.argsort(d,axis=-1)

will return an array of integers with the same shape as d such that
d[i,ix[i,0]], d[i,ix[i,1]], d[i,ix[i,2]], ...
are in ascending order.

I.e. it contains the column indices which would sort each row.
>>
>>52163235
Not only is it retarded to put this crap on a cheatsheet but it's also fucking wrong. Kill yourself.
>>
>>52163302
> pointers are absolute cancer

Hello, is this Haskell I'm speaking to?
>>
>>52163301
HTML >>>>>>> regex confirmed :^)
>>
>>52163282
>only Python 3
>no Python 2
Seriously fucking hope you don't think 3 is the face of Python
>>
>>52163287
>Omega(n^n)
I basically don't understand anything you said written after this. I will do some reading and get back to you. Thanks for the reply anyway.
>>
>>52163328
Hello, is this 99.9% of the world's most destructive bugs I'm speaking to?
>>
>>52163302
> faster than C in real-world, non-toy tasks in many instances.

Examples? Well-optimized C code that makes use of AVX/SSE is going to outperform functional code every time.
>>
>>52163324
what is wrong about it
>>
>>52163261
What other alternatives are there? I'm not writing C# without an IDE, that's for sure
>>
>>52162792
Not an answer but I just realized these are piss easy to do in APL
A ← ∘.(+.×)⍨∘⊂[2]
B ← ⍋
>>
>>52163320
Ah, nice nice, this is prefect thank you.
>>
>>52163282
>he thinks numpy is python
it's fortran and c with a python front-end, retard
>>
>>52163357
>>>/tumblr/
>>
>>52163375
If I learn APL will I become a wizard?
>>
VOTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

http://strawpoll.me/6415189
>>
File: 1409937369650.jpg (52 KB, 421x834) Image search: [Google]
1409937369650.jpg
52 KB, 421x834
>>52163383
>someone suggests making full use of the hardware
>you send them to... tumblr
>>
>>52162134
nums = input(">>> ").split(" ") # 1 10 100 4
ints = []
for item in nums:
ints.append(int(item)) # Convert to int
ints.sort()

if len(ints) > 0:
print("Lowest:",ints[0])
print("Highest:",ints[-1])
>>
>>52163384
It actually is "useful" as in it influences your mindset
>>
>>52163375
I have to say this is pretty interesting, I've never heard of APL before.
>>
>>52163355
No, I'm performance. Who's this "Haskell" guy?
>>
>>52163282
For this, Python shouldn't be significantly slower than C, as you're performing a small number of operations, each processing a large amount of data.

It may even be faster: if you have a finite amount of time to spend on the problem, faster turnaround means that you can spend more time on algorithmic optimisations.
>>
>>52163411
>Having single character names for SIMD vector functions is one way that APL enables compact formulation of algorithms for data transformation such as computing Conway's Game of Life in one line of code.[52] In nearly all versions of APL, it is theoretically possible to express any computable function in one expression, that is, in one line of code.

Is APL the Ur-language? It sounds like possibly the most /dpt/ language I've ever seen.
>>
>>52163349
Omega(n^n) means, at worst, you are performing n^n operations. That basically means you're brute forcing every dot product.
This is because you're performing the dot product of each element with every other element. Therefore, n^n.

O(n(n-1)/2) is with caching involved.
If you use a Map to pair two elements with a dot product, then you have cached the calculation.
When you require the dot product again, you will receive the cached data instead of calculating it again. It's not "free", but it is immensely faster.

A binary tree is an elementary data structure where each node can point to at most two other elements. These two elements refer to a comparatively smaller and a comparatively larger element.
Inserting into this tree requires you to traverse these elements, which is an O(log(n)) operation. If you insert every element into this tree, it becomes an O(n*log(n)) operation.
This is faster than sorting a list after it's already been made, which is never smaller than O(n^2).
>>
File: dpt in a nutshell.jpg (236 KB, 1624x626) Image search: [Google]
dpt in a nutshell.jpg
236 KB, 1624x626
>>52163441
absolutely
>>
>>52163382
I've also read this and Python(x,y) distro I'm using comes with an interpreter that is written with Cython wizardry so all my functions are compiled in C anyway.

I'm not sure how much slower it is than real C, but I'm just a ChemE as long as my optimizations aren't taking weeks per run I'm happy writing quick high level scripts, I'll leave the hardcore stuff to you CS studs.
>>
>>52163441
The Ur language is the Ur-language.
>>
>>52163382
> He thinks the language used to implement a library matters.
You use it by writing Python code, not by writing C or Fortran code.
>>
>>52163445
Ah, cool, thanks for explaining that.
>>
>>52163463
That's nearly FL level of maintainability.
>>
File: >mfw.jpg (119 KB, 695x642) Image search: [Google]
>mfw.jpg
119 KB, 695x642
>working on p2p browser application
>have to use node.js because I need to use webtorrent
>npm's fucking atrocious build ecosystem keeps breaking on this one dependency that I absolutely need to install
>I've spent all day trying to get it to build
>nothing works
>none of the suggested solutions on the internet work
>>
How do I start contributing to big projects? All I do is kiddie script shit, I want to do something bigger than 300 lines
>>
>>52163393
>/pol/ is winning
I'm so proud of my home board.
>>
>>52163564
>write a python web scraper that searches github projects with a certain number of downloads for common english typos
>fix typos, submit pull requests
>within a week, have hundreds of accepted contributions to the biggest open-source projects
>>
>>52163384
> If I learn APL will I become a wizard?
You may as well learn NumPy, which is basically just APL in the form of a Python library.

Easier to get, easier to find documentation, more heavily used (thus more libraries, more people who can give advice), better tools (e.g. IPython integration via pylab).

The only real "advantage" of APL is the geeky syntax (i.e. it uses mathematical symbols rather than ascii function names).

The fundamental idea behind both is that arrays are first-class values; you write code by operating on entire arrays rather than explicitly iterating over their elements. It can take some effort to get your head around, but once you get used to it you can be very productive.
>>
>>52163484
and? the heavy lifting is done in those languages. i guess gnuradio, theano, tensorflow, and qt are all inconsolably inefficient because they have python front-ends?
>>
>>52163398
Worst code I've written all year. Should have replaced
ints = []
for item in nums:
ints.append(int(item)) # Convert to int

with
ints = [int(item) for item in nums]
>>
>>52163636
since you're clueless, shut up.
>>
Happy new year autists.

I'm making a media player in C# - my current method for my "Library" window essentially generates a static data object for each music file uses a 3rd party lib to grab useful information out of it adds the whole thing to an ObservableCollection, then serialises the whole lot to a file in appdata.

Obviously this takes a long ass time to do for people with larger music collections, and is completely and utterly static - detecting additions to the selected root folder is nigh on impossible without generating another Library from scratch, which is just dumb. (detecting file removals is alright though, it just checks the path stored in the object to see if the file still exists).

Is there a better solution to this? Is there a way to bind a WPF form directly to that kind of thing, or am I stuck with iteration and all the shit that comes with it.
>>
>>52163649
Theano outputs C and cuda code on-the-fly and compiles it. It doesn't use code written in C as part of its own operations and doesn't implement operations as an overlay over C code.
>>
>>52163393
WHERE THE FUCK IS /PO/ YOU CUNTING BASTARD
>>
>>52161828
>>> import random
>>> l = [random.randint(1, 100) for x in range(10)]
>>> l
[2, 73, 89, 7, 59, 79, 10, 42, 77, 92]
>>> len(l)
10
>>> max(l)
92
>>> min(l)
2
>>>
>>
>>52161828
Bubble sort, it's an easy algorithm to implement and it's one of the most efficient sorting methods out there.

Look it up senpai.
>>
>>52163677
good to know but what is the point of this pedantry? it does not affect my statement.
>>
>>52163753
>bubble sort
get out
>>
>>52163657
poll the file modification dates, if the date is newer than the one you have cached then regen the metadata
if windows has something like inotify you can use that to avoid the constant stat calls
>>
>>52163393
>no /trash/
>>>/trash/
>>
>>52163806
Seems like a reasonable idea for my reading changes thing.

Still have a problem with the sheer amount of time it takes to generate a library, yeah I could make my code robust enough so it only ever has to do it once (or however many different sources a user sets).

There must be a better way to do it, that doesn't take so much time.
>>
File: neither squirrel nor beaver.jpg (50 KB, 460x349) Image search: [Google]
neither squirrel nor beaver.jpg
50 KB, 460x349
What language should I write a text editor in?
I sort of want to write it in python so I can learn python because it seems like it might be useful to know but I don't know if there's any point doing it and not just writing
import texteditor


Should I do it with haskell or is that just a meme language?
>>
>>52163806
>noatime
>>
>>52163865
Haskell is a meme language, but it might be fun to write a text editor in it.

If you want function, do c++ or C#. If you want to have fun, Haskell, F#, or Lua are your best bets.
>>
>>52163846
>/trash/ gets added
>one day and it's nothing but pony porn
I hate this place
>>
>>52163865
Mutability is a necessary part of editing so you literally can't write a text editor in haskell
>>
>>52163865
Both Python and Haskell are meme languages.

The none meme languages are as follows:
- C
- C++
- Java
- JavaScript
- PHP
>>
>>52161874
thank
>>
>>52163890
>>52163885
I have no idea what haskell is or does by the way, I've just heard it mentioned here
>>
>>52163910
It's essentially like programming in mathematical expressions instead of computational instructions.

You can make GUIs with it using gtk2hs.
>>
File: 1417912850240.png (2 MB, 1920x1080) Image search: [Google]
1417912850240.png
2 MB, 1920x1080
Happy new CLISP year!
>>
>>52163903
>java
>no C#
either both or none, they're the same language famalam
>>
>>52163302

>Pointers are absolute cancer and belong in the trash.

Irony -- every program contains at least two pointers: the stack pointer and the instruction pointer. Inevitably, some programmer has to deal with these because no program is purely abstracted from there machine it is running on. For example, if I write a ruby program, that ruby program has to run inside of another program which uses pointers. C at least does a better job of making pointers eat to work with than pure assembly.

What you hate is not the existence of pointers, only the idea that you might have to work in a language that deals with them. All I see from your complaint is a big fat "look at me world, I cannot do native programming!"
>>
>>52163890
Sure you can!
Just have the text in the text window be a 1:1 'graph' of the text that the user types in. Have the typed-in text be saved in an abstract buffer which then pipes 1:1 to the text window.
Boom.
>>
>>52161946
What's the point of tail recursion when loops exist?
>>
>>52163928
Thanks, anon.

I don't blame you for what the sneaky Jew elites do, the average Jew is alright.

I hope you fix your Palestine problem.
>>
I want to make a foobar component. I have a lot of beginner programming experience from doing electives in uni. Basically first year stuff and a good idea on how to use std libraries.
How difficult is it to make something like this? First time doing something like this.
>>
>>52163865
Whatever you want farn
I did one in python and it works fine
>>
>>52163235
>1 byte is 8 bits
WRONG

>in C an address is a hex number
hex, oct and dec are simply representations

>a 4 byte int in C
Just note that int in C *may* be 4 bytes, but it is not necessary true.

>byte adrs 0x0*
I don't get this
adrs? address? nobody calls address as "adrs".
>>
>>52163865

Text editors should ideally be lightweight. If you want to use a meme language, use Rust. Otherwise, just use C or C++.
>>
>>52163960
It gets optimised to a loop, it can loop a lot cleaner and be more obvious.
>>
>>52162193
Walter Bright is a self-confessed autist
>>
File: tips fascism.jpg (59 KB, 500x435) Image search: [Google]
tips fascism.jpg
59 KB, 500x435
>>52164004
>>1 byte is 8 bits
>WRONG
Oh my god FUCK OFF
>>
>>52164022
look a lot cleaner*

also fuck this minute interval, literally communism
should be 30 seconds max
>>
>>52164009
>Rust
>not Go
>>
>>52163865
I heard JS is an excellent language for editors.

>le 2 MB faic
>>
>>52163065
:^)
>>
>>52163065
There Is Literally Nothing Wrong With Edge.

Happy new year, faggots.
>>
File: 1424939568543.png (280 KB, 659x720) Image search: [Google]
1424939568543.png
280 KB, 659x720
>>52164036
I am sorry for your ignorance, but no knowledgeable person claims such an inaccuracy,
>>
>>52164004
>1 byte is 8 bits
>WRONG

assuming we are using a desktop computer from the year 2000 or older

>in C an address is a hex number
>hex, oct and dec are simply representations

okay i will change it to simply "number"

>a 4 byte int in C
>Just note that int in C *may* be 4 bytes, but it is not necessary true.

yes that is why i said a 4 byte int

>byte adrs 0x0*
>I don't get this
>adrs? address? nobody calls address as "adrs".

that was done due to space issues
>>
https://codeshare.io/uZRQj

Let's make something great, /dpt/!
>>
>>52164096
You have been visited by
The Knowledgeable C Autist

100% compatibility will come to you, but only if you post "NOT PORTABLE" in this thread
>>
More of an IT question:

How would you deploy and monitor an application to a large number of servers? Servers may be removed or added at any time.

Adding a new server should take no more than 1 minute of manual intervention.
>>
>>52161857
Several "functional features" (lambdas, persistent data structures), like most language features, cost something in terms of performance on micro-benchmarks.

But it's a poor comparison, take a substantive program written in declarative and functional styles, memoize the functional one as far as you can, and you'll generally find the functional one is faster even if with JVM-tier overhead like clojure has.
>>
File: 1418079207589.png (249 KB, 351x618) Image search: [Google]
1418079207589.png
249 KB, 351x618
>>52164101
>assuming we are using a desktop computer from the year 2000 or older
Should have mention that then, however since you are teaching C, you should instead say "in C a byte is at least 8 bits"

>that was done due to space issues
Use addr instead as it is much more common.

Since you are explaining something as basic, I doubt the person seeing this will know the hex notation. Moreover since it is not necessary in this case, I suggest simply removing the 0x part.
>>
>>52163235
What are bit fields?
>>
>>52164135
More like 'Undefined Behavior'.
>>
>>52164193
>NOT PORTABLE isn't portable
>>
how do i average 3 long longs in c
>>
>>52163865
I mean if you want to write something you expect to be used for real you'll first need a compelling reason why it isn't vi or emacs. Then you'll want to implement it in C or C++ or at least substantive parts of it because mutable memory and low-level disk IO is the only way to get the level of performance we expect form editors.

If you want to have fun doing a project for the sake of learning though python would be a great choice. Haskell could be fun but you'd probably be fighting with the immutability a little bit
>>
>>52164180
In a struct you can add :n after the field to specify the n bits a field consists of.
>>
>>52164214
You don't, it's impossible in C.
>>
>>52161857
C's performance is a product of 40 years of optimization on both the hardware and software end. Some computers, like Lisp machines, were optimized for functional programming and ran functional code at similar speeds to more conventional computers running imperative code, but these computers failed to ever take off and thus modern computers are great at running C/C++ or Fortran code and pretty shitty at running Lisp or Haskell code in comparison.
Thread replies: 255
Thread images: 29

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

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.