It’s a bear dance!
It’s a bear dance!
Unfortunately, “sauron [command]
” still won’t see the Jia Tan backdoor obscured in the shadows, nor the_ring.yml
that you’re piping to /dev/null
Imagine being so disliked that it becomes the goal of elderly voters to live long enough to vote against you, nevermind that it’s a former president
I find real-world examples help grasp concepts for me. I’ll use an example like a video platform (like Youtube) as an example for this:
One-to-one: for each one User, you maybe only allow one [content] Channel (or, could be one-or-none, meaning a User may have one Channel, or may use use their User account to be a viewer and have no Channel. You might decide to change this later to be one-to-many, but for the example let’s say you don’t). All the data could be stored just on the User entity, but maybe you decided to separate it into two tables so you don’t need to query the User entity which has sensitive info like a password, email, or physical address, when you just need a Channel. For each Channel, there is a foreign key pointing to the (owning_)user_id, and this is “unique”, so no duplicate id’s can exist in this column.
One-to-many (or Many-to-one): for each one Channel, there may be many Videos. You could use a relational table (channel_x_video), but this isn’t necessary. You can just store the (owning_)channel_id on the Video, and it will not be unique like the prior example, since a Channel will have many Videos, and many Videos belong to one Channel. The only real difference between “one-to-many” and “many-to-one” is semantic - the direction you look at it.
Many-to-many: many Users will watch many Videos. Maybe for saving whether a Video was watched by a User, you store it on a table (by the way, this example might not be the best example, but I was struggling to find a good example for many-to-many to fit the theme). Although each video-to-user relation may be one-to-one, many Videos will be watched by one User, and many Users will watch one Video. This would be not possible to store on both the Video or the User tables, so you will need a relational table (video_x_user, or include “watched” in the table name for clarity of purpose). The id column of each row is irrelevant, but each entry will need to store the video_id and the user_id (and neither will be unique), as well as maybe the percent watched as a float, the datetime it was watched, etc. Many-to-many relationships get very complicated often, so should be used carefully, especially when duplicate combinations of a_x_b can occur (here, we shouldn’t store a new row when a user watches a video a second time)
That’s how languages should all work?
While I agree, should be is not is. Also, Javascript is still a widely used and favored language, despite it’s flaws.
Sometimes people need to be convinced that there’s something better, hence all the articles of “Javascript devs discovering actual typing”, as you mentioned. Although it seems like the author already knew there’s better (I see Typescript and Rust on their Github), that they were just sharing Gleam.
As for specifically Gleam, I will say it’s a very nice language. Very simple to understand (with one minor exception: I personally find the use
keyword is a bit odd), strong typing, no collections of mysterious symbols (cough, Haskell), no metaprogramming, no lifetimes, no borrowing, no unclear polymorphism, no pointers, no nonsense. I like it, and am excited to see it grow
To be fair, all three can probably do what you’re asking for, in building a desktop application. So the real question comes as which flavor of language do you want to write. The only language of the three I can’t speak on is Ruby, as I haven’t used it.
Python is a “scripting language”, but by that token technically so is Javascript. It’s an immensely popular language due to its simple syntax, yet complex features as you get better with it. Python can build large-ish applications: web apps, desktop apps, terminal apps, and yes also of course AI, bulk data processing, etc. For GUI applications, I’ve personally used pyqt (4? 5? 6?)
Much of the same can be said for Javascript. As you said, there are “negative opinions” about JS, but everyone has their opinions (most factually-based) on the goods and bads of languages (although, yes, JS does get more negative opinions than others). Yet, Javascript is still a widely used language, and you’ll probably end up needing learning it anyway if you decide to go into web development.
What I personally suggest is this:
When the enum reaches your JSON, it will have to be a string (as JSON does not have a dedicated “enum” type). But it at least ensures that languages parsing your JSON will should have a consistent set of strings to read.
Consider this small bit of Elm code (which you may not be an Elm dev, and thats okay, but it’s the concept that you should look to get):
-- A Directions "enum" type with four options:
-- North, East, South, West
type Directions
= North
| East
| South
| West
-- How to turn each Directions into a String
-- Which can then be encoded in JSON
directionsToString : Directions -> String
directionsToString direction =
case direction of
North -> "north"
East -> "east"
South -> "south"
West -> "west"
-- "Maybe Directions" since not all strings can be parsed as a Directions.
-- The return will be "Just <something>" or "Nothing"
directionsFromString : String -> Maybe Directions
directionsFromString dirString =
case dirString of
"north" -> Just North
"east" -> Just East
"south" -> Just South
"west" -> Just West
_ -> Nothing
The two functions (directionsFromString and directionsToString) are ready to be used as part of JSON handling, to read a String from a key and turn it into a Directions enum member, or to turn a Directions to a String and insert the string to a key’s value
But all that aside, for your restructuring, and keeping with the license plate example, both type and license number could be contained in a small object. For example:
{
...
"licensePlate": {
"type": "government" <- an enum in the language parsing this
but a string in JSON
"plateNumber": "ABC123"
...
}
...
}
If its something that represents mutually exclusive states, like the license plates examples (Gov’t, Embassy, Learner), an enum like 4wd mentioned is a better idea than many boolean keys. This would also be the switch/case question you posed. For a “regular case”, I would include that in the enum, but if you create an enum that only contains “special cases”, you can always set it to null.
On the case of booleans, I would suggest avoiding them unless it is necessary, and truly a binary (as in, two-option, not binary numbers), self-contained-in-one-key thing (obligatory anti-boolean video). If the use case is to say what a different key’s object represents, you don’t need it (see: enums. You’ll thank yourself later if you add a third option). If the use case for using it is saying another key contains value(s), you don’t need it. Many languages can handle the idea of “data is present, or not present” (either with “truthy/falsey” behavior interpreting “data-or-null”, or “Maybe/Option” types), so often “data-or-null” can suffice instead of booleans.
I would suggest trying to always include all keys of a present object, even if it’s value is null or not applicable. It will prevent headaches later when code might try to access that key, but it isn’t present. This approach might also help you decide to reduce the quantity of keys, if they could be consolidated (as in taking booleans and converting to a state-like enum, as mentioned above), or removed (if unused and/or deprecated).
You can feign immutablility on class attributes by playing with __setattr__
. I don’t remember the exact way to do it, but its roughly like this:
class YourClass:
def __setattr__(self, name, value):
if not hasattr(self, name):
super().__setattr__(name, value)
else:
# handle as you wish if the
# attr/value already exists.
# pass, raise, whatever
I say “feign immutability” because there are still cases in which an attr value can change, such as:
I was using VSCode prior. VSCode works, sure, I just like the layout and flow of how I have Zed configured at the moment.
Also, preferably less Microsoft in my everything
Which plugins? I dont really care about many of them. Does the editor type my funny robot words and help me make sure the words I typed made sense for the language (aka, language servers)? Yes? Good.
Neat. I use Zed at work, but now also having it on my personal desktop will be nice. Bye, VSCode.
On my system, just one note that it didn’t render a menu bar. Not that I use it much anyway, just had to find the default keybind to open the keybinds config (btw: ctrl K |> ctrl S) and pasted what I used from work (then bulk-replaced all cmd’s with ctrl’s)
Theme change was not sticking on first launch, but second launch I guess it realized “Oh, I’m supposed to be this color now. Got it”. Ligatures don’t do, but it is a preview and that’s just an aesthetic.
Materials:
Coal and emeralds are usually higher up in caves, where stone is (emeralds much less apparent, best obtained through trading with villagers), and are rarer the further down you go. Iron, copper, and lapis lazuli are found almost throughout all height levels of cave. Gold, diamond, and redstone usually start around where stone-meets-deepslate, and further down. Ancient Debris is only in the Nether, and far down in the layers of netherrack.
Some non-ore materials, like bamboo, dripstone, moss, amethyst, coral, prismarine, etc., just require exploring the right biome to find them.
“Templates” are usually in chests of points-of-interests (below).
Points of Interest:
Really the best way to find most of these are just exploring. If your world is oceanic, consider a boat or boat-with-chest. If the world is continental, maybe consider a horse/donkey/mule/camel (if you stumble across a saddle).
Some PoI’s are common-ish enough where you’ll probably find at least one just by exploring, or exporing the right biome. Shipwrecks and underwater ruins in the oceans, pyramids in the desert, villages and incomplete nether portals in most biomes. These you just have to stumble across them, and you’ll know when you see them.
Some PoI’s are very hidden, and really require luck and time to find, like “old-style” dungeon spawners, Ancient Cities, Trail Ruins. Trail Ruins in particular, you can spot them from the surface if you notice the terracotta and/or suspicious gravel (which looks like gravel at a glance, but it may be out-of-place next to dirt/grass), but they’re pretty rare to find. Ancient Cities are always in the Deep Dark, but requires a lot of digging/wandering around blindly to find due to the rarity. The old dungeon spawners are very obvious if you stumble across them, it just looks like a cobblestone cube with mossy-cobblestone mixed into the floor, and the spawner cage in the middle. Nether fortresses look like bridges and buildings of dark-red netherbricks. Piglin Bastions are giant towers of blackstone (plain, bricks, etc), with some guilded blackstone scattered in.
Strongholds, can be found with Eyes of Ender (obtained later in the game, after killing Blazes and Enderman for their Blaze Rods and Ender Pearls respectively).
Some, like Woodland Mansions, Ocean Monuments, and Trial Chambers (in 1.21) can be found by leveling up a Cartographer villager and purchasing the corresponding map from them.
Elm
In short, it’s ruined my expectations of languages. It’s a functional language, like the style of Haskell, and transpiles to html or js (its meant for web). There’s very little that it allows for going wrong, and for things that could fail, it either tells you to port that out to JS and bring it back when you’re done, or you have to handle a Result type or Maybe type.
It sounds strict, yes, but not having to deal with issues later is so nice.
Also, I take issue with the claim that OOP is all about “objects”. It’s also about classes.
Depending on the language, classes are just objects too. So its still just about objects.
Hello world should look something like this:
print("Hello, World"!)
You don’t need the annotation line in Haskell-esque languages, most of the time. Without the annotation, this is Hello World in Haskell:
main = print "Hello, World!"
And when you need more complexity, it can still be far simpler than Unison (or Haskell)
import qualified Data.List as List
import Data.Function ((&))
processNumbers numbers =
let
isEven n = mod n 2 == 0
in
numbers
& List.filter isEven
& List.map (^2)
main =
processNumbers [1, 2, 3, 4, 5, 6]
& print
i starts at 0, checks if i is less than n (the first time it will be, no matter what), prints a “#”, then increments i by 1 and loops
Why does the for loop repeat after it exits to print a new line? If it exits the loop, shouldn’t it be done with it?
There’s the new line after the for loop to make sure that the next recursion starts on a fresh line. Otherwise the next recursion would print on the same line, right where it left off, and you’d just have a line of “#”'s. The for loop itself is just for printing “#”'s.
Why is n incremented and not i as stated with i++?
I think this is a confusion with the recursion. Look at the line with draw(n - 1);
this happens before any printing of hashes happens, and only continues after its done. And it calls itself as long as it’s not less than or equal to 0. To psuedo-code the order of operations here:
draw 3 {
draw 2 {
draw 1 {
draw 0 {};
print "#" * 1;
};
print "#" * 2;
};
print "#" *3;
};
so n is never incremented as you think, it just calls decremented versions of the draw function before the current one finishes. The i’s are purely involved in the for loop, which only prints hashes. Does that make sense?
Although, i would agree with it not necessarily being “friendly”, since its a drastically different syntax than many beginners would be used to, the brackets and parenthesis here are not what you think they are.
Unison is a language in the style of Haskell, F#, Purescript, Elm, etc. So that first line is actually type annotations.
In Haskell, this would just be helloWorld :: IO ()
, meaning a function named “helloWorld” with no arguments and produces what is essentally a potentially-unsafe IO action with a Void return (the empty parenthesis () ).
Here in Unison they call the bracket part “abilities” or something. Its saying the same thing as Haskell, but being more explicit in saying it can raise an exception.
Cool. Cool cool cool