/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

cs.dartmouth.edu/~thc/clrscode/
youtube.com/watch?v=oHC1230OpOg
twitter.com/SFWRedditImages

When your mong brain finally understands how to do multiple recursions at once. Haha no more shitty for loops for me.

Remember this graph when people tell you that Java is slow.

>posting rigged benchmark

>using boxplots to show distribution when scale is logarithmic
Whoever made this is a retard.

So, i've been trying to create a data type that is bigger than unsigned long long int.
I managed to overload the + and - operator, but how to do it when the object is on the right side?
For example:
int main()
{
Bigshit foo(16); // 16 is the number of char
Bigshit bar(16);
int baz = 17;
foo = 0; //done by operator=(int)
bar = 15;
foo = bar + baz //done by operator+(int) and operator=(Bigshit&)
baz = foo.to_int() + baz; //Managed to hack it with some method to convert it back to int
foo = 13 + foo //How?????
}

wow, so java is okay :)

Copy and paste your overloading code for + and -, but change the order of the arguments.

...

When writing pseudocode, in a if statement, would you include any specific formulas for things?
For instance, given a point p and another set of 5 points, my method should return the closest point to p. Would I just write:
closest = nullptr;
for(all points in array)
{
if(points[i] is closer to p than closest)
closest = points[i];
}


or would I have to write out the actual formula to get the distance between points[i] and closest?

// distance is associative array of distances to p
closest = nullptr;
for (point in array of points) {
if (closest == nullptr or distance[point] < distance[closest]) {
closest = point;
}
}

At the end of the day, Java's speed does not matter when PIC RELATED happens -and that's a mild one without any AOP besides the aspect. Real world applications written by Indian codemonkeys and recent graduate imbeciles who are aiming for management asap can be thrice as long.

I say that as Spring microservice architect.

Thanks.
Would you not need to declare distance[] explicitly then?

In this case it is implied that it is already initialised properly, which I personally feel a comment is more suitable for explaining.

Use free functions.

why are people aiming for management asap when they studied programming for so long?

The idea is to omit language-specific details and abstract away irrelevant operations in a consistent manner. Instead, you have an inconsistent mix of irrelevant C++-specific constructs and verbal explanations. Here's something saner:
min_dist = infinity

for each point in point_array
if dist(point, p) < min_dist
min_dist = dist(point, p)
closest = p

I usually look into clrs and copycat that shit when I need to write some pseudocode
oh and there should be a latex extension to do it clrs style

>distance is associative array
>nullptr
You're just repeating his errors in a different form. How is nullptr or "associative array" relevant to the algorithm?

Oops. Should be "closest = point".

Okay thanks.
For dist(), would you not need to explicitly include a formula for, say, eucldean distance? Or is that unnecessary?

Microoptimized Java is fast. Nonallocating Java is fast.

Java code that creates unnecessary new objects everywhere is still going to be slow because the JIT won't be able to optimize it. The issue with Java is the programming culture around it (and the memory usage).

What's the deal with the face of the "watch this" dude, I've seen him in several other memes

fair enough. I was just messing anyway. Recommend any book to help with this "culture"? I am newish to the scene (1.5years)

>Java code that creates unnecessary new objects everywhere is still going to be slow because the JIT won't be able to optimize it.
it depends how easy it is to do escape analysis

enjoy your stack being raped then
pajeet performance ahoy!

I don't know what to make my dudes, give me some ideas?}

having a lot of free time at work

Anybody here use Scrapy? What sort of stuff do you create from web-crawling?

build a program to parse html with regexes instead of using a dedicated parser

Kek my dude, for real i need an idea :c

Is there a computer science book not directly connected to programming that I could benefit from reading if I'm a self-taught programmer?

>using a dedicated parser

And? REGEX under the hood on backend. Just because mask looks pretty does not mean it is not ugly behind

what do you do for a living

I am a developer, a c# developer so no bulli please i know i'm not using a 'real language'

Michael Sipser - Introduction to the Theory of Computation

>le real language meme
you are your own retard

>Introduction to the Theory of Computation

Thanks!

Did you notice the single quotation marks?

np
also Code: The Hidden Language of Computer Hardware and Software is a very good book if you don't know much about low level stuff

>For dist(), would you not need to explicitly include a formula for, say, eucldean distance? Or is that unnecessary?
It works for any valid definition of distance, if "closest" means "having the smallest distance to", so it's unnecessary.

How do people make programming languages? As someone who doesn't know how to use a search engine properly or program well, could I ever make one through the power of autism?

Autism

>As someone who doesn't know how to use a search engine properly or program well, could I ever make one through the power of autism?
Yes, but C++ already exists.

Well Brainfuck is technically a programming language and that's pretty simple

>function signatures have a time complexity
>the concept of a linked list is tied to malloc
>malloc is O(n) for n nodes
#include
#include
#include

typedef struct {
void *next;
int data;
}NODE;

void alloc(int n) {
void *nodes[10000];

for(int i = 0; i < n; ++i) {
nodes[i] = malloc(sizeof(NODE));
}

for(int i = 0; i < n; ++i) {
free(nodes[i]);
}
}

float ts() {
return ((float)clock()) / CLOCKS_PER_SEC;
}

int main()
{
float t0 = ts();

for(int i = 0; i < 10000; ++i) {
alloc(1000);
}

float t1 = ts();

for(int i = 0; i < 10000; ++i) {
alloc(10000);
}

float t2 = ts();

printf("%f %f", t1 - t0, t2 - t1);
return 0;
}

When did you realize /dpt/ was eugenics propaganda material?

just drop it jesus christ

i don't like the look, but it does exist
cs.dartmouth.edu/~thc/clrscode/

Do you wear a white lab coat when programming?

You are a computer SCIENTIST aren't you?

>white lab coat
That's inferior "science" uniform. Computer scientists wear skirts and white knee socks.

>not wearing both lab coats and knee socks when programming
Fucking amateurs

I think I learned Ruby to its entirety but I can't make a functioning calculator. The same thing happened with C, I "learned" a language and had no idea how to apply it practically

Am I damned to be a moron or am I missing something?

I practice nudist programming.

>can't make a functioning calculator
>Am I damned to be a moron
Probably.

spotted
L
O
N
D
O
N

Rate my programming language.
[>> #(1 100)i%3/5/15?$fizz:$buzz:.]:(T:=int->mod->out)

It's shit

So, the only coding language I know is java, and I've been thinking of how to implement this idea I had. Basically, I work in a biochemistry research lab, and very frequently have monstrous lists of proteins implicated my mass spec analysis. I want to be able to interact with google scholar or something and search for each protein, along with a set of keywords, and pull publications. I'd probably want to only pull publications with the keywords in the title. Any ideas on where to start learning how to do this. My only question would be how to interact with google or another catalog of publications.

I meant to make my own thread, but if you guys have any recs that'd be cool

>t. javeet

Use java URL to visit web pages and optionally use something like jsoup to parse those pages

Look for an API to interact with Google Scholar or use a scraper.

Sounds like something that can be done in 5 lines of Python.

Or two lines of Common Lisp.

Or one line with clever use of list comprehensions

>implying your memes have a library for this
>implying it wouldn't take more than 5 lines without a library

Is this worth grabbing as someone who wants to get into a programming job?

Common Lisp actually does have a library for google parsing, and its list comprehension supports way more than Java or Python combined.

LISP is the GOAT language. Best language on earth. Prove me wrong

Protip: You can. I'm totally bullshitting you.

Consider this:
70% of language is syntax and usage, rest 30% - toolkit.

95% of programming is math and CS, rest 5% - language of choice.


Do the first-grade math to realize how little language matters

JVM object allocation is literally free because it just leaks as much memory as humanly possible. If the program finishes before garbage collection is needed there will be no overhead at all. Nobody really cares abour memory usage. Unused RAM is wasted.

>95% of programming is math and CS, rest 5% - language of choice.
Imagine being so deeply delusional...

>95% of programming is math and CS
i only wish this were true

Python is the only acceptable Lisp.

...

if (something.StartsWith("thing"))
return something.Substring(5, something.Length-5);
return something;

What's a more elegant way of doing this?

This is fine.

>Nobody really cares abour memory usage.
youtube.com/watch?v=oHC1230OpOg

Instead of Substring you can use LINQ

something.Skip(5).ToString();

NUDISTO BIICHI!!

hey thanks, I still need to wrap my head around LINQ expressions

is it purely shorthand or does it change the time-complexity?

but BeautifulSoup exists

How are you defining learned? If you can't write functional programs from a description I wouldn't say you learned the language.

Reading the Ruby C source code of some built-in extensions. Truly much superior to Python. Python C interface feels like Windows API programming, Ruby feels like a proper UNIX-like C program.

func odd(x: Int) -> (p: Bool | p => exists y. x + 1 = 2 * y);

func even(x: Int) -> (p: Bool | p => exists y. x = 2 * y) {
if x < 0 {
odd(x + 1)
} else if x = 0 {
true
} else {
odd(x - 1)
}
}

func odd(x) {
decreasing if x >= 0 { x } else { -x };
if x < 0 {
even(x + 1)
} else if x = 0 {
false
} else {
even(x - 1)
}
}


func incr(r: &[\(_, _). true, \(x, x'). x + 1 = x'] Int) -> () {
let x := *r;
// if *r = x then global progress may not have been made
if !cas(r, x, x + 1) {
// *r != x proves global progress was made; it's safe to retry
incr(r)
}
}

Rate my programming language.

Was your "learning" all about watching videos?

It truly is beautiful.

It's not a shorthand. That Skip function can be applied to any IEnumerable. It shouldn't really make a difference in terms of performance.

And Lua?

The culture of design patterns evolved naturally in order to get around the limitations of the Java language. The real problem is retards who have no idea why they're doing these things and thus apply them by default everywhere without thinking and without justification, as well as retards who also don't know anything and start memeing about it.

Factories. Their entire purpose is to stop users of the class from constructing objects with new. Writing new SomeClass results in tightly-coupled code down to the ABI. If you decide to delete SomeClass later, you will break compatibility with all users of your code. It's much better to make a small interface and a static method that returns instances of that interface. Now you can swap out the actual types with impunity.

Singletons. Why do they exist? Why can't you just make a static class and call it a day? Because classes aren't objects, they can't be passed around as arguments, they can't implement interfaces. So the solution is to make a class that goes to autistic lengths to maintain exactly one static instance of itself. That class can implement interfaces and the instance can be passed around.

These things exist because Java sucks as a language and we need to work around it's limitations. Better languages like Ruby don't need any of this junk; in Ruby, classes are objects and new isn't a keyword, it's an overridable factory method present in every class. Of course, Sup Forums retards who don't know this will make meme projects with SingletonFactoryFactories and such instances of ironic uneducated humor.

Lua has a fucked up naming convention.

Accessing an element in a vector is not O(1).
For this, you need to dereference a pointer, which requires you to address memory. Addressing memory is O(log(n)).

strangely, the go4 book predates java

Nah it's fine

Haven't looked at it.

Good evening /dpt/. I've been writing JavaScript (NodeJS, I really don't like frontend) for a year and a half - not professionally, mind you -, but I've been meaning to move on to something closer to the hardware.

I was dabbling in C for a week or two, but it just feels so clunky when compared to JS.
Is there any language with control like C, but as comfy as JS?

Pic related is an example of what I find comfy about JS.

Try Rust.

C++.

>Is there any language with control like C, but as comfy as JS?
No. Higher level languages are comfier by definition because they're less lower level.

Have you actually ever worked anywhere with real processing to do? Literally nobody cares about the resources consumed, they just buy more because the value of what they are getting far exceeds their cost.

I'm guessing Java blew up your shitty laptop's 4 GB of memory and caused the OS to swap out to its slow ass 5400 RPM drive and drive you nuts. The difference is the money-making company matters a lot while cheap ass laptop lusers don't matter at all.

create a function called "replace" that takes a string, a string to search for, and a string to replace it with
call it like this to simply erase
return replace(something, "thing", "");

if you like, you can have it take a fourth parameter (with a default) so you can do things like REPLACE_ALL, REPLACE_ATSTART, and so on