Programming thread

  • 🐕 I am attempting to get the site runnning as fast as possible. If you are experiencing slow page load times, please report it.
EDIT: Just read Squishy's post. I neglected to mention that's another huge issue with OOP, when inheritance gets that deep you may as well be Columbus charting America trying to find any meaningful behaviour or implementation or what the fuck anything actually is.
Yeah, basically. I like OOP myself, but I make a point of absolutely never using more than 1 layer of inheritance because of this shit. If you need to inherit more than twice, you are doing it wrong.
 
Yeah, basically. I like OOP myself, but I make a point of absolutely never using more than 1 layer of inheritance because of this shit. If you need to inherit more than twice, you are doing it wrong.
Reminds me of writing triple-star programs in C in high school. I did it mainly to prove that I could but in practice it's considered a code smell to go beyond **, as I understand it.
 
Reminds me of writing triple-star programs in C in high school. I did it mainly to prove that I could but in practice it's considered a code smell to go beyond **, as I understand it.
There's probably some universal truth hiding in there.

A value is just that, a value. The mapping is nil-> value.
A pointer is a direction to a value. This is a novel level of indirection. The mapping is Pointer->Value.
A pointer pointer is a direction to a direction. This is another novel level of indirection. The mapping is Pointer->Pointer.
A triple pointer is a direction to a direction to a direction. This is not a new level of indirection, since the mapping is still pointer -> pointer.

There must be some maxim that two levels of indirection is all you should ever need, because beyond that you're not creating new information. Someone smarter than me's probably written a thesis on it or something.
 
There's probably some universal truth hiding in there.

A value is just that, a value. The mapping is nil-> value.
A pointer is a direction to a value. This is a novel level of indirection. The mapping is Pointer->Value.
A pointer pointer is a direction to a direction. This is another novel level of indirection. The mapping is Pointer->Pointer.
A triple pointer is a direction to a direction to a direction. This is not a new level of indirection, since the mapping is still pointer -> pointer.

There must be some maxim that two levels of indirection is all you should ever need, because beyond that you're not creating new information. Someone smarter than me's probably written a thesis on it or something.
Another reason that comes to mind is that ** can be mentally visualized as a two-dimensional (possibly "ragged") structure whereas *** is hitting something like a cube and becomes increasingly difficult to reason about.
 
I'm considering writing my own programming language (who hasn't), but I'm stuck on what I should target with the back-end.
It doesn't matter what you target as long as the output can run somewhere. Most of the interesting decisions to make for a compiler are in the front end anyways. What features do you want in your programming language?

I've also been at pain wondering if I should just write the lexer myself, or try and fuck with a compiler compiler, for which I'm truly at a loss.
I have found compiler compilers to be annoying to use, I've always found it to be easier to write the whole thing by hand as a set of mutually recursive functions rather than describe the language in some custom BNF syntax unique to the compiler compiler.
 
  • Thunk-Provoking
Reactions: Belisarius Cawl
I've thought about writing a programming language but kind of lack motivation because I can't think of any really novel features that I'd like to add to what already exists, even fairly minor ones. Anyway I think it would probably be a Lisp due to the dead-simple syntax or maybe a Smalltalk also because of the syntax. (I don't think any other language (besides Self which was the origin of prototype faggotry) does keyword messages which are very readable.) Not sure how I'd implement it all. I know that Raku (formerly Perl 6) has first-class grammars which might be quite useful for implementing a (very slow) language but I'm going to have to hold my nose for Perl's weak typing which has continued into Raku, though possibly there are more safeguards against its downsides. Thoughts?
 
My personal preference, in order, is:
Declarative (Pure State, Implies Behaviour)
Functional (Pure Behaviour)
Procedural/Imperative (Mutations)
Object-Oriented (For Well Defined Objects/Domains, prefer Composition > Inheritance)
I'm definitely a far less skilled programmer compared to most others on this thread, so forgive me if this is a stupid question - but couldn't you argue that declarative programming is even worse than the limitations of OOP because of the immutable data structures that come with it? Especially memory-wise? On top of the potential abstraction costs that can be attributed to declarative-style
 
but couldn't you argue that declarative programming is even worse than the limitations of OOP because of the immutable data structures that come with it? Especially memory-wise?
Once you make your data structures immutable and garbage-collected, it opens up a whole new universe of hacks to get that memory back. Just as a very simple example, take a C-style string. If you make everything immutable, "Hello world", "world", and "d" can all be implemented as pointers into the same buffer, and you only need to allocate new memory if someone actually modifies something.

A good book on the topic is "Purely Functional Data Structures": https://www.cambridge.org/core/book...a-structures/0409255DA1B48FA731859AC72E34D494
 
I've thought about writing a programming language but kind of lack motivation because I can't think of any really novel features that I'd like to add to what already exists, even fairly minor ones. Anyway I think it would probably be a Lisp due to the dead-simple syntax or maybe a Smalltalk also because of the syntax. (I don't think any other language (besides Self which was the origin of prototype faggotry) does keyword messages which are very readable.) Not sure how I'd implement it all. I know that Raku (formerly Perl 6) has first-class grammars which might be quite useful for implementing a (very slow) language but I'm going to have to hold my nose for Perl's weak typing which has continued into Raku, though possibly there are more safeguards against its downsides. Thoughts?
Make it the exact same thing as c-sharp or c but all of the syntax is written like words of power not meant to be spoken with human tongues.

Or APL but egyptian heiroglyphics.
 
Wait, it's not?
If it was I'd just code in that because fucking fuck yeah.

There was a stint of time I was microdosing shrooms before I code and one time I fucked up the dose and I blinked my eyes while I was typing out a function and every single character on the screen immediately looked like actual egyptian fucking hieroglyphics and did not go away.

The rest of my day was like

 
Anyway I know that Raku (formerly Perl 6) has first-class grammars which might be quite useful for implementing a (very slow) language but I'm going to have to hold my nose for Perl's weak typing which has continued into Raku, though possibly there are more safeguards against its downsides. Thoughts?
Perl's typing is fine because it knows how to do it. A variable exists as both a number and a string and because it uses different operators for comparing numbers vs text you'll always get the one you want. JavaScript OTOH will make you hate your life because variables are one or the other and just change without warning and then crash. Why couldn't it just change back without telling me the way it did the first time? Don't make the mistake of thinking X sucks just because one language sucks at X. Also pretty sure you could use raku to create a strictly typed language if you want.
 
Perl's typing is fine because it knows how to do it. A variable exists as both a number and a string and because it uses different operators for comparing numbers vs text you'll always get the one you want. JavaScript OTOH will make you hate your life because variables are one or the other and just change without warning and then crash. Why couldn't it just change back without telling me the way it did the first time? Don't make the mistake of thinking X sucks just because one language sucks at X. Also pretty sure you could use raku to create a strictly typed language if you want.
I used to write a lot of Perl 5 and thought I remembered weak typing being a pain but OTOH I could be mixing up distant memories with those of JS. Also of course one could use Raku to write a compiler for any sort of language.
 
Writing parsers in Haskell is often part of introductory course.
It is as simple as defining newtype Parser a = String -> Maybe (a, String) which is just a function that takes String and returns a (which might be a token, statement or whatever) and the rest of String. Then you can wrap it in Maybe or Either for some basic error handling.

Afterwards you create instance of Functor, Aplicative, Monad and Alternative for Parser type. And you now can combine it to do anything you want.
e.g.
Code:
parseChar :: Char -> Parser Char
parseChar c = Parser fn
  where 
    fn []         = Nothing
    fn (x:xs) 
      | c == x    = Just (c, xs)
      | otherwise = Nothing
is parser which takes Char and returns Parser Char Parser Char :: (String -> Maybe (Char, String))
Which is a function that will take String and return Char + rest of the String if the character is the first character that occurred in string, or Nothing otherwise.

Then you can combine those smaller parser using Alternative to automatically choose first possible parsing output
e.g.
Code:
parseWhitespace :: Parser Whitespace
parseWhitespace = charP ' ' <|> charP '\n' <|> charP '\t'
Will try to parse either space, newline or tab and will return Whitespace.

There is nice Tsoding video that goes more into detail.
But it's amazing how easy it is when done in functional style.
I assume it will be similiar in OCaml.
 
Using PHP for the first time to make a simple webapp with minimal dependencies. Thoughts so far:

1. Overall idea of the language is great. Stateless per-request execution while allowing code to freely mix with HTML lets you whip out a prototype really fast. There's a reason the retards in Javascript land have spent the past decade reinventing it through the React + JSX circus.
2. Syntax sucks ass, using "$" as a variable prefix was a a horrible idea. Fuck Perl for starting this shit.
3. Standard library is a fucking trashheap. mime_content_type() can't even get the right result for a goddamn CSS file. Had to copy paste some asshole's code from the comment section like it's 2005.

Overall, it's not too bad. I do wish some hipster had taken the time to write a thin syntax level wrapper that makes it all more palatable. (Sort of like Elixir/Erlang or Typescript/JS.)
 
Back