18 December 2009

The logical-complement operator !

Maybe I'm weird but I really do not like syntax for this operator.

Now time it's like:

if (!person.getThinkingModel().isThinking()){...}

I would personally prefer:

if (person.getThinkingModel().!isThinking()){...}

I would do same about instanceof to allow:

if (obj !instanceof Person){...}

Work around:
Would be nice to see both methods generated isThinking() as well as isNotThinking() instead of one in that case. Problem in this solutions involve setters which should be duplicated as well, and mostly 'Not' version should call traditional with simple negation, which increases stack traces.

if (person.getThinkingModel().isNotThinking()){...}

This way have one more advantage. When you write in more than one language you can worry less about operators priority.

Use yours own judgement, which is easier to read and write.

15 October 2009

Little confusion about Generics

Lets consider some class used for collecting References. It requires little work but there is way to do not determine Reference type to early. So lets observe consequences of this action.

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Collects {@link Reference}-s
 */
public class ReferenceCollector<Ref extends Reference</* ? extends */ Type>, Type>
    implements Iterable<Reference<? extends Type>> { ... }

This class will allow given code to compile:

ReferenceCollector<WeakReference<String>, ?> rc1 = null;
ReferenceCollector<WeakReference<String>, ? extends Object> rc2 = null;

On the other hand reversing Type arguments will be not allowed:

ReferenceCollector<WeakReference<? extends Object>, String> rc2 = null;

This mean that nesting is count more then arguments order, what more it's all about compatibility not as I would expect equality of types. Probably I just need read rest of JLS when I'll have free time to get idea why '?' is allowed as second generic argument.

4 October 2009

I just killed Eclipse

I like enum-s more than most people do.

They are really nice to use and synchronization-safe. But as I found, they have their limits as well.

After generating 1,8Mb Java code for one enum Eclipse dying after most try of refactorization ;), Java was not happy at all about it as well with error:

The code for the static initializer is exceeding the 65535 bytes limit

30 March 2009

Enhanced while statement proposal

OVERVIEW

FEATURE SUMMARY:
Enhanced while statement allow to iterate through iterator.

MAJOR ADVANTAGE:
People will stop working around for-each loop.

MAJOR BENEFIT(s):
Allow to easy express operation on iterator(s), and iterating over non linear Iterators.

MAJOR DISADVANTAGE:
Automatic loop over Iterator my be problem for some peoples.

ALTERNATIVES:
Using while loop.

27 March 2009

'forget' keyword proposal

OVERVIEW

FEATURE SUMMARY:
'forget' keyword allows to erase variable from current context, or it means that field should not be used.

MAJOR ADVANTAGE:
This change makes language be more WYSIWYG.

MAJOR BENEFIT(s):

  • It makes people be able to erase 'variable' from current context, while now it's:
    • impossible for final variables (only by comments),
    • impossible for arguments (for not final Object we can assign null),
    • impossible for fields.
    • local fields need more or 'less' artificial blocks (two lines wasted and one indent level).
  • Declaring that variable should not be used, or does not contain valid information for this scope (at current time) will be possible.
  • Code quality does not fall so drastically after we leave it, comparing to '=null', 'only comments' or 'weird blocks'.

MAJOR DISADVANTAGE:
New keyword == Someone can have declared method/field/variable named 'forget'.

ALTERNATIVES:
It's already listed.

26 March 2009

'final' without explicit type proposal

OVERVIEW

FEATURE SUMMARY:

MAJOR ADVANTAGE:
It allows people to concentrate on logic during operating on heavy generics and to use values which are more intuitive for them than variables.

MAJOR BENEFIT(s):

  • It allows to avoid duplicating unnecessarily types of declaration.
  • It increase a concentration on 'what I've got' than on 'what type is that' (we decrease size by one to obtain last element index, not because we can do this = it's int), while for variables we still keep concentrate on: 'what type is that' / 'what I can put there'.
  • Editing existing code to get some value from method chain is easier.
  • That method can be itself multi-thread with this, but it's a far future.
  • Using of Generics is easier.

MAJOR DISADVANTAGE:

  • Certainly, some people will overuse this solution.
  • Consider operator is easier to read.
  • It might be a problem if a person does not know how to give proper names for values.

ALTERNATIVES:
Normal variables.

20 March 2009

Glue classes proposal 0.9

OVERVIEW

FEATURE SUMMARY:

Glue classes allow to link utils direct with objects.

MAJOR ADVANTAGE:

Forgotten functionality can be not such big deal now.

MAJOR BENEFIT(s):

  • New functions can be easy localized (critically important while introduce new peoples into project).
  • Security: glue class do not see anything protected.
  • Light binding new functions with existing classes.
  • Number of used classes reduction.
  • Allow to assign methods and functions(static methods) to arrays, classes, interfaces, …
  • It's proof against same method occurs in class and delegator as well like in two delegators.
  • Allow to link gained(.jar) logic with new one, witch is impossible before final developer implements his classes.
  • Allow to project compact interfaces and do not worry about additional logic.

MAJOR DISADVANTAGE:
Do not know any ;) sorry.

ALTERNATIVES:
Utils classes, more work on project, duplicated code...

15 March 2009

Return 'this' proposal

GENESIS

It's a simplified 'This' type problem, which seems to be too much complicated as for now and need more analyses. Construction is designed not to interact with possibility that 'This' type will be introduced.

OVERVIEW

FEATURE SUMMARY:
It allows the method to return reference to 'this' object.

MAJOR ADVANTAGE:
Simplification of return this; statement.
'void' can be easy replaced with 'this'.

MAJOR BENEFIT(s): It would prevent NullPointerException, and make some 'builder' like interfaces look really clear and simple.

MAJOR DISADVANTAGE:
Returned value cannot be changed while inheritance.

ALTERNATIVES:
Self-bounded generics, This type.

14 March 2009

Read-only & Partial arrays proposal

Instrukcje

Tworzenie tablic do odczytu pozwoliło by zwiększyć szybkość jak i bezpieczeństwo pisanych programów. Była by to zwykła tablica tworzona na podstawie już istniejącej bez możliwości modyfikacji jej stanu.

Tablice częściowe tworzone na tablicach do odczytu pomogły by zmniejszyć ryzyko popełnienia błędu dostępu do niewłaściwego obszaru tablicy oraz zmniejszyło by zużycie pamięci.

12 March 2009

Glue classes proposal beta

OVERVIEW

Notice that it's beta specification: it's not described in full details, half validated (translation), and it's provided for you to pre-analyse. I still need some time to provide syntax which fully supports generics. Multi-glue classes are under consideration as well, but this may occur to be to complex to handle by any earth living programmer.

FEATURE SUMMARY:
Glue classes allow to link utils direct with objects.

MAJOR ADVANTAGE:
Forgotten functionality can be not such big deal now.

MAJOR BENEFIT(s):

  • New functions can be easy localised (critically important while introduce new peoples into project).
  • Security: glue class do not see anything protected.
  • Light binding new functions with existing classes.
  • Number of used classes reduction.
  • Allow to assign methods and functions(static methods) to arrays, classes, interfaces, …
  • It's proof against same method occurs in class and delegator as well like in two delegators.
  • Allow to link gained(.jar) logic with new one, witch is impossible before final developer implements his classes.
  • Allow to project compact interfaces and do not worry about additional logic.

MAJOR DISADVANTAGE:
Do not know any ;) sorry.

ALTERNATIVES:
Utils classes.

11 March 2009

Consider operator proposal

OVERVIEW

FEATURE SUMMARY:
Consider operator extends language with full value support and assign value to name and return it.

MAJOR ADVANTAGE:
It introduces natural division in variables and values.

It makes language to be more natural for human and generics easier to use.

MAJOR BENEFIT(s):

  • If we need to get a value, we can do that quite simple (without splitting expression or duplicating code).
  • Decrease number of potential bugs (value cannot be assigned).
  • It can help in splitting code to proper parts; nowdays, we need to declare variable regardless we need it or not (or make it final).
  • Decrease size of unnecessary code.
  • Method can be itself multi-thread with this, but it's far future.

MAJOR DISADVANTAGE:
Possibility to be unclear at start.

ALTERNATIVES:
Some time 'final' variables can be used, but it's more like for-each, life is better with it.

10 March 2009

Delegation proposal

OVERVIEW

FEATURE SUMMARY:
This change allow to delegate methods, interfaces and classes.

MAJOR ADVANTAGE:
It would be a first step for programmers to have something instead of inheritance, allowing to write better code.

MAJOR BENEFITS:
Java looks incomplete without something so base as delegating. Others are:

  • Code more immune for changes(if interface changes, there will be not so much to change, or I would say, changes will be on the right place, but not on all projects)
  • Decreasing costs of code modification.
  • Explicit defining MethodModifiers

MAJOR DISADVANTAGE:
Changes cost.

ALTERNATIVES:
It's nothing that cannot be implemented in a simple way, but this change does not increase delegation complex, unreadablity, and costs of support with each method.

9 March 2009

Final interfaces... proposal

Instrukcje

Interface (klasa abstrakcyjna) finalny nie mógłby zostać rozszerzony (zaimplementowany) przez żadną klasę(interface), oprócz tych określonych wprost.

8 March 2009

'forget' keyword proposal

Instrukcje

Słowo 'forget' powodowało by wymazanie zmiennej z obecnego kontekstu. Co pozwoliło by na bardziej intuicyjne operowanie logiką programu, w przypadku gdy dana zmienna nie może(powinna być) być już używana. Ma to niebanalne znaczenie gdy po jakimś czasie wracamy do napisanego kodu.

3 March 2009

'This' type

AUTHOR: Lasu aka Marek Kozieł http://lasu2string.blogspot.com/

OVERVIEW

FEATURE SUMMARY:
This type add ability to project valid interfaces(classes) for further extending/implementing. 'This' means current interface/class type or something implementing/extending it.

18 February 2009

11 February 2009

Encapsulation though access control

Encapsulation does not necessarily means getters and setters. And have more than one aspects:

  • Inside structure control.
  • Input data validation.
  • Outside access control.

Lets consider 'Outside access control'.

While we directly do not know which class calls method, it's hard to limit context of (method) call. It is possible, but amount of work is to big now time.
Any way what solutions do we have?

4 February 2009

Using Strings and Objects in Switch case statements.

Lets consider enhancement on Sun Bug Database : 5012262

It's about letting us using String in switch.

3 February 2009

Memory management in Java


 
Different look on memory leak problem.

We have garbage collector in Java, but this do not prevent us from make memory to leak. What more even standard library isn't leak-free.

How can we spare memory easly?

String.intern() is one of the easiest way.

  • It do not interfere with gc.
  • It's fast.
  • Multi thread safe.
I just need to check if .intern() work with .substring(...)

Where we loose memory quietly?

Most Classes created to store high amount of dynamic data have their own memory menage system. ArrayList, StringBuilder, ... they all allocate *2 memory. Which mean that is we have 1024 elements and need to add one while no free space is available then space will be extended to 2024.

How much memory do we loose?

Calling .trimToSize() can spare approximately 10% of memory.
On String.intern() I used to save up to 70%.

2 February 2009

1 February 2009

Genesis of Programming

Wikipedia: Tower of Babel

1 At one time the whole earth had the same programming language and vocabulary. 2 As people migrated from the asembler, they found a valley in the land of Shinar and settled there 3 They said to each other, "Come, let us make libraries ." They had objects for stone and patterns for mortar. 4 And they said, "Come, let us build ourselves a language and a standard library with everything programmer can need under the sky. Let us make a name for ourselves; otherwise, we will be scattered over the face of the whole earth."

5 Then the marketing came down to look over the language concepts and the library that the men were building. 6 The marketing said, "If, as one people all having the same language, they have begun to do this, then nothing they plan to do will be impossible for them. 7 Come, let Us go down there and forbid them to create language so that they will not be able to create programs for all the platforms."

8 So the marketing scattered them from there over the firms on the whole earth, and they stopped building the language. 9 Therefore its name is called Babylon, for there the marketing confused the programmers of the whole earth, and from there the marketing scattered them over the face of the firms on the whole earth.

19 January 2009

Gdyby ludzie mówili językami programowania?

Generalnie programowanie sprowadza się do myślenia w określony sposób. Często opanowanie tego sposobu zajęło nam tyle czasu i w trakcie użycia sprawia tyle trudności, że nie mamy czasu się zastanawiać co my właściwie myślimy.

Tak więc spróbuje przedstawić jak wyglądała by przykładowa sytuacja w której to Heniek mówi Marianowi, że ten ma udać się do monopolowego po flaszkę oraz bimber który kochana sprzedawczyni Hela trzyma za pazuchą dla najlepszych klientów, a co gorsza z nimi wrócić.