NN – WordPress

September 12, 2009

Default arguments

Filed under: Uncategorized — by NN @ 7:40 am

Today I am going to talk about default arguments in programming languages.
What do you think about it ? Should your language support default arguments ?
Some languages support and some don’t. It has a heavy influence on the design.

What are the pros for the default arguments:
* Instead of writing many overloads you can write only one.
* The code completion can show only one function instead of 20 (E.g. System.MessageBox.Show method)

What are the cons for the default arguments:
* They can lead to strange behaviour.
– Default arguments in python: Default values
– Default arguments in C++ when using virtual functions. You use the default value according to the static and to the dynamic type.

So what is the best solution ?
In my opinion the best solution is to create many functions with overloads, but to do it automatically.
You can do it in Nemerle language using macros:

Default arguments

Enjoy :)

July 26, 2009

Scripts Part 3

Filed under: script — by NN @ 4:13 am

We are back, and now we have a different problem with scripts.
On the one hand we want things just work, on the other hand we don’t want always to expose our code to the end user.
So what the dilemma?

1. We can use the same code for production and for debugging. It is good enough when we don’t have some special features in our code.
2. We can obfuscate the code in the production stage. Why would we this at all? Perhaps we have some meaningful algorithm or we don’t want to expose functions and variables names.
And then we have a problems.
How the code should be obfuscated? The question is so difficult, so for sure I can say it depends.

There are some possible scenarios for obfuscation.
1. change names. We get the same code structure and we have auto generated dictionary to translate real name to obfuscated name and vice versa.
2. Change code. We get a different code structure. It differs from the real one. In this case our debugging capabilities are not so high.
3. We can use both 1 and 2 thus providing unreadable and not debuggable code.
4. I didn’t mention it before, but we can also optimize our code. Here we get the different code in the production.
5.compilation. Some script engines provide support for internal byte code. We can compile our script code to the byte code, so there will be no any original text.

Thoughts.
The problem is very interesting yet not trivial.
If you are sure in your code, the best is to obfuscate, optimize and compile to byte code. This brings almost no additional information about you code.
But, if your are not sure in your code, or you want to be able to debug it (especially if you want to debug in the production code), you can throw away thoughts about obfuscation.
I belive that the real answer depends on the situation.

June 20, 2009

Scripts Part II

Filed under: Uncategorized — by NN @ 8:29 pm

From the post before it can be realized that we do need some dynamic environment.
But how is it easy to achieve this?

Today I will talk about some common things. For these things one cannot find a good answer.

  • First, A script debugging.
  • Is this easy ? It should be, but not always.

    Lets start from MS supported products.

    VBA: So how do you do this in VBA ? There is a whole world of support. It works in all MS Office programs, moreover I there are more programs with VBA support. E.g. AutoCAD support VBA programming.
    Scripting technology: Here you have a bunch of interfaces and baz words like “Machine Debug Manager” and “Process Debug Manager”. Active Scripting API
    After reading a lot and trying a lot without a success you can manage to debug a script which runs in your executable file.

    What with the open source projects?
    Lua: There is no built-in debugger attached with the lua implementation from lua.org.
    But there is a debugger called Decoda. It costs money of course if you are not sure. ;)
    It works very nice. It doesn’t work good with the compiled lua code and code in release. But works.
    Python: You can try PDB.
    Wingware claims to debug embedded Python script.
    I did not check them, you can try and tell me if it works.
    Ruby:Internet search (like with Python) gives the ruby-debug, it seems very similar to python debugger (pdb).
    What with other languages ? There are few widespread scripting languages, so if you have something good and works, you can point me to.

    What the next?

  • Second, Interoperability.
  • How you can call from script to your language, and from your language to the script?

    The best what I know is the Boost.Python implementation.
    It supports whatever you want and it works, yeah ! :)
    For Lua you have luabind of luabridge libraries, they are pretty good too.
    There are more libraries than I can think about, so use the Internet search.
    What we have for Ruby language: Rice

    What about ActiveScripting ?
    Here you have just to implement COM object and you are in. It was too easy, so the long answer that you have to implement IDispatch interface and maybe to write some more magic. To make it shorter, ATL solves all your problems.

    The only problem with this that there is no automatic way to expose your classes to the script.
    Not so!
    With Boost.Python you have Pyste and the newer Py++:

    Looks just great. It uses GCC XML so it can be a problem for some incompatible code.
    One day we can see automation support for other scripts too.

    For Active Scripting you just do nothing, because every COM object can be used automatically.
    The only disadvantage of this technology that it is not cross platform. (You can use WINE to make it cross platform ;) )

    What else bothers you with the scripting languages ?
    Something about the scripting virtual machine: Speed and size, multithreaded support.
    Something more about the language itself: Strong typed or non strong typed. duck typing.

    Conclusion:
    In my opinion if you want some scripting environment in your program make it easy and extendable enough.

    P.S.
    Yes, I did not mention Perl language. If someone can give me a good link for Perl language debugging and embedding, it would be nice.

    June 13, 2009

    Scripts Part I

    Filed under: script — by NN @ 8:17 am

    Dynamic and static.

    What the difference and why do we need both, or perhaps don’t need :)

    What the different between two approaches ?
    The static approach means that all control paths are known before the application runs, the dynamic approach means that we can create on the fly different control paths.

    It is easy to see that static approach is a subset of dynamic approach.
    So why don’t we use dynamic in all ?
    There are two main reasons:

  • Performance: When we have a knowledge about all control paths in our program, we can optimize it easy
  • Strictness: The most problems can be caught before we run our program and not when the program runs.
  • It seems that the best is something like dynamic environment but with a good performance and with ability for static checking. I will return to this statement some when after.

    Let’s start from some examples and analyze why we have two approaches:
    1. C – static language.
    2. Perl – dynamic language.

    In C we have a well written program with all static checks we have and we know everything to happen, in Perl we create code dynamically and run it thus providing flexibility and no checks :)
    I know, it wasn’t a good competition. It was to demonstrate the competition.

    Another example: We have a well designed program but we want to improve it simply by adding some dynamic abilities to our program. See Microsoft Word and VBA for example.

    So what is the scripting language ? I won’t bother you with wikipedia and encyclopedia. I just tell you what I think.
    The main advantage of scripting language is no need for compilation.
    That’s why many languages have a success, you don’t have to wait Hours!! till you have your program compiled. Of course you pay in performance, but who cares about performance too much ?

    Ok, but what about Virtual Machine based languages ? Here you have a very interesting case, on the one hand you have dynamic environment with JIT compilation with good optimizations, on the other hand you have static or dynamic language on top over.
    E.g. .Net is a dynamic environment while most languages for .Net are static.
    So I can claim that C# is a script language because you have C# interpreter ! C# Interpreter :)

    It was a prelude. And now the back to the post. I will talk about adding scripting technology to C++ programs.
    Why C++ ? Because sometimes you have to use it.
    Of course I prefer .Net but you don’t have .Net anywhere, at least for now. I’m still waiting for MSIL based smartphone ;)

    Let’s see our candidates:
    Lua
    Squirrel
    tiscript
    JScript + VBScript
    C interpreter
    And more :)

    The purpose is simple, I want some code base and then everyone can use abilities very simple and extend my program.

    The choice is right to you.

    June 12, 2009

    Windows 7 x64

    Filed under: windows — by NN @ 8:32 pm

    I have Windows7 for a long time in my laptop.

    It works pretty good.

    I have upgraded Windows7 from RC1 to post RC1 and to RC2. No problems.

    The only one thing which doesn’t work good is Daemon Tools.

    Today I have installed Windows 7 on my home computer.

    I have AMD X2 Processor and 4Gb RAM so I wanted 64-bit system of course.

    I have very good impression. It works fast. Even faster than my Windows XP x64 !

    I don’t care about eye candy in Windows 7 but some eye candy features are definetly good.

    And of course IE8 in Windows 7 works faster than in Windows XP ;)

    Conclusion: Windows 7 is the best Windows for today. Even in RC state.

    I will buy it for a sure :)

    P.P.S.

    Currently I did have one problem. The quick launch bar.

    You don’t have it automatically in Windows 7. I hope it will be restored in the RTM.

    Now you have to use this trick:

    http://www.howtogeek.com/howto/windows-7/add-the-quick-launch-bar-to-the-taskbar-in-windows-7/

    Some magic but does the work.

    And if you don’t want a watermark use patch:

    http://www.megaupload.com/?d=3AKF1TDG

    Enjoy.

    May 16, 2009

    BoostCon 2009

    Filed under: Uncategorized — by NN @ 8:58 am

    Very interesting docs about C++: BoostCon 2009.

    C++0x overview and Compiler support
    Parallel Patterns Library in Visual Studio 2010
    Icefishing for Neutrinos with Boost – Serialization Tutorial and Examples
    Icefishing for Neutrinos with Boost – Hybrid Architecture with Boost Python
    The Meta State Machine (Msm) library
    High-Level Parallel Programming EDSL
    Boost++0x #1: Hands-on rvalue References
    Tuesday Presentations

    A Cmake-Based Software Process for Development and Integration Testing
    Status of the boost-cmake effort
    State-Oriented Programming Using Boost Statechart Library
    The Meta State Machine (Msm) library
    Multithreaded C++0x: The Dawn of a New Standard
    Extending Boost.Algorithms — A Progress Report
    Boost Exception
    Boost + Software Transactional Memory, Boost + Software Transactional Memory – paper
    Boost++0x #2: Hands-on decltype, variadic templates, advanced SFINAE Also, slides from last year’s C++0x talk, covering variadic templates et al.
    Wednesday Presentations

    Keynote: Iterators Must Go
    C++0x Support in Visual Studio 2010
    Building a simple language compiler using Spirit V2.1
    Kamasu: Parallel computing on the GPU with boost::proto
    The Boost Smart Pointer Library
    Thursday Presentations

    Practical C++ Test-Driven Development with Boost.Test and Bmock
    Dynamic Programming: A Generic Viterbi Algorithm
    A Generic Geometry Library, A Generic Geometry Library – paper
    GTL for STL-like 2D Operations
    The Boost Filesystem Library V3
    Boost Fusion
    An experimental domain specific language for template metaprogramming
    Introduction to Graphics Programming with boost::gil
    GIL Workshop – Basic Algorithms, link available Wednesday
    Friday Presentations

    Advanced Preprocessor Meta-Programming with Boost.Preprocessor Library
    An Introduction to the Interval Template Library
    All library in a week presentations:

    Library in Week 2009 – std::rdb

    April 14, 2009

    MSI Wind U100 Plus

    Filed under: Uncategorized — by NN @ 2:23 pm

    I got a new netbook, yes yes this name is forbidden to say :) but i like this name.

    So what did I get ?
    http://www.msi.com/index.php?func=newsdesc&news_no=771
    This one with the red color, red is more beautiful ;)

    What can I talk about my new computer. It is very very good.
    It has N280.
    It supports wifi b/g/n.
    And works very fast. Faster definitely than old Pentium 3.
    The keyboard is pretty good, I can arrange writing fast enough.
    But Fn key in the left bottom corner not so good. I always press it when I want Ctrl button.

    So if you are searching a good netbook, you must buy this !!!

    There is one problem which isn’t solved.
    What OS should I install and use this computer.

    What I got is Windows XP Home Edition !!
    It works good, every Fn+Fx keys work, in ubuntu not all work.
    But i don’t like Windows XP Home ..

    Maybe Windows 7…

    February 2, 2009

    Hello IE 8 RC1 Final

    Filed under: Uncategorized — by NN @ 12:10 pm

    So for now definitely a good version of IE 8!
    Works faster but not as fast as Maxthon.
    All sites work as expected.
    Even ACID 2 test. Not ACID 3 :( But at least something good :)

    Anyway, without IE7Pro plugin this browser is not usable at all !
    MS should think about merging it to the IE.

    The security part is very good though. It asks about any strange thing. Well done.

    Hopefully the final version will work even faster. I still do not get why opening a tab takes so much time.
    Maxthon can open 10 tabs while IE 8 opens 1 tab. (I do not compare to IE7 at all :D )

    P.S.
    Still no Flash for IE x64 what makes IE x64 useless.

    January 9, 2009

    Boot loaders

    Filed under: Uncategorized — by NN @ 10:09 pm

    I have a good rescue DVD, it is very helpful to fix computers.

    It is a multiboot DVD which includes Windowses installations, some Windows Live, Hiren’s Boot CD, System Rescue CD, Acronis Boot CD and something else. The list changes all the time because I look up for improvements.

    I am using now a tool called Bootable CD Wizard. This is a very simple boot loader for CD which allows everything you need:
    1. Support for gif format in logo.
    2. Simple to use.
    3. Can boot almost everything. It boots Windows installation , Linux installation without any problems.
    4. Can boot ISO image directly ! You just write a path and it works.

    The only problem is a lack of USB support. I know that some day I will need it, so I have started searching for something better.
    The candidates are: ISOLinux, GRUB, GRUB2.
    It is easy enough to install them to the CD but it is not easy to make them work.
    I did not find how to load ISOLinux from GRUB or GRUB2. It just not as simple as it is done using BCDW.
    I did not find how to load ISOLinux from ISOLinux, it didn’t work for me either. Here I can just edit isolinux.cfg but it is not what I want..

    Sounds strange but program from 2004 beats the new programs from 2009!!
    I think that all my needs can be satisfied using GRUB or ISOLinux but the solution will not be intuitive like it is done in BCDW.
    Some day the problem will be solved, some day.

    January 5, 2009

    Netbook Remix

    Filed under: Uncategorized — by NN @ 8:18 pm

    Have you heard about netbook ? It is a small computer with a small display. I had Asus 701 model. The main OS was Linux with english and no translation. The goal was installation a normal system with russian interface.

    First I looked at Windows XP Tiny edition it looked interesting. I even found how to boot Hiren’s Boot CD from USB and run Windows installation.

    Everything was prepared but it was found. Eeebuntu!

    The main problem with all strange hardware is driver for all. I assumed about difficulty finding driver for Wi-Fi network adapter and web cam for Windows. And there it is all packed, no need to look in all internet.

    So was it.

     

    The other interesting part is netbook remix, nbr-launcher. It is very intuitive and minimalistic interface. It is good for touchpads because you have no need to scroll in menus and good for those who want simplicity in their life.

    IMHO it is good for desktops too.

    Anyway eeebuntu was a good choice, russian interface was completely installed, every program worked as expected. There was enough space for OpenOffice, Skype, many games and even for WINE :) Finally about 250Mb was left free.

    In any way you have to buy some USB stick to have all things close to heart so it is ok.

    Currently the applets work only in Gnome. KDE will be supported some day, I hope.

     

    References:

    Eeebuntu

    Ubuntu Netbook Remix - there you have a nice video. 

    Netbook Remix

    Next Page »

    Powered by WordPress.com