/dpt/ - Daily Programming Thread

What are you working on, Jow Forums?

Previous thread:

Attached: that one dpt picture the same anon posts every time.png (406x467, 20K)

Other urls found in this thread:

github.com/UsabilityEtc/d3-space-filler-explorer
github.com/edvin/tornadofx-guide/blob/master/part1/8. Charts.md
twitter.com/NSFWRedditImage

Attached: 1496748874565.png (500x855, 143K)

Thank you for not using a vegetable image user !

>c#
>beautiful and cleanly designed language

Templates are just syntax macroes pending to be an elaborate type system. Quit this smugness and just be your homoiconic self. You were born that way

Anyone here read Structure and Interpretation of Computer Programs? I've heard that it's got a bit of an inflated reputation thanks to its cult-like following of advocates

Attached: pool_study.jpg (599x775, 88K)

Thought it was C++, had my finger on the meme folder...

>Core 2.1
>still unstable as fuck on linux
>half of EF is missing

b-b-b-but you saw how much features we added. W-w-w-we cross platform!

>Java™ 10
>added var
>can't even crossplatform console beep

Discovering that GNU Smalltalk has a fatal floating-point bug on macOS, rendering it unusable.

Its reputation is well-deserved. The issue is, IMO, it gets recommended when it shouldn't really be.

It's an introduction to computer science, not the panacea for all programming.

>not fixing the fuck
you are doing it wrong

It ain't released is it?

what does this line mean in C++ if both these variables are ints?
if (!(visited & 1

> implying I know anything, whatsoever, about floating-point arithmetic

check the bit "last" digits from the right is not set

Yes, March 20th. I'm lagging.

Value classes when tho?

Working on a CLI program
For Reddit
In Rust

I meant to ask what does the & do specifically.

I'm thinking of making a circuit simulator, sort of like LT Spice.
I want the user to be able to input LaTeX as a label and have it formatted correctly into an image.

I've been trying to look for "Text->LaTeX" converters I could use, but most of them are for Windows. I'm planning on making my application for Mac OS X.
Anyone know of something I could use?

bitwise AND

First for Erlang

Attached: toptal-blog-image-1373446107190(2).png (1248x1016, 38K)

*upvoted*

It checks whether the last bit in visited is not set

Attached: OO.png (719x712, 74K)

>"Text->LaTeX" converters
Latex *is* text.

python

how to do this in one line
pst = []
for i in range(100):
if i < 10:
pst.append("0000" + str(i))
else:
pst.append("000" + str(i))


i tried
pst = ["000" + str(i) for i in range(100) if i > 10 else "0000"+str(i)]


but no luck

why would java be limited to 2 cpus?

you could just format with %05d

Because its shit

Honestly, visited should be a std::bitset / std::vector and the check should be !visited[last]

The programmer is obviously an idiot who fell for the "start with C first" meme and now is coding around C limitations that don't exist.

Let me guess, you're a 4th year CS major.

The "&" is a bitwise AND, which compares each set of bits and returns a "1" if both bits in the location are 1

In this case, you are shifting 1 by "Last" amount of bits to the left. This gives you a pattern like (if ints were 8 bit numbers):
1 = 0 0 0 0 0 0 0 1
1

Attached: Screen Shot 2018-04-17 at 11.09.56 AM.png (1334x844, 131K)

what if they don't want flexible size

Short answer: is the "last" bit 0? then true.
! means not
& means and

thanks bruv

if else inside the for thus before the for in comprehensions. That's what you're having backwards

I thought the C way were to use structs with bitfields.

>constexpr size_t N = sizeof(int)*8;
>using flag_t = std::bitset;

oh is bitset like array?

pst = ["0000" + str(i) if i < 10 else "000" + str(i) for i in range(100)]

you're right.

thanks for the help guys

There is literally no reason to use Rust when you have C++.

Attached: C++.png (972x259, 54K)

Yes. They didn't make the same mistake with std::array that they did with vector.

Haha, nice picture you got there, kiddo.

did the course a few years ago

java has the current state of art garbage collector which is fully parallel.

yes.
thanks

i precise that by java i do mean hotspot.

That's not the same issue

#include

int main()
{
printf("Hello world!\n");
return 0;
}


$ valgrind g++ test.cpp -o test -std=c++11 -Wall -Wextra -Wpedantic
...
==7787== HEAP SUMMARY:
==7787== in use at exit: 153,353 bytes in 206 blocks
==7787== total heap usage: 371 allocs, 165 frees, 174,967 bytes allocated
==7787==
==7787== LEAK SUMMARY:
==7787== definitely lost: 35,997 bytes in 135 blocks
==7787== indirectly lost: 82 bytes in 5 blocks
==7787== possibly lost: 0 bytes in 0 blocks
==7787== still reachable: 117,274 bytes in 66 blocks
==7787== suppressed: 0 bytes in 0 blocks
==7787== Rerun with --leak-check=full to see details of leaked memory
==7787==
==7787== For counts of detected and suppressed errors, rerun with: -v
==7787== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


$ valgrind clang++ test.cpp -o test -std=c++11 -Wall -Wextra -Wpedantic
...
==7796== HEAP SUMMARY:
==7796== in use at exit: 80,809 bytes in 5 blocks
==7796== total heap usage: 31,777 allocs, 31,772 frees, 1,637,502 bytes allocated
==7796==
==7796== LEAK SUMMARY:
==7796== definitely lost: 0 bytes in 0 blocks
==7796== indirectly lost: 0 bytes in 0 blocks
==7796== possibly lost: 0 bytes in 0 blocks
==7796== still reachable: 80,809 bytes in 5 blocks
==7796== suppressed: 0 bytes in 0 blocks
==7796== Rerun with --leak-check=full to see details of leaked memory
==7796==
==7796== For counts of detected and suppressed errors, rerun with: -v
==7796== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)


Wow! GCC BTFO!

Java 9 has like 5 different garbage collectors, unless they removed some. I assume you're speaking of the default G1.

Wouldn't have been a "mistake" if they used persistent immutable vectors tho

Don't you mean clang btfo?
31 000 allocations, 1.6MB for hello world, what the fuck?
gcc is bad enough (you shouldn't need any dynamic allocations just to pint a static string of text), but that is ridiculous.

>sepples

Memory-mapping executables and libraries probably count as allocations. You also need buffers for stdin stdout stderr as well as probably all the mutable static storages. And some other stuff surely. Would be my guess. C++ is still quite bloated tho. Comparison with C?

Erlang had GC for thread allow low latency because GC begin smalls and clean Independent.

But Java GC is better for high performance task.

I thought I'd pick up my ASCII raymarcher again. Maybe get a movable camera working properly.

Attached: ascii_rm.gif (962x582, 918K)

I should be able to do
SELECT a+b AS c FROM t
on pl/sql, right?

sup /dpt/

I need to build a desktop app with a fancy UI that displays colorful normie charts to show clients. I've never done UIs so I don't know what to use, have been told javafx is a good option for this tho. what do you suggest?

Attached: 1509009522495.jpg (1183x1674, 283K)

Either QML or go full cancer and Electron with Chart.js.

Qt or JavaFX. Are you sure your clients don't expect a web UI?

spring webapp with a frontend would be the easiest way to do it

Can a text file be accessed by more than one application for reading and writing at the same time?

Attached: 1523057204568.png (1200x1483, 1.1M)

Electron plus D3.js.
github.com/UsabilityEtc/d3-space-filler-explorer

JavaFX will died and begin hard found documentation and get started.

WPF + C# begin nice but need learn too much.

QT have ass rape license model.

thanks m80s, i'll look into those and come back later

the chart data is supposed to include some numbers they'd rather not leak to competition, so it's gonna be a desktop app they can show to clients on one-on-one visits. it's a solar panel manufacturer by the way

Attached: 1509047329895.jpg (1132x1600, 812K)

in that case do the fastest thing that can work, e.g. kotlin + tornadofx instead of java + javafx (less bloat) - as long as the integrated chart types or an appropriate chart library does the job for you
Example:
github.com/edvin/tornadofx-guide/blob/master/part1/8. Charts.md

but if you need fancy animations and interactivity, the JS cancer libs are probably a better choice
remember: right tool for the job

>the chart data is supposed to include some numbers they'd rather not leak to competition, so it's gonna be a desktop app they can show to clients on one-on-one visits. it's a solar panel manufacturer by the way
Oh, OK.
Just make sure you pick a framework with proper chart support.

Is using a calculator in programming cheating?

Not him but:
1) C# is not homoiconic.
2) Homoiconicity is a good thing.

On the contrary, using a calculator in programming, at least in COMPUTER programming, is by definition the only way to do it.

I thought programmers did all the math and stuff in their heads or on paper

What are some statically typed homoiconic languages?

Is there a homoiconic language with expressive static type system?

lisp is a homo icon alright

>What are some statically typed homoiconic languages?
Not possible. Also not desirable.
No, but there are plenty with expressive dynamic value systems.
Type systems are shit by the way.
In general.
All of them.
Not just the static ones either.

I've been programming in statically typed languages for over 20 years now, and I find static typing to hold little value for regular business applications. It's valuable when doing systems programming.

which statically typed languages?

JABA :DDDDDD

C, C++, Delphi (ages ago), Java, Scala, C# (a little bit). Tried Rust a bit. Been doing mostly Java and Scala lately.

try Haskell with GHC extensions

the halting problem can't be solved but here is a solution to the problem *of* the halting problem.
just give every type a special "undefined" value.
now all partial functions are total gg no re.
even infinite loops.
because say you have a function that should return a Nat but actually just keeps incrementing it forever.
what does that function return?
well, it's not defined what it returns, because it doesn't.
guess what? the Nat type now has a value for that.
hence the function is total.
GG NO FUCKIN RE

Attached: grad.png (2154x2167, 200K)

not him but haskell is shit it literally does not even have:
>functions
>types
>moan ads
>lamb duhs
>mod you'lls
>algebraic types
>types
>you nyuns
>PoO
>closures
>co/contra very ants
>vidya
>muh types
>thype thery

not to mention it is lacking:
>lazy eval
>currying

>"Haskell doesn't have these things therefore it sucks"
>proceeds to list specifically all the things Haskell is known for having
wat

So P really does equal NP thank you.

@65580278
low effort shitpost

Not even then, really. Static typing is literally never valuable.
In business applications, they are excessively restrictive. They are ALWAYS more restrictive than the underlying program logic they strive to express, REGARDLESS of how """"good"""" the type system in question is or how simple the program logic is, with NO EXCEPTIONS, not even in Haskell, Liquid Haskell, Idris, or Oh Camel. And in systems programming, the efficiency you gain from using them could just as easily be bought by going completely typeless, with no static OR dynamic types, and doing everything in terms of pure byte/word logic.

arigatou sesu denpai

Java uses OS native threads which makes multithreading very expensive compared to others

Is it acceptable to use a binary search algorithm to approximate a calculation because you can't be arsed to do the manual algebra it would take to find a constant time closed form?

I mean O(log n) isn't THAT much worse than O(1) rite?

Attached: 1516853355139.png (618x618, 90K)

No it isnt, there are tons of approximation formulas you could use.

I'm too drunk to be effortposting on Jow Forums. I expected the Haskell response. When one is dissatisfied with Java's type system, there's two ways you can go. You can go with dynamic typing or you can go ball's deep into types and find a language with a more complete type system, which is where haskell comes in. At find I loved the things that were introduced over the years in java like generics, I felt that it better specified how to fit code together at interface boundaries. Then scala added more things etc... but then I found myself disillusioned with types.

I've found that whatever interface clarity (parameters, returns) types added, it never quite removed all the validation I had to do. So while the type spec checked some things, it didn't check everything so there were often extra checks. In Java you had to check for null values. Then you took something like Kotlin or Ceylon which allowed you to declare if type was nullable. You still had to check string lengths or whether the integer that represents an id is positive. Of course you can switch to a type system that supports that. Then something else is missing. There's always some concepts that are beyond the type system and even if type system is turing complete, there's things that are dynamic in nature, not determinable at compile time (input is data over the wire). At the same time as you go deeper into this, the code gets less readable. I work with people who are delighted about generics and other things like that. Their code is not maintainable by anyone but them. At some point of type system complexity the types start to be a lot of noise because their specifications start to have very little to do with the business problem that you're trying to solve.

For this purpose I prefer the solution introduced in Clojure 1.9, the spec system, where the specification of a datastructure, parameter or return type can be pretty much anything, including runtime loads from a db. The sky is the limit. (cont.

Just check correctness algorithm.
Post problem

(cont)
It also generates specced data, enabling a bunch of things like generative tests.

In any case, the other thing people really like types for is to describe library API, so you don't have to look into documentation for what the parameters are. I liked that too, but then I noticed, that more often that not that information is not enough. Either the type is too simple, like Integer id, which doesn't at all describe which id or which form of ID that is. Then there's the cases where the construct parameter is a bespoke datastructure (like ClientConfig class), which has many fields. The type spec itself doesn't specify which of the 20 fields have to be filled, which are mutually exclusive options, or the rules like "if client timeout is set to 0 then field x is ignored", "if type is 'async' then callback handler param is required, else not", and so on. Or the thing has 5 or 10 overloads that do all sorts of things. So I often ended up looking into documentation or even more often, sources, to get a clue how to call or construct something. Same goes for returns.

None of these things really go away if you use structs instead of classes, or functional instead of OO.

At the same time that I noticed that I wasn't gaining much from the type system, I noticed that dynamic system had something to offer, and that is a generalised interface to accessing data. So when using C structs or Java classes I had to code toward the interface of the data structure (which is basically a mini-DSL), something like Clojure that said "99% of things is a combination of lists, maps and primitives, and here's 200 functions to manipulate that" allowed for much clearer code when processing data in a typical business app.

So that was my experience in last 20 years. I was hardcore type enthusiast, but now I like clean and simple code and I spec all data in code and I don't care about having to look up API documentation since I always ended up having to do that when I used types too

ayylmao who cares c++ everything its gonna be c# in 3 years.

I know the calories in a pound of human fat.
I know the calories in a pound of human muscle.
I know the calories in a pound of human bone.
I know how to map age and sex to average height, weight, and percent body fat, for ages 0 to 20 inclusive.
I know the percent of body weight made up by bone, regardless of how heavy or light said body may be. (Bone mass scales with weight gain and loss.)
I know that I am working with hypothetical "ideally lazy" individuals, whose lifestyles are so unimaginably sedentary that any and all weight gain is accounted for entirely in fat and bone, with no muscle gain. These people can only change their muscle mass by *losing* muscle, and this only after all their fat is gone. (My system does not account for essential fat.)
Given an age, sex, and number of calories contained, I am interested in calculating the weight of the person described by these properties, under this system.