Named Params in Softanza

15 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Mansour Ayouni

belum dibaca,
15 Mei 2022, 14.25.1315/05/22
kepadaThe Ring Programming Language
Hello All,

As part of the EXPRESSIVENESS design goal in Softanza, named params can turn your code into a knowledgeable narration by your readers, and saves your time and energy in commenting and documenting it...

image.png

All the best,
Mansour

Mahmoud Fayed

belum dibaca,
15 Mei 2022, 22.20.2015/05/22
kepadaThe Ring Programming Language
Hello Mansour

The API for the ReplaceNextOccurrence() method looks interesting
You provided two versions of the parameters
The first version get String, Number & String ( i.e. "love", 5 , etc.)
The second version get List,List,List (i.e. :of = "love", :startingAt = 5, etc. )

Looks like a nice way to apply named parameters without the need to use [ ] inside the ( ) of the function call
but this suffer from two things
(1) You can't change the parameters order
(2) You can't add more parameters in the future without breaking the current code

So use this way only if you are sure that you will not change the parameters order and you will not need to add more parameters in the future (But are you sure that you know the future? IMHO, sometimes we can predict it correctly and sometimes we fail to do that)

In my projects I prefer accepting a List and write it like this   myfunction( [  :para1 = value1, :para2 = value2  ])
Yes there are extra [ ]  and I can't use the function without passing a List (i.e. can't write the values directly)
But this way is more flexible and support
(1) Changing the parameters order
(2) We can add more parameters in the future without breaking the current code
(3) Optional Parameters

Note: I like your way, I fell it teaches me something new about Ring, I just shared my ideas about this topic

Keep up the GREAT WORK :D

Greetings,
Mahmoud

Mansour Ayouni

belum dibaca,
16 Mei 2022, 06.08.5716/05/22
kepadaMahmoud Fayed, The Ring Programming Language
Hello Mahmoud,

What a nice discussion!

So use this way only if you are sure that you will not change the parameters order and you will not need to add more parameters in the future

In Softanza, the most natural order of params (in "natural" language sense) is proposed first. In fact, if you tell me:

Mansour, please take this string "love I love Ring love", and replace the next occurrence of "love", starting at Position 5, by the substring ""...

Then, I'll answer you with this Ring code:
? Q("love I love Ring love").ReplaceNextOccurrence(:Of = "love", :StartingAt = 5, :With = "♥")

It's exactly the literal translation of your natural language sentence to a Ring code sentence!

But are you sure that you know the future?

No, but what I'm betting on here is the own structure of natural language and how humans used to express their ideas in it, yesterday, now, and definitely in a long future to come!

In my projects I prefer accepting a List and write it like this   myfunction( [  :para1 = value1, :para2 = value2  ])

Yes! This is the most flexible way to provide programmers with a complete freedom on using params, without being constrained by the order we decided, as library designers, on behind of them!

Later on, when I'll talk about the FLEXIBILITY design goal in Softanza, you will see how I made it available (as a showcase only because it's a FUTURE feature) for those:
  • who do not want to fellow the basic order of functions,
  • or when they do not need to specify all the params,
  • or when they forgot them,
  • or when they want to use a function with its defaults without entering any param...
In a nutshell, I call this @FunctionFreeForm and it is used like this, for example:

? Q("I love Ring").SectionFF([]) #--> "I love Ring"

Note that the params are always hosted in a [] like you suggested. As you see, Softanza decided to give the value 1 to the first param and 11 to the second one, like if you have entered:

? Q("I love Ring").Section(8, 11) #--> "I love Ring"

Which is natural and expected since Softanza tells us: You wan to get a section of the string, you didn't provide me where to start and where to finish, so let's take all the string as a section!

This beeing said, please stay tuned and I'll tell you more about it in my next posts.

Best regards,
Mansour



--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/e1261e3b-79b6-4652-8b14-8ada6e2a702cn%40googlegroups.com.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru