There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

philomory , in More believable for a Linux OS

Wow, a Lain meme was not something I was expecting.

I should watch that show again sometime, I still have the DVDs somewhere I think.

xmunk ,

“And you don’t seem to understand…”

Tesla ,

A shame you seemed an honest man…

Z4rK , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

It’s really cool, but the example doesn’t produce any sensible output? If you have created something like this, why wouldn’t you have your demo output something sensible like Fibonacci or 1337 or whatever.

prof OP ,
@prof@infosec.pub avatar

Great idea if I have to extend it

neatchee ,

I’m opening an issue on your ticket tracker to add file i/o. Let the nightmare commence

ChubakPDP11 , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

People are designing languages with JetBrains MPS and I am making an AWK interpreter in C with Yacc, Lex and my own implementation of ASDL. Why do I do this to myself? It seems like the technology I like is way behind. Like C is a language created for freaking mini-computers like VAX and PDP-11 and I still use it? I knew about MPS, I just felt a strong dislike towards it. Now that I am no longer a pill addict, I have to reconsider the technology I choose to implement my stuff. C lacks portability, and QoL features.

(Psyche! All you n000bz can be stuck with your Fischer-Price toys — I’ll do it MY way, the 70s WAY!!!1)

MinekPo1 ,
@MinekPo1@lemmygrad.ml avatar

don’t worry , it can always get worse . source : I implemented a esoteric programming language of my own making with just a parser (no lexer !) and a tree walking interpreter while reimplementing a standard library and depending on undefined behavior in python . honestly I fear that code more each time I look at it

AMDIsOurLord ,

We think alike friend

Don’t lose your passion, doing things the shit old way can also make you a better programmer in the newer paradigms

Although, I recommend you at least learn C++23

einsteinx2 ,
@einsteinx2@programming.dev avatar

Reading this comment and then looking up and seeing that your username ends with PDP11 was chef’s kiss

Scoopta ,
@Scoopta@programming.dev avatar

I choose option C, eclipse xtext

joyjoy , in More believable for a Linux OS

You call that russian roulette? This is real russian roulette. Dying is a 1/6 probability.


<span style="font-style:italic;color:#969896;">#!/usr/bin/env python3
</span><span style="font-weight:bold;color:#a71d5d;">import </span><span style="color:#323232;">random
</span><span style="color:#323232;">
</span><span style="color:#323232;">barrel </span><span style="font-weight:bold;color:#a71d5d;">= </span><span style="color:#323232;">[</span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">0</span><span style="color:#323232;">, </span><span style="color:#0086b3;">1</span><span style="color:#323232;">]
</span><span style="color:#323232;">random.shuffle(barrel)
</span><span style="color:#323232;">
</span><span style="color:#62a35c;">print</span><span style="color:#323232;">(</span><span style="color:#183691;">"Russian Roulette"</span><span style="color:#323232;">)
</span><span style="font-weight:bold;color:#a71d5d;">for </span><span style="color:#323232;">i </span><span style="font-weight:bold;color:#a71d5d;">in </span><span style="color:#323232;">barrel:
</span><span style="color:#323232;">  </span><span style="color:#62a35c;">input</span><span style="color:#323232;">(</span><span style="color:#183691;">"Press enter to shoot"</span><span style="color:#323232;">)
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">if </span><span style="color:#323232;">i </span><span style="font-weight:bold;color:#a71d5d;">== </span><span style="color:#0086b3;">1</span><span style="color:#323232;">:
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">print</span><span style="color:#323232;">(</span><span style="color:#183691;">"You are dead."</span><span style="color:#323232;">)
</span><span style="color:#323232;">    exit()
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#a71d5d;">else</span><span style="color:#323232;">:
</span><span style="color:#323232;">    </span><span style="color:#62a35c;">print</span><span style="color:#323232;">(</span><span style="color:#183691;">"Phew. You survived."</span><span style="color:#323232;">)
</span>
librecat ,
@librecat@lemmy.basedcount.com avatar

I love this, except for i i hate i.

faintwhenfree ,

I like it, i for int easy to remember. I also use i, j, k as u it vectors and remember at what depth of a multidimentional array in working at.

saroh ,

And maybe the fact that you have to continue until the gun actually fires :|

bhamlin ,

You can quit control-c at any point. Sometimes, the game plays you.

problematicPanther ,
@problematicPanther@lemmy.world avatar

but it’s easier than thinking of a useful variable name.

kogasa ,
@kogasa@programming.dev avatar

bullet_idx

Iapar ,

Like bullet?

finestnothing ,

I always use i because I’m too lazy to type out iterator when I’m making my garbage spaghetti code that will support infrastructure for years

winky9827b ,

You forgot the switch.

mox , in More believable for a Linux OS

Perfectly safe on Windows, too. The remove() function doesn’t work on directories.

aodhsishaj ,

Remove-Item -LiteralPath "C:" -Force -Recurse

okamiueru ,

I’m curious. Does anyone like PowerShell, and the syntax you end up with?

OfficerBribe ,

I work pretty frequently with PS and have no issues with syntax. It’s easy to read and you always have autocomplete so there is just 1 extra click to get from -r to -Recurse. Same command could be also written as this due to alias feature.

rm 'C:' -r -fo

It’s just not the best practice since in PowerShell it is recommended to not use aliases for readability reasons. Also less chance to mess things up due to how verbose all commands and their parameters are.

okamiueru ,

Thanks for the info! Is a correct assumption that this is a “yes”, to my question?

OfficerBribe ,

It is. Besides some very niche bugs everything in the core of PowerShell seems logical to me and easy to understand.

egonallanon ,

Yeah I’m a big fan of it. People complain about the verbosity of it but I like that for readability and autocomplete makes that a non issue I find. Plus if you really want to save on typing when using it as a terminal tool you can just make aliases for all your common commands.

okamiueru ,

No complaints from me. Maybe if I had to use it. The thing that strikes me as particularly noisy is what seems to be either case insensitive commands and flags, or case sensitive and using Pascal-Case for both commands and flags. Which would be my least preferred option.

AnyOldName3 ,
@AnyOldName3@lemmy.world avatar

Commands and flags (for native powershell commands) are case insensitive, but the autocomplete both in the shell and text editors is really good, so people typically use it and have it tidy up whatever they’ve written to match the canonical case.

AnyOldName3 ,
@AnyOldName3@lemmy.world avatar

Powershell isn’t perfect, but I like it a lot more than anything that takes sh as a major influence or thing to maintain backwards compatibility with. I don’t think the Unix philosophy of having lots of small tools that do one thing and do it well that you compose together has ever been achieved as I think being consistent with other tools you use at the same time should be part of doing your thing well, and things like sed, grep and perl all having different regular expression syntax demonstrate inconsistency and are easy to find. I also like that powershell is so verbose as it makes it much easier to read someone else’s script without knowing much powershell, and doesn’t end up getting in the way of actually writing powershell as the autocomplete is really good. I like having a type system and structured data, too.

Some of these things are brought to a unixier shell with nushell, but I’m not convinced it’ll take off. Even if people use it, it’ll be a long while before you Google a problem and the solution also includes a nushell snippet, whereas for any Windows problem, you’ll typically get a GUI solution and a powershell solution, and only a maniac would give a CMD solution.

okamiueru , (edited )

I don’t think the Unix philosophy of having lots of small tools that do one thing and do it well that you compose together has ever been achieved

Why do you think this might be the case? It’s not remotely accurate, which suggests that you must understand it very differently than I do. To some extent, I am curious.

I’ll give you a recent example. Which is just from yesterday. I had a use case where some program had a memory leak, which would eventually lead to the system running out. So, I “built a program that would monitor this and kill the process that used the most memory”. I don’t know how complicated this is in windows and PS, but it took about 2 minutes in Linux, and it very much leverages the Unix philosophy.

Looks something like this:


<span style="color:#323232;">get_current_available_memory_mb() {
</span><span style="color:#323232;">    cat /proc/meminfo | grep MemAvailable | grep -oP 'd*' | xargs printf "%d / 1024  n" | bc
</span><span style="color:#323232;">}
</span>

Functionality based on putting together very small pieces that do their things well.

  • /proc/meminfo is a file pipe that gives you access to information related to memory usage.
  • cat just outputs data from a file or a named pipe, here the latter
  • grep lets you filter stuff. First time the relevant line. Then again to strip out the number with a regex.
  • xargs does one thing well, and lets you pass that on to another command as arguments, instead of stdin.
  • printf formats the output, here to express the numerical operation of dividing the value by 1024 as "[number] / 1024"
  • bc evaluates simple mathematical operations expressed in text

Result: 1 file pipe and 5 simple utilities, and you get the relevant data.

The PID of the process using the most memory you can get with something like:


<span style="color:#323232;">ps aux --sort=-%mem | head -n2 | tail -n1 | awk '{print $2}'
</span>

Same sort of breakdown: ps gives you access to process information, and handles sorting by memory usage. head -n2 just keeps the first two lines, but the first one is a header so tail -n1 keeps the second line. awk is used here to only output the second column value. And, you get the relevant data. Also, with simple tools that leverage the Unix philosophy.

You then check if the available memory is below some threshold, and send a kill signal to the process if it does. The Unix way of thinking also stops you from adding the infinite loop in the script. You simply stop at making it do that one thing. That is, 1. check remaining memory. 2. if lower than X, kill PID". Let’s call this “foo.sh”.

You get the “monitoring” aspect by just calling it with watch. Something like watch -n 2 – ./foo.sh.

And there you go. Every two seconds, it checks available free memory, and saves my system from freezing up. It took me 10 times longer to write this reply, than to write the initial script.

If memory serves me correctly, PS also supports piping, so I would assume you could do similar things. Would be weird not to, given how powerful it is.

I could give you an endless list of examples. This isn’t so much a case of “has ever been achieved”, but… a fundamental concept, in use, all the time, by at least a dozen people. A dozen!

Also yesterday, or it might have been Saturday. To give you another example, I scratched different itch by setting up a script that monitors the clipboard for changes, if it changes, and now matches a YouTube URL, it opens that URL in FreeTube. So… with that running, I can copy a YouTube URL, from anywhere, and that program will immediately pop up and play the video. That too, took about 2 minutes to do, and was also built using simple tools that do one thing, and one thing well. If you wanted it to also keep a local copy of that video somewhere, it wouldn’t be more effort than the 10 seconds it takes to also send that URL to yt-dlp. One tool, that does that one thing well. Want to also notify you when that download is complete? Just add a line with notify-send “Done with the thing”. What about the first example, if you want to get a OS level notification that it killed the process? Just add a line to notify-send, same tool that does that same one thing well.

None of this takes much effort once you get into it, because the basic tools are all the same, and they don’t change much. The whole workflow is also extremely iterative. In the first example, you just cat meminfo. Then you read it, and identify the relevant line, so you add grep to filter out that line, and run the command again. It’s now a line containing the value, so you add another grep to filter it out the number, and again, run it. “Checks out”. So, you pipe that to printf, and you run it. If you fuck something up, no biggie, you just change it and run it again until that little step matches your expectations, and you move on.

AnyOldName3 ,
@AnyOldName3@lemmy.world avatar

I think you’ve misunderstood my complaint. I know how you go about composing things in a Unix shell. Within your post, you’ve mentioned several distinct languages:

  • sh (I don’t see any Bash-specific extensions here)
  • Perl-compatible regular expressions, via grep -P
  • printf expressions
  • GNU ps’s format expressions
  • awk

That’s quite a lot of languages for such a simple task, and there’s nothing forcing any consistency between them. Indeed, awk specifically avoids being like sh because it wants to be good at the things you use awk for. I don’t personally consider something to be doing its job well if it’s going to be wildly different from the things it’s supposed to be used with, though (which is where the disagreement comes from - the people designing Unix thought of it as a benefit). It’s important to remember that the people designing Unix were very clever and were designing it for other very clever people, but also under conditions where if they hit a confusing awk script, they could just yell Brian, and have the inventor of awk walk over to their desk and explain it. On the other hand, it’s a lot of stuff for a regular person to have in their head at once, and it’s not particularly easy to discover or learn about in the first place, especially if you’re just reading a script someone else has written that uses utilities you’ve not encountered before. If a general-purpose programming language had completely different conventions in different parts of its standard library, it’d be rightly criticised for it, and the Unix shell experience isn’t a completely un-analogous entity.

So, I wouldn’t consider the various tools you used that don’t behave like the other tools you used to be doing their job well, as I’d say that’s a reasonable requirement for something to be doing its job well.

On the other hand, PowerShell can do all of this without needing to call into any external tools while using a single language designed to be consistent with itself. You’ve actually managed to land on what I’d consider a pretty bad case for PowerShell as instead of using an obvious command like Get-ComputerInfo, you need:


<span style="color:#323232;">(Get-WmiObject Win32_ComputerSystem).FreePhysicalMemory / 1024
</span>

Even so, you can tell at a glance that it’s getting the computer system, accessing it’s free physical memory, and dividing the number by 1024.

To get the process ID with the largest working set, you’d use something like


<span style="color:#323232;">(Get-Process | Sort-Object WorkingSet | Select-Object -Last 1).Id
</span><span style="color:#323232;"># or
</span><span style="color:#323232;">(Get-Process | Sort-Object WorkingSet)[-1].Id
</span>

I’m assuming either your ps is different to mine, or you’ve got a typo, as mine gives the parent process ID as the second column, not the process’ own ID, which is a good demonstration of the benefits of structured data in a shell - you don’t need sed/awk/grep incantations to extract the data you need, and don’t need to learn the right output flag for each program to get JSON output and pipe it to jq.

There’s not a PowerShell builtin that does the same job as watch, but it’s not a standard POSIX tool, so I’m not going to consider it cheating if I don’t bother implementing it for this post.

So overall, there’s still the same concept of composing something to do a specific task out of parts, and the way you need to think about it isn’t wildly different, but:

  • PowerShell sees its jurisdiction as being much larger than Bash does, so a lot of ancillary tools are unnecessary as they’re part of the one thing it aims to do well.
  • Because PowerShell is one thing, it’s got a pretty consistent design between different functions, so each one’s better at its job as you don’t need to know as much about it the first time you see it in order to make it work.
  • The verbosity of naming means you can understand what something is at first glace, and can discover it easily if you need it but don’t know what it’s called - Select-String does what it says on the tin. grep only does what it says on the tin if you already know it’s global regular expression print.
  • Structured data is easier to move between commands and extract information from.

Specifically regarding the Unix philosophy, it’s really just the first two bullet points that are relevant - a different definition of thing is used, and consistency is a part of doing a job well.

Matriks404 ,

And Windows nowadays have like dozen of different security measures that stop you from removing critical system components. It is not like in Windows 95 days, that OS allowed you to remove kernel by just typing a single command.

bhamlin ,

And much like Windows, everything dangerous is done better elsewhere.

bjorney , in More believable for a Linux OS

OSError: File or directory not found “C:WindowsSystem32”

mox , (edited )

Nope. From the spec:

“Unlike Standard C, all unrecognized escape sequences are left in the string unchanged, i.e., the backslash is left in the result.”

Ephera ,

This behavior is useful when debugging: if an escape sequence is mistyped, the resulting output is more easily recognized as broken.

Wow, this sentence really threw me for a moment. I had no idea how other programming languages behave.

…which makes sense, because they don’t. The compiler just tells you to fuck off and that’s the end of that story. I guess, they can’t do that in Python…

bjorney ,

Python 3.12’s compiler tells you to fuck off

Ephera ,

Ah, neat.

onion , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS
MajorHavoc , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

It’s so beautiful!

Now I’m thinking about how to alias “flex X on the haters” into other development environments…

brunofin , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

Is flex X on the haters a way of logging to console?

prof OP ,
@prof@infosec.pub avatar

Yes, it pretty much just wraps the expression in a “System.out.println(<expression>);”

Aatube ,
@Aatube@kbin.social avatar

Maybe "flex X" outputs to stdout and "flex X on the haters" outputs to stderr?

prof OP ,
@prof@infosec.pub avatar

I like the way you think! 😂

mwguy ,

flex X on the fools does verbose logs only.

brunofin ,

I’m curious to know how your language throws and catches errors :)

pivot_root , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

Does it compile into JVM bytecode or Java source code?

JVM bytecode is one of the most infuriating IRs I ever had the displeasure to work with, and if you managed to make a compiler for that, I applaud you.

prof OP ,
@prof@infosec.pub avatar

Fortunately I generate Java source code from it. However MPS generates both source and byte code when you build the solution. For some reason I can’t get the byte code to run though, but the source code does, so I don’t care too much.

pivot_root ,

That sounds about right for JVM bytecode… In any case, great work!

WarmSoda , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

No cap is cracking me up. This is great stuff

blotz , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS
@blotz@lemmy.world avatar

Oh metaprogramming! I’m doing a dissertation on this.

prof OP ,
@prof@infosec.pub avatar

Very cool, I’d be interested in your publications once you’re done. I like metaprogramming, but once you realise you might have needed it, you’re already knee deep in fresh legacy code.

blotz ,
@blotz@lemmy.world avatar

You essential have a compiler written through metaprogramming. For your implementation, did you use a find and replace or did you define and parse a grammar like a true compiler.

prof OP ,
@prof@infosec.pub avatar

MPS uses projectional editing. Which means for the user that everything you do is free from concrete syntax, and you basically edit a graphical representation of that abstract syntax tree directly, while it looks like you’re in a textual editor.

So I define abstract nodes that may have certain relationships with each other and then give them a representation in the editor (which is what you see in the screenshot). These nodes may also have generators assigned to them, which use map/reduce operations to generate whatever source code I desire. It usually includes its own bit of code, and triggers code generation of its children as well.

I hope that was somehow clear 😄

AceFuzzLord , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

That’s cool but also makes me cringe.

superduperenigma , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

Looks like you’ve got a bug in there.


<span style="color:#323232;">if false no cap
</span><span style="color:#323232;">    canYouSeeMe = false
</span><span style="color:#323232;">if cap
</span><span style="color:#323232;">    canYouSeeMe = true
</span><span style="color:#323232;">sheesh
</span>

Won’t this always go into the else/cap condition since the if condition is checking to see that false == true?

prof OP ,
@prof@infosec.pub avatar

You’re correct, but it doesn’t really matter for demo purposes. In an actual use case (whatever that would be for this language) you would of course want to use some kind of variable or expression there instead of a constant.

shiveyarbles , in I had to design a simple general purpose language for university, so I tried creating "ZoomerScript" with Jetbrains MPS

Are you fo sho?

Yep

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines