Subscribe to The Madman Scribblings        RSS Feed
-----

English-ising Code

Icon 5 Comments
English-ising Code

OK you don't need to be illiterate to see that VB.net is a Programming Language, that isn't shy about it verbosity of word. So I thought let's go crazy and see how close to Written English I can make it.

So I started with simple task. English-ify the follow.
Dim value = 3
Dim lower = 0
Dim upper = 10
Dim result = ""
If lower <= value AndAlso value <= upper Then
  result = "Yes"
Else
  result = "No"
End If



What you really want to do is say Is value between lower and upper?

If value.IsBetween(lower).And(upper) Then 
  result = "Yes"
Else
  result = "No"
End If





Example 2: IsEqualTo
   If (value).IsEqualTo(lower).Or(upper) Then Console.WriteLine("Yes")






To see how this English-fication was/is created, pop over to my GitHub Repo: Englishify
NuGet: Englishify

Future
I've got a working implementation that Englishify numbers, via the digits.
Dim i As Integer = Number.Negative.One.Two.Three ' i <- -123 '
It current restricted to Integer Values only, it eventually will have floating point numbers as well (Double).
Some version in the future will enable you express numbers like Dim i2 As Integer = Number.One.Hundred.And.Twenty.Three.

5 Comments On This Entry

Page 1 of 1

37Liion Icon

07 May 2012 - 12:06 PM
I don't mean to come off as extremely pessimistic.. but this is gross.

value.IsBetween(lower).And(upper)


We're writing for the computer and each other, not for our grade school English teachers.

At best create a helper method/macro:
(value).IsBetween(lower,upper)
// or
IsOrdered(lower, value, upper)



Until code dictation becomes the norm, I don't see much use creating a vague .And(integer) method, or an IsBetween(integer) method that takes one argument.
0

AdamSpeight2008 Icon

07 May 2012 - 02:37 PM

37Liion said:

We're writing for the computer and each other, not for our grade school English teacher

Did you read the post fully?

Quote

So I thought let's go crazy and see how close to Written English I can make it.

That's the whole point, make it (vb.net) read as much like English as possible.

Source Code is for humans to read, not computers.

37Liion said:

At best create a helper method/macro:

It's an extension method that appears on any type, not just integer. If look at the code example it's also use on a String as well.

Or you're want more coding style examples
Snippet 1
Snippet 2
0

AdamSpeight2008 Icon

07 May 2012 - 02:47 PM
The .And method is not vague

For example
You don't say
If Zero is Less Or Equal to value And Also value is Less or Equal to Ten Then


when you want to say

If value Is Between Zero and Nine 


In Englishified Code this would be

If value.IsBetween(0)
(Inclusive is the Default)
now if do . you get access to the .Add method.
0

37Liion Icon

07 May 2012 - 04:12 PM

AdamSpeight2008, on 07 May 2012 - 02:47 PM, said:

The .And method is not vague

For example
You don't say
If Zero is Less Or Equal to value And Also value is Less or Equal to Ten Then


when you want to say

If value Is Between Zero and Nine 


In Englishified Code this would be

If value.IsBetween(0)
(Inclusive is the Default)
now if do . you get access to the .Add method.


Inclusive is the Default what?

What happens when you don't append .And(value) to .IsBetween(value)?
Is what you mean to say is that .And(0) is implicitly default?

What is the return type of IsBetween that .And can be called on?
Where is IsBetween implemented?

I understand that it was just a brainstorm and not a fully fleshed out idea.
And I don't mean to attack you.
Its just that particular line is an eyesore in my opinion.

I suppose one more niche could be filled as such: value.IsBetween(lower.And(upper)) such that the result of lower.And(upper)) is two a argument tuple of sorts..
0

AdamSpeight2008 Icon

07 May 2012 - 06:13 PM
You want to see how it's implementd the look at the source-code. The original post includes a link.

Quote

What happens when you don't append .And(value)

You get a compile-time error because the type used can't be cast to a Boolean.

Quote

Inclusive is the Default what?

Inclusive is the default form of Inclusiveness used by methods.
The four possible variations being
lower <  value <  upper (Exclusive Lower Bound, Exclusive Upper Bound)
lower <  value <= upper (Exclusive Lower Bound, Inclusive Upper Bound)
lower <= value <  upper (Inclusive Lower Bound, Exclusive Upper Bound)
lower <= value <= upper (Inclusive Lower Bound, Inclusive Upper Bound)



Quote

I suppose one more niche could be filled as such: value.IsBetween(lower.And(upper))

I don't your version because as a side-effect of the implementation .And will be available on any type that implements IComparable(Of T)

My implementation doesn't suffer from that, plus it has been implemented so you can write the following.

value.IsBetween(0,Exclusive).And(10) 
The second listed on the list of Inclusiveness above.


Quote

I understand that it was just a brainstorm and not a fully fleshed out idea.
And I don't mean to attack you.
Its just that particular line is an eyesore in my opinion.

You'd set a better impression, if you provided working source-code implementation of your "improved" API.
0
Page 1 of 1

Search My Blog

Recent Entries

Recent Comments