« first day (4408 days earlier)      last day (734 days later) » 

15:00
should main be implicitly public?
Public to who
No, it shouldn't normally be public
who, exactly, will be accessing main other than the interpreter?
nobody, that's who
Would libraries ever need mains?
Only reason to have it public is if it calls itself recursively via another function in a different namespace. This should be very rare
15:01
@RydwolfPrograms nope, why would they?
so how about main gets to be (according to the parser) an access modifier, like public or private
I guess if it was a library that used some sorta thing in the background, like startin g a daemon or something, but that should definitely be done by calling a library.init() sorta function
@RydwolfPrograms hmmmmm
@Ginger ...which is automatically applied to a function named main, right?
Why would the syntax look like main function name()
That's just boilerplate, main is the name
it's 5 characters of boilerplate, only a Gentoo user would complain about that
15:03
@Ginger In rare cases you should be able to make it public
@mousetail huh, really?
The advantage of main as the name instead of a keyword is that libraries' main functions aren't special
What happens if I import something with a main function?
Can I call that function?
Does it get automatically called?
a function marked main should be called automatically upon import, so running a module just involves importing it with no weird if __name__ == "__main__" stuff
No
That's gross
if you don't want that don't mark it main
15:04
3 mins ago, by Rydwolf Programs
Would libraries ever need mains?
if they have initialization to do, sure
No initialization should exist for the library as a whole
Global state is gross
Require the importer to do lib.init() to initiate an instance of that
@RydwolfPrograms I agree wholeheartedly with that
And initialization of a whole library is global state
I think it should be up to the developer
15:06
0
Q: Simultaneously solve N-queens and no-3-in-line

Parcly TaxelAn intriguing MathsSE question asked if there were large N-queens solutions where no three queens lie on a line. That question's body included the unique 4×4 solution up to symmetries . Q . . . . . Q Q . . . . . Q . and noted that there are no solutions for 5×5 to 7×7 because of knight lines. Ho...

but I'm doing it this way and that's static final d:
And let's say two things I depend on import the same module
it only gets called once, because of caching
Do they each run their mains separately?
If they don't that means a second library being run alongside mine can change the behavior of one of my dependencies
Did we have a question on OEIS A326077?
Of course not. But would it make for a good challenge?
15:08
@RydwolfPrograms then just... don't add a main function to a library! do init() the way you suggested!
Libraries should be "immutable". When I import it it should be the same every time. Anything that can change needs to be an instance of something in that library.
@Ginger But if you give people the option, they will take it
Alternatively...I guess you could just refuse to allow importing things with mains
okay, how about this: main is only executed in the module being run
Which may actually be a better option than having main as a private function
all other mains are ignored
actually, I like this idea
Yeah, I guess that'd be fine
15:09
it means libraries can put little demo scripts in their mains that only run when you execute the library directly, like Python's __main__.py
OOOH trueee
Like python without an argument being a REPL
exactly!
and if for some ungodly reason an importer wants to call the demo function directly they can still do that
ok cool
Would main be accessible from the outside? That seems unnecessary
They could always create a public wrapper around it
yes, I can't think of any reason for it not to be
it hurts nothing (probably)
How about the library author not intending the main function to be run alongside other things
15:11
hm, fair enough
Why are any functions private if they can just say "don't call this"
next: should static be the keyword used for class methods? I don't really like it, but Python's @classmethod thing is too verbose (and janky anyway)
also, what should constructor syntax look like?
I like Vala's multi-constructor idea, but I feel like the syntax could be improved
first idea:
public class Main():
	constructor function():
		pass
	constructor function withFoobar():
		pass
doesn't feel right
public class Main():
	construct():
		pass
	construct withFoobar():
		pass
that feels a bit better
in Vala, extra constructors are called like class methods (Main.withFoobar()); I don't like this, so I think I'm going to do something like Main:withFoobar() for constructors and Main.classmethod() for class methods
although actually, do they have to be distinct?
it's not hard to make a class method that returns a new instance of the class
do I use new? because if I do I can re-use it for constructors
@Ginger koltin's
example?
it has a primary constructor, and secondary constructors that call the primary
lemme make a quick example
15:20
aight
class Complex/* primary constructor */(val re: Double, val im: Double) {
	/* secondary constructor */ constructor(re: Double) : this(re, 0) {}
}
@Ginger No constructors
the advantage is you see that val in the constructor? its boilerplate for creating a property and a parameter to set that property
@RydwolfPrograms huh?
Just have static functions that return an instance
Like Rust does
15:22
like Main.new()?
@RydwolfPrograms doesnt really work well in a traditional oop lang
Hmph, fine
As long as you don't have a new keyword
Anything but a new keyword
15:23
how are you supposed to construct it in the static method?
@Seggan hm, what if I want to call a function in the primary constructor? where does that go?
in a separate init block
hmmmmmmm
class Complex/* primary constructor */(val re: Double, val im: Double) {
	/* secondary constructor */ constructor(re: Double) : this(re, 0) {}

	// called by primary constructor
	init {
		whatever()
	}
}
im using this system for rol
15:25
I think I'm going to do this:
public class Main():
	construct():
		pass
	construct withFoobar():
		pass
Main()
Main:withFoobar()
Single colon?
Why not .
Or ::
:: is too chunky, . is for calling methods
Having a weird third property accessor for one specific case is just janky
@Ginger And...you're calling a method
A constructor is a method
I don't like how Vala doesn't differentiate between calling a constructor and calling a static method
I could just have static methods that work like constructors tho
@RydwolfPrograms lua go brrr
15:27
public class Main():
	construct():
		pass
	<static keyword> withFoobar() -> self:
		pass
Main()
Main.withFoobar()
No, still have the constructor keyword and write them like constructors, but use .
blugh no
'cause now your constructors are indistringuishable from methods syntactically, which is exactly what you didn't want
And you need some way to construct a self within your constructor functions
either no extra constructors or extra constructors that use :
and I like option 2
Oh wait so with the static constructors option there'd still be a single primary one?
15:29
@Ginger whats the parens after Main
@RydwolfPrograms yes
@Seggan they aren't required, but they work the same way as they do in Python
oh frick I missed an NHS meeting
@Ginger ugh
Got buried in my emails lol
I'm prolly getting kicked out anyway so I might as well just not go I guess
I didn't do any volunteer hours or service projects 'cause I thought they were the same thing and there weren't enough service project opportunities for me to do one
15:30
actually, should I do public class Foo(Bar) or public class Foo extends Bar?
class Foo : Bar
kotlin again
and please make public the default
what access is without a modifier?
private
@Ginger use kotlin-style nullable typing
@Ginger aaaaaaaaaa
please make public default
i have nightmares of writing public everywhere in java
15:35
@RydwolfPrograms I know you hate dunder methods, which is fair, so I'm going to avoid using them wherever possible
why do __init_subclass__() when you can do extends constructor()?
@Ginger howd you do that
@Seggan actually, I just realized that maybe making public the default is better, because private classes can only have private members
@Seggan magick™
@Ginger YES please
Rabbit will have infix methods, using the operator keyword, which will also be used for overriding mathematical operators
for example: override operator +()
the override keyword is required, to make sure you're actually doing what you intend
?
Oh wait nvm
But still override is unnecessary
It just wastes space and typing
You're making this so unnecessarily verbose
OOP is poison
It infects your brain
15:45
yeah, but that's just, like, your opinion, maaaaaaaan
@Ginger This would make sense if you need to inherit from some class to be able to do it
@mousetail oh, yeah
if you're not inheriting it's just operator
Then I'd say requireing override makes perfect sense
ok, here's Python dunder methods in Rabbit syntax:
__new__ -> class construct()
__init__ -> construct()
__del__ -> delete function <name>()
comparison and math -> operator <name>()
pretty much everything else -> interfaces
that's right, we're doing interfaces
@Ginger it will be the easy part. trust me, the hardest part will be the type checker (i speak from experience)
also dependency resolution will be very hard
15:58
delete seems odd. Why do you need function there?
opinion: no delete
I like delete, it eliminates the need for with statements if it's sufficiently reliable
@Ginger elegant, but i prefer rusts or javas way of doing it: implementing interfaces
@mousetail huh
how do delete and with go together
argh whats with my typing today
For example, closing a file when it's deleted
So you don't need to do with open()
0
Q: Shortest way to convert the result of a test to a string output (e.g. true or false) in bash

ShadowRangerI'm trying to shorten a bash solution to a Code Golf challenge, which requires an output of true or false. I've managed to condense the key piece of the code down to a substring check against the sole argument to the program, of the form: [[ FIXEDSTRING = *$1* ]]&&echo true||echo false My questi...

16:02
just make a close() method like java
Then it wouldn't run on error
Python has a close method too but it's recomended not to use it
it also closes on delete but since delete is not guarenteed to be called as soon as the reference counter reaches 0 it's considered too unrelaible
@mousetail in java it does
if u use try with resources
any brb gonna take a walk
try finally is even worse than with
even more verbose
> try with resources
Isn't that basically the same as a with statement?
16:29
hi
should interfaces be able to supply default methods?
@mousetail yeah
+ the same abilities as a normal try
@Ginger yes
@mousetail Isn't that like, purely a Python thing
Also who uses .open() directly in the 21st century
If Python makes you do that that's jank
@mousetail i'd argue with statements are more desirable than convenient explicit closes :P
What does a Python with statement do?
In JS they put all of the properties of an object in scope as variables
@RydwolfPrograms they work kinda like Rust lifetimes
16:42
@UnrelatedString The issue is if you want to share a object between different functions. Like a function that returns a open file.
I've made multiple mistakes where I use a with statement around something that actually should outlive the current function
@RydwolfPrograms if I do with open("data.txt") as file:, once execution of the with block finishes (or if an error occurs and execution ends early) the file object is closed
If you close it on drop it's guarenteed to be closed and it's guarenteed nobody will use it after close
it's very useful and I'll probably put it in Rabbit
Yeah I'd avoid any operator named with personally, since JS and Python seem to use it completely differently
16:44
speaking of: how should Rabbit do GC?
@RydwolfPrograms how about using? I'm doing import for imports
@Ginger What's a single case where it'd be useful other than for dealing with awful built-in filesystem stuff?
fwiw i feel like js's with is slightly more intuitive but yeah can also just be using
@RydwolfPrograms network connections, thread pools
1. An open file handle being dropped should close the file no matter what, this is 2023 people
2. You shouldn't need open() for anything but low level file stuff, and even then, rarely for that
anything that should be cleaned up once it's done being used
16:46
There are many things that need to be closed, like database connections, thread pools, transactions, etc.
@Ginger Why would that need a with
Just have it do that when the object is deleted from GC
@RydwolfPrograms What do you mean not use open? There is no alternative
If there's no alternative the language is bad
@mousetail ideally the variable would go out of scope and have some special prohibition against being returned :P
16:46
You should be able to just do something like fs.read_file("xyz") to get it as a bytestring or something
As is the case in Node, Rust, etc.
@RydwolfPrograms i think we have multiple ideas of what open is
you can use os, but only masochists do that
@RydwolfPrograms That could be a option but it's generally bad practice since it would load the entire file into memory
oh yeah being able to slurp a file all at once isn't a bad idea
2 mins ago, by Ginger
speaking of: how should Rabbit do GC?
16:47
only usable for very small files
...which 90% of files you need are
but quite useful for said small files :P
I'm thinking Rust-style lifetimes
@RydwolfPrograms which might not be in a while
And streams should exist too right?
16:48
python does let you treat the handle from open() as an iterable
@Ginger What happens if I don't use a with with something that needs to be closed?
@RydwolfPrograms Config files maybe
Does it silently create some sort of resource leak (very bad language design) or error (a sign you don't need with to be explicit at all)
Most files shouldn't be loaded into memory
@RydwolfPrograms usually Python closes it when the program ends or when the object gets GC'd, but that might be a while
16:49
@mousetail I can't think of a single situation where I've needed to read a file that wouldn't take up negligible amounts of RAM
so a silent resource leak
that I wouldn't've needed otherwise
@RydwolfPrograms Clearly you don't use enough XML
How little RAM do you have
16 GB but the programs I write should be usable for people with much less
16:50
i feel like incrementally reading is beneficial the moment you're even asking that question :P
The data I work with comes in 15 GB XML files
@RydwolfPrograms dealing with textures and gpu stuff needs closing too
Unless you're one of those 640 KB should be enough for anyone people, reading any file into RAM is probably a safe bet it's not gonna cause issues
I'm pretty sure the only >100 MB files I have are .isos and stuff
@RydwolfPrograms lol
@Ginger tracing GC
16:51
@Seggan huh?
oh
@mousetail That seems like an edge case, and having convenience doesn't come at the cost of being able to do things the old way
@RydwolfPrograms tars and zips :P
@RydwolfPrograms I think any sane program should avoid loading files into memory if remotely possible
Guess I'm insane then
You don't know how big they can get
16:52
A few megabytes here and there is nothing on any remotely modern machine
If this was the only program maybe
But there is a ton going on on a typical computer
I wonder what I should write the Rabbit interpreter in
Scala maybe d:
At my work we use servers with over 100 GB of ram that are constantly nearly full
A ton of things that use a megabyte here and there
Even cheap lil' laptops come with 4 GB nowadays
@RydwolfPrograms ever worked with video? :P
16:54
At 4 GB you can not afford to load files into memory
My RPi has 8GB of RAM
@mousetail I'm pretty sure I'll be fine reading a 500 byte config file
Yea config files are fine
I'm talking about opening a file provided by a end user
Or some data
Or a couple kilobytes of input, or whatever. That's what 90% of file I/O is, after all, right? Config files and shit
I'd support a convinience method for loading config files fast
But it shouldn't be the default
16:55
@Ginger kotlin or rust
Well I guess if your program's a utility for doing stuff to files that just happens to be something you can do line-by-line or byte-by-byte, sure. But that's not the default any more than just reading a file all at once
And there wouldn't be any "default" anyway, just a set of options
True
Maybe not default but "general recomendation"
@Ginger all modern interpreted langs do that
ast eval is too slow
@Ginger Rust, 100%
It's low level enough that you'll have a lot of control, but will keep nasty bugs out of your language
You don't want to be the next PHP
But you also don't want to be the next Python
@RydwolfPrograms sounds like it'll be hell to write, especially since I know very little Rust
and "learn rust by making a programming language in it" is maybe not a good idea
17:01
Y'know I think I'm going to start working on Cuprous
I think the world deserves a Rust that's easier to use
and then I'll implement Rabbit in it
Altho soon Complement will replace all existing programming languages so there's little point
fair enough
@RydwolfPrograms do it
One of my biggest complains with Rust is Arc<Mutex<...>>
As soon as there's more than a single thread I want to jump into a pit of spikes
17:08
type Easy<T> = Arc<Mutex<T>>
Barely helps
(I feel like I should be able to flag locked posts)
or, if it remains featured, could the title be changed?
17:23
@RydwolfPrograms And sometimes you need your own wrapper around an Arc<Mutex<...>> so that you can implement some trait for it
Example?
That seems kinda weird
I might've done it the wrong way, but I needed to pass a Read once and had to make a wrapper around an Arc<Mutex<Cursor<Vec<u8>>>> or something like that
Let me try to find it
That sounds like the wrong approach for sure
How do people usually do it?
The Cursor is Read right
17:25
Yeah
But the Arc<Mutex<...>> wasn't, hence the wrapper
You'd normally dereference the Arc<Mutex<...>> I think
But I don't know, maybe that is a situation where you'd need a wrapper
Wait do MutexGuards have the traits of the type they contain? Lemme check
Wait you can do &mut *thing I think
2
A: Calling method on Trait object behind Arc & Mutex

CalculatorYou are passing a reference to the MutexGuard to your runner instead of a reference to the wrapped runnable. You need to insert a deref: pub fn run<R>(&mut self, index: usize, mut runner: R) where R: FnMut(&mut Runnable), { let runnable_arc = self.runnables[index].clone(); let mut ru...

@RydwolfPrograms Looking at it again, the library's example uses a plain Vec instead of all that wrapped nonsense, so I guess I did overcomplicate it
17:43
idk if I should use Rust or not
The answer to that question is always yes
Until Cuprous exists
but, but, Kotlin!
LDQ: Is it worth distinguishing between fixed-size arrays and vectors syntax-wise?
The advantage of distinguishing between them is performance and low-level control, the advantage of not doing so is compactness since you can write a vector of strings as [String] instead of Vec<String>
Worth noting in many cases I could optimize it into a fixed size array
LDQ: print(pattern, ...stuff) vs. print("string" + stuff + "string" + stuff)
Basically should print take a string or a constant pattern and a list of things
@RydwolfPrograms no
dont have a distinction between them, syntax wise or not
How low-level is this language?
17:52
thats one thing i like about python/js: no distinctions between arrays and lists
if i really want it i just write an immutable list
or a fixed list
@Ginger YES
@RydwolfPrograms just add string interpolation
print("string${stuff}string${stuff}")
13 mins ago, by Ginger
but, but, Kotlin!
ok time for a minor ad break
brought to you by Seggan
Kotlin is really close to being the ideal language imo
it has nice OOP which is not overcomplicated (like i sometimes feel about rust)
operator overloading is real nice
infix functions are sometimes nice, but i could do without them
the lambda syntax is one of the best ive seen
native function types (in a static language!), receiver types, implicit arguments
@Seggan one thing: can Kotlin can be compiled to a native executable?
yes
please lemme finish typing
lol
the lambda syntax allows for really nice DSLs (check gradle), as well as allowing you to embed code in config files n stuff
the multiplatforming ability is awesome
im currently working on a web game, and both the frontend and backend are in kotlin
it also allows you to share code across platforms, so i dont have to do a ton of duplication
back to lambdas: you dont need to put parentheses around lambda args if its the last one
so as well as having syntax like list.map { it + 1 }, you can also make functions that look like inbuilt structures
i.e. with(obj) { code } is actually a stdlib function taking an obj and a lambda
receiver objects allow you to have an implicit this in lambdas
kotlin can target JS, JVM, iOS, Android, and can compile natively
one thing ii really love as well is extension functions
oh the nightmares of making tons of utility classes in java
now youve got extension methods
primary constructors are a really nice feature, as well as specifying fields in constructors allows you to remove a bunch of boilerplate
when statements are a souped up switch, with limited pattern matching
the absence of full blown rust style pattern matching is one of my main grievances with kotlin
nullable types are mwah
no more NPEs
the interop with java is the best in any jvm lang besides probably groovy
i commonly use java libs if i cant find a kotlin lib
its integration with gradle is the best
(gradle is another topic entirely)
the large amount of functional extension functions to collection types in the stdlib i love
no more Streams, no more for loops just for a map
</ad-break>
18:20
@Seggan it will happen someday, kotlin is still young
I can’t wait for that and contracts to get good
@Seggan well rust isn’t meant to do oop
That snippet ginger posted was cursed af
@Seggan idk about that baut o love the intellij support for it
I once converted a small codebase from java to kotlin during a school day
Intellij is that good
18:38
ok I'm going to do it in Kotlin
how tf does ANTLR work
18:58
ok this might take a bit of explaining
do you have intellij + gradle
0
Q: Compact my variables (and code)!

Infigon(Notice the differences from this post. Specifically, this references JavaScript, a programming langauge that happens to be one you can run on StackExchange. However, you may use any programming language to do this challege. An example of JS looks like this (try running all the snippets in here):...


« first day (4408 days earlier)      last day (734 days later) »