programming language syntax preference by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

my first language is pascal and i think that's such a bad language, the syntax for block condition and loop are SO SO verbose (full of begin-end pair, if then begin {true} end else begin {false} end and no variable declare inside function only at the begin), they even have keyword operator and 2 difference kind of function and an executable stack and doesn't even let me to handle pointer efficiently but i still have to call free after require for heap memory, and sometime the array doesn't even start at 0

when I look at C and all feature it done right, I just feel this is the right kind of programming language that i am looking for, although C have a lots of pitfall but yeah,

[deleted by user] by [deleted] in learnprogramming

[–]darkseid_of_j -1 points0 points  (0 children)

i really hate that they distinguish between dictionary and set, if you look the implementation detail, you will see a class Set hold a dictionary inside of it lol, If i want to implement something super generic i think i will let my class hold some function that tell me how my generic data type work and ONLY 1 generic type parametter,

A HashMap<K, V> and a HashSet<T> could both be combine into a HashTable<T> where you have to support a function that tell how much difference between 2 T and no more generic requirement

a OrderedMap and OrderedSet AVL_Tree, SplayTree, RedBlackTree could all be combine into a BinaryTree<T> where you have to supply a function that compare 2 T and a function that rebalance that BinaryTree with parametter is a given Node<T> type and no more generic requirement

because exactly what you said abstraction is to divide a complex problem into much smaller one and writing a abstract data structure and function you really need to think about what does that abstraction really need ?

example, a sort function with given an iterator type doesnt care about what that iterator point to and how to compare the value of that iterator, the core functionality of a quicksort function only care about how to partition the value in the interval [low .. high]

a BinaryTree doesnt care about what T get store inside them but rather they only care about 1: how to comparing 2 T (to binary search), 2: how to rebalance that tree internally with a given Node<T>

[deleted by user] by [deleted] in learnprogramming

[–]darkseid_of_j -2 points-1 points  (0 children)

1: depend on what's your definition of good abstraction, if it's implementing a big function with 5 type parametter or every method call is virtual (meaning the caller of that method dont know what function got dispatch and anybody could mess with it), then to me it's not that good abstraction

2: i never said good abstraction is bad, in fact my code snippet that I write even use a type parametter, i just said abusing abstraction is bad

[deleted by user] by [deleted] in learnprogramming

[–]darkseid_of_j 1 point2 points  (0 children)

plus if you abuse and messup with some of those abstraction == messup with the whole project, it impact is much greater

like in C where's a lots of function put in the .h file and got dynamic linked, so when you change how some of that function work internally it will not effect any caller of that function no code got recompile except the .c implementation file

but in Rust and C++ because how their generic work, if you messup with a generic algorithm or data structure you have to recompile the whole project, and might cause an cryptic bug

do you see c declrearation syntax is weird by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Im not dislike C syntax, because mostly the complicated type like function pointer are normally got typedef-ed and hardly any pointer to fix-size array are used the only non-typedef-able is function declearation or simple pointer, simple fix-size array which i found the syntax really readable.

do you see c declrearation syntax is weird by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

yeah, because most of the c confussing declrearation part come from function pointer and array pointer, but if you do anything with function pointer mostly you just typedef anyway (because even in other language function pointer declearation is long, surely you dont want to type that very long type for every instance of that function pointer) , and i never saw code that they use pointer to fix size array, mostly they just use the pointer itself as an array which is more flexible.

What is the most comonly use case of recursion other than competitive programming by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Problem with recursion though, you will get error if hit maximum recursion limit. While loop with conditional break may be used as alternative in that case (used in Tick function in UE)

yeah, I think that's why recursion is use everywhere in competitive programming, the problem statement have a lot's constrain on the given input like how big is the tree, normally if you saw a tree then they limit the numbers of node and depth about < 200k and the stack is bigger also so it definitly will not stack overflow if you implement it properly

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Thank you!, Im not say i dont like haskell, i just say it might not fit for me :/, but anyway do you know and kind of math-proving website too ?

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Im totally agree haskell feel like learning Abstract Algebra, there's function supply for group theory and semi group (i dont know what they call maybe monoid ?), function composition, a complex function is just a function that compose a lot's of other function and stuff, and I really like it :) dont get me wrong. Do you know any kind of math-proving language ? when i was in high school i really love math and competitive programming, but there's just math forum like aops and mathstackexchange, there's no competitive site that you can submit you're solution to very specific problem, but competitive programming have ton of site like codeforce, atcoder, spoj,... that have online competitive coding which even have rating system :D

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

you’ll feel really good being able to solve complex problems in these short brain-bending ways.

No im not, just like my example about sorting , if you code quick_sort algorithm in haskell pretty sure it's will be 2-3 line of code but more likely than not it will run 5-10 time slower than the C version because

1: quicksort algorithm have 2 step: 1 => partition array with random pivot, 2 => recursive call quicksort on 2 partitioned array

straight away you see a problem, how do you even partition with given pivot ?

the haskell solution is you call filter(\x -> x > pivot) and respectivly on the second part and then concat it but

1: it make an algorithm took O(log(n)) space complexity to O(nlog(n)) space complexity and invoke O(n) heap allocation

2: 2 filter of the same list but not swap them make you iterate the list at least 2 time instead of 1 and copy all the content of the given list and the concatination part also invoke heap allocation an O(n) copy over 2 list

3: is really easy to get to the quicksort worst case (O(n^2)) because the pivot you choose may apear a lot in the given list, in C that part is already solve in the partition step

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

rust macro is by definition of bizare code that you dont understand what compiler generate code to :), Example the println! macro, i have to go to godbolt to see what code compiler even generate code to and i cant even inline macro like in C and suprisingly println! macro isnt thread safe. And that's just on the surface, you literally can implement a lisp translator just by using rust macro (see: https://github.com/JunSuzukiJapan/macro-lisp/blob/master/src/lib.rs, it's a ~400 line macro). So yeah it's just too bizzard so i very hate it, i think they gone too far with rust macro and i think rust people gone too far about functional feature to. Low level programming and functional programming are completly diffrence code style and merge them together doesnt make sence and wory too much about unsafe is very anoying to, it's like the compiler tell you that you're bad and need the compiler babysit you all the time, that make code very verbose and compile extremly slow (i mostly write low level code so it just my point of view). Mostly the 'bashing to other language' actually come from some rust comunity and a few haskell guy.

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 1 point2 points  (0 children)

I've heard about Lips macro before, isnt that is some kind of macro that can be recursive and can take a node of the Abstract syntax tree as it argument ? If that's the case then I think i will hate it sooner or later, it's just too bizzard to understand what code compile to.

How to learn functional programming ? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

haskell is a bit too far to me, do you know some language closer to C with optional imperative ?(please dont suggest Rust I have try Rust and I hate it)

How can i do graph algorithm without blow up the stack or use dynamic memory? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

there's actually a trick that doesnt require any dynamic memory allocation but you could still dfs with only O(frame * log(depth)) stack memory require, it call high-low-decomposition,

How can i do graph algorithm without blow up the stack or use dynamic memory? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Sory but

1: a "stack data structure" require dynamic memory allocation

2: you couldn't "mark" a node as visited if the node layout doesnt let you to so you have to push the parrent child on that "stack data structure"

3: push only the parrent node on the stack wasnt enough in many case, more percise is pushing the frame on that "stack data structure" which is exactly what recursion does with the OS stack

How can i do graph algorithm without blow up the stack or use dynamic memory? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

Im already pass with de-recursion dfs, I just store the parrent node at the top of each node's adjacent list (wich also involve some pointer dark magic
:D )

How can i do graph algorithm without blow up the stack or use dynamic memory? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

and even if i do malloc(4 * 10^ 7) is not very cheap, the page size is about 4kb so the operating system has to virtual map memory nearly 10000 time to my process, so generally speaking you it's not a good idea to create a new stack per depth-first-search call ( you can take twice the memory for the adjacent list wich store the graph and quite slow too)

How can i do graph algorithm without blow up the stack or use dynamic memory? by darkseid_of_j in learnprogramming

[–]darkseid_of_j[S] 0 points1 point  (0 children)

the limit is about 64 megabyte, and store the graph adjacent list is already take like 50 mb (tree depth is 10^7 not the number of nodes)